]> git.pld-linux.org Git - packages/cvsps.git/blob - cvsps-fixes.patch
e752e933133279d480c6875712de13e43ec5cd76
[packages/cvsps.git] / cvsps-fixes.patch
1 diff --git a/Makefile b/Makefile
2 index 507c3e9..05ca856 100644
3 --- a/Makefile
4 +++ b/Makefile
5 @@ -1,8 +1,8 @@
6  MAJOR=2
7  MINOR=1
8  CC?=gcc
9 -CFLAGS?=-g -O2 -Wall 
10 -CFLAGS+=-I. -DVERSION=\"$(MAJOR).$(MINOR)\"
11 +CFLAGS?=-g -O2 -Wall
12 +CPPFLAGS?=-I. -DVERSION=\"$(MAJOR).$(MINOR)\"
13  prefix?=/usr/local
14  OBJS=\
15         cbtcommon/debug.o\
16 @@ -20,6 +20,9 @@ OBJS=\
17  
18  all: cvsps
19  
20 +deps:
21 +       makedepend -Y -I. *.c cbtcommon/*.c
22 +
23  cvsps: $(OBJS)
24         $(CC) -o cvsps $(OBJS) -lz
25  
26 @@ -33,3 +36,27 @@ clean:
27         rm -f cvsps *.o cbtcommon/*.o core
28  
29  .PHONY: install clean
30 +# DO NOT DELETE
31 +
32 +cache.o: ./cbtcommon/hash.h ./cbtcommon/list.h ./cbtcommon/inline.h
33 +cache.o: ./cbtcommon/debug.h cache.h cvsps_types.h cvsps.h util.h
34 +cap.o: ./cbtcommon/debug.h ./cbtcommon/inline.h ./cbtcommon/text_util.h cap.h
35 +cap.o: cvs_direct.h
36 +cvs_direct.o: ./cbtcommon/debug.h ./cbtcommon/inline.h
37 +cvs_direct.o: ./cbtcommon/text_util.h ./cbtcommon/tcpsocket.h
38 +cvs_direct.o: ./cbtcommon/sio.h cvs_direct.h util.h
39 +cvsps.o: ./cbtcommon/hash.h ./cbtcommon/list.h ./cbtcommon/inline.h
40 +cvsps.o: ./cbtcommon/list.h ./cbtcommon/text_util.h ./cbtcommon/debug.h
41 +cvsps.o: ./cbtcommon/rcsid.h cache.h cvsps_types.h cvsps.h util.h stats.h
42 +cvsps.o: cap.h cvs_direct.h list_sort.h
43 +list_sort.o: list_sort.h ./cbtcommon/list.h
44 +stats.o: ./cbtcommon/hash.h ./cbtcommon/list.h ./cbtcommon/inline.h
45 +stats.o: cvsps_types.h cvsps.h
46 +util.o: ./cbtcommon/debug.h ./cbtcommon/inline.h util.h
47 +cbtcommon/debug.o: cbtcommon/debug.h ./cbtcommon/inline.h cbtcommon/rcsid.h
48 +cbtcommon/hash.o: cbtcommon/debug.h ./cbtcommon/inline.h cbtcommon/hash.h
49 +cbtcommon/hash.o: ./cbtcommon/list.h cbtcommon/rcsid.h
50 +cbtcommon/sio.o: cbtcommon/sio.h cbtcommon/rcsid.h
51 +cbtcommon/tcpsocket.o: cbtcommon/tcpsocket.h cbtcommon/debug.h
52 +cbtcommon/tcpsocket.o: ./cbtcommon/inline.h cbtcommon/rcsid.h
53 +cbtcommon/text_util.o: cbtcommon/text_util.h cbtcommon/rcsid.h
54 diff --git a/cache.c b/cache.c
55 index 4c51cf7..5f67a7c 100644
56 --- a/cache.c
57 +++ b/cache.c
58 @@ -108,10 +108,19 @@ time_t read_cache()
59      int tag_flags = 0;
60      char branchbuff[LOG_STR_MAX] = "";
61      int branch_add = 0;
62 -    char logbuff[LOG_STR_MAX] = "";
63 +    int logbufflen = LOG_STR_MAX + 1;
64 +    char * logbuff = malloc(logbufflen);
65      time_t cache_date = -1;
66      int read_version;
67  
68 +    if (logbuff == NULL)
69 +    {
70 +       debug(DEBUG_SYSERROR, "could not malloc %d bytes for logbuff in read_cache", logbufflen);
71 +       exit(1);
72 +    }
73 +
74 +    logbuff[0] = 0;
75 +
76      if (!(fp = cache_open("r")))
77         goto out;
78  
79 @@ -299,8 +308,19 @@ time_t read_cache()
80             else
81             {
82                 /* Make sure we have enough in the buffer */
83 -               if (strlen(logbuff)+strlen(buff)<LOG_STR_MAX)
84 -                   strcat(logbuff, buff);
85 +               int len = strlen(buff);
86 +               if (strlen(logbuff) + len >= LOG_STR_MAX)
87 +               {
88 +                   logbufflen += (len >= LOG_STR_MAX ? (len+1) : LOG_STR_MAX);
89 +                   char * newlogbuff = realloc(logbuff, logbufflen);
90 +                   if (newlogbuff == NULL)
91 +                   {
92 +                       debug(DEBUG_SYSERROR, "could not realloc %d bytes for logbuff in read_cache", logbufflen);
93 +                       exit(1);
94 +                   }
95 +                   logbuff = newlogbuff;
96 +               }
97 +               strcat(logbuff, buff);
98             }
99             break;
100         case CACHE_NEED_PS_MEMBERS:
101 @@ -332,6 +352,7 @@ time_t read_cache()
102   out_close:
103      fclose(fp);
104   out:
105 +    free(logbuff);
106      return cache_date;
107  }
108  
109 @@ -344,7 +365,7 @@ enum
110      CR_BRANCH_POINT
111  };
112  
113 -static void parse_cache_revision(PatchSetMember * psm, const char * p_buff)
114 +static void parse_cache_revision(PatchSetMember * psm, const char * buff)
115  {
116      /* The format used to generate is:
117       * "file:%s; pre_rev:%s; post_rev:%s; dead:%d; branch_point:%d\n"
118 @@ -354,35 +375,37 @@ static void parse_cache_revision(PatchSetMember * psm, const char * p_buff)
119      char post[REV_STR_MAX];
120      int dead = 0;
121      int bp = 0;
122 -    char buff[BUFSIZ];
123      int state = CR_FILENAME;
124 -    const char *s;
125 -    char * p = buff;
126 -
127 -    strcpy(buff, p_buff);
128 +    const char *sep;
129 +    char * p;
130 +    char * c;
131  
132 -    while ((s = strsep(&p, ";")))
133 +    for (p = buff, sep = buff;                   /* just ensure sep is non-NULL */
134 +        (sep != NULL) && (c = strchr(p, ':'));
135 +        p = sep + 1)
136      {
137 -       char * c = strchr(s, ':');
138 -
139 -       if (!c)
140 -       {
141 -           debug(DEBUG_APPERROR, "invalid cache revision line '%s'|'%s'", p_buff, s);
142 -           exit(1);
143 -       }
144 +       size_t len;
145 +       sep = strchr(c, ';');
146 +       c++;
147  
148 -       *c++ = 0;
149 +       if (sep != NULL)
150 +           len = sep - c;
151 +       else /* last field in the cache line */
152 +           len = strlen(c);
153  
154         switch(state)
155         {
156         case CR_FILENAME:
157 -           strcpy(filename, c);
158 +           memcpy(filename, c, len);
159 +           filename[len] = '\0';
160             break;
161         case CR_PRE_REV:
162 -           strcpy(pre, c);
163 +           memcpy(pre, c, len);
164 +           pre[len] = '\0';
165             break;
166         case CR_POST_REV:
167 -           strcpy(post, c);
168 +           memcpy(post, c, len);
169 +           post[len] = '\0';
170             break;
171         case CR_DEAD:
172             dead = atoi(c);
173 diff --git a/cap.c b/cap.c
174 index a6186f6..a1927df 100644
175 --- a/cap.c
176 +++ b/cap.c
177 @@ -121,11 +121,19 @@ int check_version_string(const char * str, int req_major, int req_minor, int req
178         return 0;
179      }
180  
181 +    /* We might have encountered a FreeBSD system which
182 +     * has a mucked up version string of:
183 +     *  Concurrent Versions System (CVS) '1.11.17'-FreeBSD (client/server)
184 +     * so re-test just in case
185 +     */
186      p += skip;
187      if (sscanf(p, "%d.%d.%d", &major, &minor, &extra) != 3)
188      {  
189 -       debug(DEBUG_APPMSG1, "WARNING: malformed CVS version: %s", str);
190 -       return 0;
191 +        if (sscanf(p, "'%d.%d.%d'", &major, &minor, &extra) != 3)
192 +       {
193 +               debug(DEBUG_APPMSG1, "WARNING: malformed CVS version: %s", str);
194 +               return 0;
195 +       }
196      }
197  
198      return (major > req_major || 
199 diff --git a/cbtcommon/tcpsocket.c b/cbtcommon/tcpsocket.c
200 index 27cc13a..f31060e 100644
201 --- a/cbtcommon/tcpsocket.c
202 +++ b/cbtcommon/tcpsocket.c
203 @@ -185,20 +185,20 @@ tcp_connect(int sockfd, const char *rem_addr, unsigned short port)
204  int
205  convert_address(long *dest, const char *addr_str)
206  {
207 -#ifdef LINUX
208 +#ifdef __linux__
209    struct in_addr ip;
210  #endif
211    int retval = 0;
212    char errstr[256];
213    
214    /* first try converting "numbers and dots" notation */
215 -#ifdef LINUX
216 +#ifdef __linux__
217    if ( inet_aton(addr_str, &ip) )
218    {
219      memcpy(dest, &ip.s_addr, sizeof(ip.s_addr));
220    }
221  #else
222 -  if ( (*dest = inet_addr(addr_str)) != -1)
223 +  if ( (*dest = inet_addr(addr_str)) != INADDR_NONE)
224    {
225      /* nothing */
226    }
227 diff --git a/cvsps.1 b/cvsps.1
228 index cea0faf..6cfdac6 100644
229 --- a/cvsps.1
230 +++ b/cvsps.1
231 @@ -83,7 +83,7 @@ some hacks which are not generally applicable.
232  disable the use of rlog internally.  Note: rlog is
233  required for stable PatchSet numbering.  Use with care.
234  .TP
235 -.B \-\-diffs\-opts <option string>
236 +.B \-\-diff\-opts <option string>
237  send a custom set of options to diff, for example to increase
238  the number of context lines, or change the diff format.
239  .TP
240 diff --git a/cvsps.c b/cvsps.c
241 index 1e64e3c..981cd78 100644
242 --- a/cvsps.c
243 +++ b/cvsps.c
244 @@ -39,7 +39,8 @@ RCSID("$Id$");
245  
246  enum
247  {
248 -    NEED_FILE,
249 +    NEED_RCS_FILE,
250 +    NEED_WORKING_FILE,
251      NEED_SYMS,
252      NEED_EOS,
253      NEED_START_LOG,
254 @@ -117,7 +118,9 @@ static int parse_args(int, char *[]);
255  static int parse_rc();
256  static void load_from_cvs();
257  static void init_paths();
258 -static CvsFile * parse_file(const char *);
259 +static CvsFile * build_file_by_name(const char *);
260 +static CvsFile * parse_rcs_file(const char *);
261 +static CvsFile * parse_working_file(const char *);
262  static CvsFileRevision * parse_revision(CvsFile * file, char * rev_str);
263  static void assign_pre_revision(PatchSetMember *, CvsFileRevision * rev);
264  static void check_print_patch_set(PatchSet *);
265 @@ -260,12 +263,13 @@ static void load_from_cvs()
266  {
267      FILE * cvsfp;
268      char buff[BUFSIZ];
269 -    int state = NEED_FILE;
270 +    int state = NEED_RCS_FILE;
271      CvsFile * file = NULL;
272      PatchSetMember * psm = NULL;
273      char datebuff[20];
274      char authbuff[AUTH_STR_MAX];
275 -    char logbuff[LOG_STR_MAX + 1];
276 +    int logbufflen = LOG_STR_MAX + 1;
277 +    char * logbuff = malloc(logbufflen);
278      int loglen = 0;
279      int have_log = 0;
280      char cmd[BUFSIZ];
281 @@ -273,6 +277,12 @@ static void load_from_cvs()
282      char use_rep_buff[PATH_MAX];
283      char * ltype;
284  
285 +    if (logbuff == NULL)
286 +    {
287 +       debug(DEBUG_SYSERROR, "could not malloc %d bytes for logbuff in load_from_cvs", logbufflen);
288 +       exit(1);
289 +    }
290 +
291      if (!no_rlog && !test_log_file && cvs_check_cap(CAP_HAVE_RLOG))
292      {
293         ltype = "rlog";
294 @@ -298,12 +308,12 @@ static void load_from_cvs()
295          * which is necessary to fill in the pre_rev stuff for a 
296          * PatchSetMember
297          */
298 -       snprintf(cmd, BUFSIZ, "cvs %s %s %s -d '%s<;%s' %s", compress_arg, norc, ltype, date_str, date_str, use_rep_buff);
299 +       snprintf(cmd, BUFSIZ, "cvs %s %s -q %s -d '%s<;%s' %s", compress_arg, norc, ltype, date_str, date_str, use_rep_buff);
300      }
301      else
302      {
303         date_str[0] = 0;
304 -       snprintf(cmd, BUFSIZ, "cvs %s %s %s %s", compress_arg, norc, ltype, use_rep_buff);
305 +       snprintf(cmd, BUFSIZ, "cvs %s %s -q %s %s", compress_arg, norc, ltype, use_rep_buff);
306      }
307      
308      debug(DEBUG_STATUS, "******* USING CMD %s", cmd);
309 @@ -339,10 +349,26 @@ static void load_from_cvs()
310  
311         switch(state)
312         {
313 -       case NEED_FILE:
314 -           if (strncmp(buff, "RCS file", 8) == 0 && (file = parse_file(buff)))
315 +       case NEED_RCS_FILE:
316 +           if (strncmp(buff, "RCS file", 8) == 0) {
317 +              if ((file = parse_rcs_file(buff)) != NULL)
318                 state = NEED_SYMS;
319 +              else
320 +                state = NEED_WORKING_FILE;
321 +            }
322             break;
323 +       case NEED_WORKING_FILE:
324 +           if (strncmp(buff, "Working file", 12) == 0) {
325 +              if ((file = parse_working_file(buff)))
326 +               state = NEED_SYMS;
327 +              else
328 +                state = NEED_RCS_FILE;
329 +               break;
330 +           } else {
331 +              // Working file come just after RCS file. So reset state if it was not found
332 +              state = NEED_RCS_FILE;
333 +            }
334 +            break;
335         case NEED_SYMS:
336             if (strncmp(buff, "symbolic names:", 15) == 0)
337                 state = NEED_EOS;
338 @@ -471,7 +497,7 @@ static void load_from_cvs()
339                 have_log = 0;
340                 psm = NULL;
341                 file = NULL;
342 -               state = NEED_FILE;
343 +               state = NEED_RCS_FILE;
344             }
345             else
346             {
347 @@ -480,24 +506,22 @@ static void load_from_cvs()
348                  */
349                 if (have_log || !is_revision_metadata(buff))
350                 {
351 -                   /* if the log buffer is full, that's it.  
352 -                    * 
353 -                    * Also, read lines (fgets) always have \n in them
354 -                    * which we count on.  So if truncation happens,
355 -                    * be careful to put a \n on.
356 -                    * 
357 -                    * Buffer has LOG_STR_MAX + 1 for room for \0 if
358 -                    * necessary
359 -                    */
360 -                   if (loglen < LOG_STR_MAX)
361 +                   /* If the log buffer is full, try to reallocate more. */
362 +                   if (loglen < logbufflen)
363                     {
364                         int len = strlen(buff);
365                         
366 -                       if (len >= LOG_STR_MAX - loglen)
367 +                       if (len >= logbufflen - loglen)
368                         {
369 -                           debug(DEBUG_APPMSG1, "WARNING: maximum log length exceeded, truncating log");
370 -                           len = LOG_STR_MAX - loglen;
371 -                           buff[len - 1] = '\n';
372 +                           debug(DEBUG_STATUS, "reallocating logbufflen to %d bytes for file %s", logbufflen, file->filename);
373 +                           logbufflen += (len >= LOG_STR_MAX ? (len+1) : LOG_STR_MAX);
374 +                           char * newlogbuff = realloc(logbuff, logbufflen);
375 +                           if (newlogbuff == NULL)
376 +                           {
377 +                               debug(DEBUG_SYSERROR, "could not realloc %d bytes for logbuff in load_from_cvs", logbufflen);
378 +                               exit(1);
379 +                           }
380 +                           logbuff = newlogbuff;
381                         }
382  
383                         debug(DEBUG_STATUS, "appending %s to log", buff);
384 @@ -524,7 +548,7 @@ static void load_from_cvs()
385         exit(1);
386      }
387  
388 -    if (state != NEED_FILE)
389 +    if (state != NEED_RCS_FILE)
390      {
391         debug(DEBUG_APPERROR, "Error: Log file parsing error. (%d)  Use -v to debug", state);
392         exit(1);
393 @@ -1038,8 +1062,8 @@ static void init_paths()
394       *
395       * NOTE: because of some bizarre 'feature' in cvs, when 'rlog' is used
396       * (instead of log) it gives the 'real' RCS file path, which can be different
397 -     * from the 'nominal' repository path because of symlinks in the server and 
398 -     * the like.  See also the 'parse_file' routine
399 +     * from the 'nominal' repository path because of symlinks in the server and
400 +     * the like.  See also the 'parse_rcs_file' routine
401       */
402      strip_path_len = snprintf(strip_path, PATH_MAX, "%s/%s/", p, repository_path);
403  
404 @@ -1052,9 +1076,8 @@ static void init_paths()
405      debug(DEBUG_STATUS, "strip_path: %s", strip_path);
406  }
407  
408 -static CvsFile * parse_file(const char * buff)
409 +static CvsFile * parse_rcs_file(const char * buff)
410  {
411 -    CvsFile * retval;
412      char fn[PATH_MAX];
413      int len = strlen(buff + 10);
414      char * p;
415 @@ -1129,6 +1152,28 @@ static CvsFile * parse_file(const char * buff)
416  
417      debug(DEBUG_STATUS, "stripped filename %s", fn);
418  
419 +    return build_file_by_name(fn);
420 +}
421 +
422 +static CvsFile * parse_working_file(const char * buff)
423 +{
424 +    char fn[PATH_MAX];
425 +    int len = strlen(buff + 14);
426 +
427 +    /* chop the "LF" */
428 +    len -= 1;
429 +    memcpy(fn, buff + 14, len);
430 +    fn[len] = 0;
431 +
432 +    debug(DEBUG_STATUS, "working filename %s", fn);
433 +
434 +    return build_file_by_name(fn);
435 +}
436 +
437 +static CvsFile * build_file_by_name(const char * fn)
438 +{
439 +    CvsFile * retval;
440 +
441      retval = (CvsFile*)get_hash_object(file_hash, fn);
442  
443      if (!retval)
444 @@ -2104,6 +2149,11 @@ static void parse_sym(CvsFile * file, char * sym)
445      
446      if (!get_branch_ext(rev, eot, &leaf))
447      {
448 +       if (strcmp(tag, "TRUNK") == 0)
449 +       {
450 +           debug(DEBUG_STATUS, "ignoring the TRUNK branch/tag");
451 +           return;
452 +       }
453         debug(DEBUG_APPERROR, "malformed revision");
454         exit(1);
455      }
456 @@ -2384,8 +2434,31 @@ void patch_set_add_member(PatchSet * ps, PatchSetMember * psm)
457      for (next = ps->members.next; next != &ps->members; next = next->next) 
458      {
459         PatchSetMember * m = list_entry(next, PatchSetMember, link);
460 -       if (m->file == psm->file && ps->collision_link.next == NULL) 
461 -               list_add(&ps->collision_link, &collisions);
462 +       if (m->file == psm->file) {
463 +               int order = compare_rev_strings(psm->post_rev->rev, m->post_rev->rev);
464 +
465 +               /*
466 +                * Same revision too? Add it to the collision list
467 +                * if it isn't already.
468 +                */
469 +               if (!order) {
470 +                       if (ps->collision_link.next == NULL)
471 +                               list_add(&ps->collision_link, &collisions);
472 +                       return;
473 +               }
474 +
475 +               /*
476 +                * If this is an older revision than the one we already have
477 +                * in this patchset, just ignore it
478 +                */
479 +               if (order < 0)
480 +                       return;
481 +
482 +               /*
483 +                * This is a newer one, remove the old one
484 +                */
485 +               list_del(&m->link);
486 +       }
487      }
488  
489      psm->ps = ps;
490 @@ -2576,7 +2649,7 @@ static void determine_branch_ancestor(PatchSet * ps, PatchSet * head_ps)
491          * note: rev is the pre-commit revision, not the post-commit
492          */
493         if (!head_ps->ancestor_branch)
494 -           d1 = 0;
495 +           d1 = -1;
496         else if (strcmp(ps->branch, rev->branch) == 0)
497             continue;
498         else if (strcmp(head_ps->ancestor_branch, "HEAD") == 0)
499 diff --git a/cvsps_types.h b/cvsps_types.h
500 index b41e2a9..dba145d 100644
501 --- a/cvsps_types.h
502 +++ b/cvsps_types.h
503 @@ -8,7 +8,7 @@
504  
505  #include <time.h>
506  
507 -#define LOG_STR_MAX 32768
508 +#define LOG_STR_MAX 65536
509  #define AUTH_STR_MAX 64
510  #define REV_STR_MAX 64
511  #define MIN(a, b) ((a) < (b) ? (a) : (b))
This page took 0.763186 seconds and 2 git commands to generate.