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