forked from andreyvit/cvsps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cvsps.c
2691 lines (2274 loc) · 68 KB
/
cvsps.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2001, 2002, 2003 David Mansfield and Cobite, Inc.
* See COPYING file for license information
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <unistd.h>
#include <search.h>
#include <time.h>
#include <ctype.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <regex.h>
#include <sys/wait.h> /* for WEXITSTATUS - see system(3) */
#include <cbtcommon/hash.h>
#include <cbtcommon/list.h>
#include <cbtcommon/text_util.h>
#include <cbtcommon/debug.h>
#include <cbtcommon/rcsid.h>
#include "cache.h"
#include "cvsps_types.h"
#include "cvsps.h"
#include "util.h"
#include "stats.h"
#include "cap.h"
#include "cvs_direct.h"
#include "list_sort.h"
RCSID("$Id: cvsps.c,v 4.106 2005/05/26 03:39:29 david Exp $");
#define CVS_LOG_BOUNDARY "----------------------------\n"
#define CVS_FILE_BOUNDARY "=============================================================================\n"
enum
{
NEED_RCS_FILE,
NEED_WORKING_FILE,
NEED_SYMS,
NEED_EOS,
NEED_START_LOG,
NEED_REVISION,
NEED_DATE_AUTHOR_STATE,
NEED_EOM
};
/* true globals */
struct hash_table * file_hash;
CvsServerCtx * cvs_direct_ctx;
char root_path[PATH_MAX];
char repository_path[PATH_MAX];
const char * tag_flag_descr[] = {
"",
"**FUNKY**",
"**INVALID**",
"**INVALID**"
};
const char * fnk_descr[] = {
"",
"FNK_SHOW_SOME",
"FNK_SHOW_ALL",
"FNK_HIDE_ALL",
"FNK_HIDE_SOME"
};
/* static globals */
static int ps_counter;
static void * ps_tree;
static struct hash_table * global_symbols;
static char strip_path[PATH_MAX];
static int strip_path_len;
static time_t cache_date;
static int update_cache;
static int ignore_cache;
static int do_write_cache;
static int statistics;
static const char * test_log_file;
static struct hash_table * branch_heads;
static struct list_head all_patch_sets;
static struct list_head collisions;
/* settable via options */
static int timestamp_fuzz_factor = 300;
static int do_diff;
static const char * restrict_author;
static int have_restrict_log;
static regex_t restrict_log;
static int have_restrict_file;
static regex_t restrict_file;
static time_t restrict_date_start;
static time_t restrict_date_end;
static const char * restrict_branch;
static struct list_head show_patch_set_ranges;
static int summary_first;
static const char * norc = "";
static const char * patch_set_dir;
static const char * restrict_tag_start;
static const char * restrict_tag_end;
static int restrict_tag_ps_start;
static int restrict_tag_ps_end = INT_MAX;
static const char * diff_opts;
static int bkcvs;
static int no_rlog;
static int cvs_direct;
static int compress;
static char compress_arg[8];
static int track_branch_ancestry;
static void check_norc(int, char *[]);
static int parse_args(int, char *[]);
static int parse_rc();
static void load_from_cvs();
static void init_paths();
static CvsFile * build_file_by_name(const char *);
static CvsFile * parse_rcs_file(const char *);
static CvsFile * parse_working_file(const char *);
static CvsFileRevision * parse_revision(CvsFile * file, char * rev_str);
static void assign_pre_revision(PatchSetMember *, CvsFileRevision * rev);
static void check_print_patch_set(PatchSet *);
static void print_patch_set(PatchSet *);
static void assign_patchset_id(PatchSet *);
static int compare_rev_strings(const char *, const char *);
static int compare_patch_sets_by_members(const PatchSet * ps1, const PatchSet * ps2);
static int compare_patch_sets_bk(const void *, const void *);
static int compare_patch_sets(const void *, const void *);
static int compare_patch_sets_bytime_list(struct list_head *, struct list_head *);
static int compare_patch_sets_bytime(const PatchSet *, const PatchSet *);
static int is_revision_metadata(const char *);
static int patch_set_member_regex(PatchSet * ps, regex_t * reg);
static int patch_set_affects_branch(PatchSet *, const char *);
static void do_cvs_diff(PatchSet *);
static PatchSet * create_patch_set();
static PatchSetRange * create_patch_set_range();
static void parse_sym(CvsFile *, char *);
static void resolve_global_symbols();
static int revision_affects_branch(CvsFileRevision *, const char *);
static int is_vendor_branch(const char *);
static void set_psm_initial(PatchSetMember * psm);
static int check_rev_funk(PatchSet *, CvsFileRevision *);
static CvsFileRevision * rev_follow_branch(CvsFileRevision *, const char *);
static int before_tag(CvsFileRevision * rev, const char * tag);
static void determine_branch_ancestor(PatchSet * ps, PatchSet * head_ps);
static void handle_collisions();
int main(int argc, char *argv[])
{
debuglvl = DEBUG_APPERROR|DEBUG_SYSERROR|DEBUG_APPMSG1;
INIT_LIST_HEAD(&show_patch_set_ranges);
/*
* we want to parse the rc first, so command line can override it
* but also, --norc should stop the rc from being processed, so
* we look for --norc explicitly first. Note: --norc in the rc
* file itself will prevent the cvs rc file from being used.
*/
check_norc(argc, argv);
if (strlen(norc) == 0 && parse_rc() < 0)
exit(1);
if (parse_args(argc, argv) < 0)
exit(1);
if (diff_opts && !cvs_direct && do_diff)
{
debug(DEBUG_APPMSG1, "\nWARNING: diff options are not supported by 'cvs rdiff'");
debug(DEBUG_APPMSG1, " which is usually used to create diffs. 'cvs diff'");
debug(DEBUG_APPMSG1, " will be used instead, but the resulting patches ");
debug(DEBUG_APPMSG1, " will need to be applied using the '-p0' option");
debug(DEBUG_APPMSG1, " to patch(1) (in the working directory), ");
debug(DEBUG_APPMSG1, " instead of '-p1'\n");
}
file_hash = create_hash_table(1023);
global_symbols = create_hash_table(111);
branch_heads = create_hash_table(1023);
INIT_LIST_HEAD(&all_patch_sets);
INIT_LIST_HEAD(&collisions);
/* this parses some of the CVS/ files, and initializes
* the repository_path and other variables
*/
init_paths();
if (!ignore_cache)
{
int save_fuzz_factor = timestamp_fuzz_factor;
/* the timestamp fuzz should only be in effect when loading from
* CVS, not re-fuzzed when loading from cache. This is a hack
* working around bad use of global variables
*/
timestamp_fuzz_factor = 0;
if ((cache_date = read_cache()) < 0)
update_cache = 1;
timestamp_fuzz_factor = save_fuzz_factor;
}
if (cvs_direct && (do_diff || (update_cache && !test_log_file)))
cvs_direct_ctx = open_cvs_server(root_path, compress);
if (update_cache)
{
load_from_cvs();
do_write_cache = 1;
}
//XXX
//handle_collisions();
list_sort(&all_patch_sets, compare_patch_sets_bytime_list);
ps_counter = 0;
walk_all_patch_sets(assign_patchset_id);
handle_collisions();
resolve_global_symbols();
if (do_write_cache)
write_cache(cache_date);
if (statistics)
print_statistics(ps_tree);
/* check that the '-r' symbols (if specified) were resolved */
if (restrict_tag_start && restrict_tag_ps_start == 0 &&
strcmp(restrict_tag_start, "#CVSPS_EPOCH") != 0)
{
debug(DEBUG_APPERROR, "symbol given with -r: %s: not found", restrict_tag_start);
exit(1);
}
if (restrict_tag_end && restrict_tag_ps_end == INT_MAX)
{
debug(DEBUG_APPERROR, "symbol given with second -r: %s: not found", restrict_tag_end);
exit(1);
}
walk_all_patch_sets(check_print_patch_set);
if (summary_first++)
walk_all_patch_sets(check_print_patch_set);
if (cvs_direct_ctx)
close_cvs_server(cvs_direct_ctx);
exit(0);
}
static void load_from_cvs()
{
FILE * cvsfp;
char buff[BUFSIZ];
int state = NEED_RCS_FILE;
CvsFile * file = NULL;
PatchSetMember * psm = NULL;
char datebuff[20];
char authbuff[AUTH_STR_MAX];
int logbufflen = LOG_STR_MAX + 1;
char * logbuff = malloc(logbufflen);
int loglen = 0;
int have_log = 0;
char cmd[BUFSIZ];
char date_str[64];
char use_rep_buff[PATH_MAX];
char * ltype;
if (logbuff == NULL)
{
debug(DEBUG_SYSERROR, "could not malloc %d bytes for logbuff in load_from_cvs", logbufflen);
exit(1);
}
if (!no_rlog && !test_log_file && cvs_check_cap(CAP_HAVE_RLOG))
{
ltype = "rlog";
snprintf(use_rep_buff, PATH_MAX, "%s", repository_path);
}
else
{
ltype = "log";
use_rep_buff[0] = 0;
}
if (cache_date > 0)
{
struct tm * tm = gmtime(&cache_date);
strftime(date_str, 64, "%d %b %Y %H:%M:%S %z", tm);
/* this command asks for logs using two different date
* arguments, separated by ';' (see man rlog). The first
* gets all revisions more recent than date, the second
* gets a single revision no later than date, which combined
* get us all revisions that have occurred since last update
* and overlaps what we had before by exactly one revision,
* which is necessary to fill in the pre_rev stuff for a
* PatchSetMember
*/
snprintf(cmd, BUFSIZ, "cvs %s %s -q %s -d '%s<;%s' %s", compress_arg, norc, ltype, date_str, date_str, use_rep_buff);
}
else
{
date_str[0] = 0;
snprintf(cmd, BUFSIZ, "cvs %s %s -q %s %s", compress_arg, norc, ltype, use_rep_buff);
}
debug(DEBUG_STATUS, "******* USING CMD %s", cmd);
cache_date = time(NULL);
/* FIXME: this is ugly, need to virtualize the accesses away from here */
if (test_log_file)
cvsfp = fopen(test_log_file, "r");
else if (cvs_direct_ctx)
cvsfp = cvs_rlog_open(cvs_direct_ctx, repository_path, date_str);
else
cvsfp = popen(cmd, "r");
if (!cvsfp)
{
debug(DEBUG_SYSERROR, "can't open cvs pipe using command %s", cmd);
exit(1);
}
for (;;)
{
char * tst;
if (cvs_direct_ctx)
tst = cvs_rlog_fgets(buff, BUFSIZ, cvs_direct_ctx);
else
tst = fgets(buff, BUFSIZ, cvsfp);
if (!tst)
break;
debug(DEBUG_STATUS, "state: %d read line:%s", state, buff);
switch(state)
{
case NEED_RCS_FILE:
if (strncmp(buff, "RCS file", 8) == 0) {
if ((file = parse_rcs_file(buff)) != NULL)
state = NEED_SYMS;
else
state = NEED_WORKING_FILE;
}
break;
case NEED_WORKING_FILE:
if (strncmp(buff, "Working file", 12) == 0) {
if ((file = parse_working_file(buff)))
state = NEED_SYMS;
else
state = NEED_RCS_FILE;
break;
} else {
// Working file come just after RCS file. So reset state if it was not found
state = NEED_RCS_FILE;
}
break;
case NEED_SYMS:
if (strncmp(buff, "symbolic names:", 15) == 0)
state = NEED_EOS;
break;
case NEED_EOS:
if (!isspace(buff[0]))
{
/* see cvsps_types.h for commentary on have_branches */
file->have_branches = 1;
state = NEED_START_LOG;
}
else
parse_sym(file, buff);
break;
case NEED_START_LOG:
if (strcmp(buff, CVS_LOG_BOUNDARY) == 0)
state = NEED_REVISION;
break;
case NEED_REVISION:
if (strncmp(buff, "revision", 8) == 0)
{
char new_rev[REV_STR_MAX];
CvsFileRevision * rev;
strcpy(new_rev, buff + 9);
chop(new_rev);
/*
* rev may already exist (think cvsps -u), in which
* case parse_revision is a hash lookup
*/
rev = parse_revision(file, new_rev);
/*
* in the simple case, we are copying rev to psm->pre_rev
* (psm refers to last patch set processed at this point)
* since generally speaking the log is reverse chronological.
* This breaks down slightly when branches are introduced
*/
assign_pre_revision(psm, rev);
/*
* if this is a new revision, it will have no post_psm associated.
* otherwise we are (probably?) hitting the overlap in cvsps -u
*/
if (!rev->post_psm)
{
psm = rev->post_psm = create_patch_set_member();
psm->post_rev = rev;
psm->file = file;
state = NEED_DATE_AUTHOR_STATE;
}
else
{
/* we hit this in cvsps -u mode, we are now up-to-date
* w.r.t this particular file. skip all of the rest
* of the info (revs and logs) until we hit the next file
*/
psm = NULL;
state = NEED_EOM;
}
}
break;
case NEED_DATE_AUTHOR_STATE:
if (strncmp(buff, "date:", 5) == 0)
{
char * p;
strncpy(datebuff, buff + 6, 19);
datebuff[19] = 0;
strcpy(authbuff, "unknown");
p = strstr(buff, "author: ");
if (p)
{
char * op;
p += 8;
op = strchr(p, ';');
if (op)
{
strzncpy(authbuff, p, op - p + 1);
}
}
/* read the 'state' tag to see if this is a dead revision */
p = strstr(buff, "state: ");
if (p)
{
char * op;
p += 7;
op = strchr(p, ';');
if (op)
if (strncmp(p, "dead", MIN(4, op - p)) == 0)
psm->post_rev->dead = 1;
}
state = NEED_EOM;
}
break;
case NEED_EOM:
if (strcmp(buff, CVS_LOG_BOUNDARY) == 0)
{
if (psm)
{
PatchSet * ps = get_patch_set(datebuff, logbuff, authbuff, psm->post_rev->branch, psm);
patch_set_add_member(ps, psm);
}
logbuff[0] = 0;
loglen = 0;
have_log = 0;
state = NEED_REVISION;
}
else if (strcmp(buff, CVS_FILE_BOUNDARY) == 0)
{
if (psm)
{
PatchSet * ps = get_patch_set(datebuff, logbuff, authbuff, psm->post_rev->branch, psm);
patch_set_add_member(ps, psm);
assign_pre_revision(psm, NULL);
}
logbuff[0] = 0;
loglen = 0;
have_log = 0;
psm = NULL;
file = NULL;
state = NEED_RCS_FILE;
}
else
{
/* other "blahblah: information;" messages can
* follow the stuff we pay attention to
*/
if (have_log || !is_revision_metadata(buff))
{
/* If the log buffer is full, try to reallocate more. */
if (loglen < logbufflen)
{
int len = strlen(buff);
if (len >= logbufflen - loglen)
{
debug(DEBUG_STATUS, "reallocating logbufflen to %d bytes for file %s", logbufflen, file->filename);
logbufflen += (len >= LOG_STR_MAX ? (len+1) : LOG_STR_MAX);
char * newlogbuff = realloc(logbuff, logbufflen);
if (newlogbuff == NULL)
{
debug(DEBUG_SYSERROR, "could not realloc %d bytes for logbuff in load_from_cvs", logbufflen);
exit(1);
}
logbuff = newlogbuff;
}
debug(DEBUG_STATUS, "appending %s to log", buff);
memcpy(logbuff + loglen, buff, len);
loglen += len;
logbuff[loglen] = 0;
have_log = 1;
}
}
else
{
debug(DEBUG_STATUS, "ignoring unhandled info %s", buff);
}
}
break;
}
}
if (state == NEED_SYMS)
{
debug(DEBUG_APPERROR, "Error: 'symbolic names' not found in log output.");
debug(DEBUG_APPERROR, " Perhaps you should try running with --norc");
exit(1);
}
if (state != NEED_RCS_FILE)
{
debug(DEBUG_APPERROR, "Error: Log file parsing error. (%d) Use -v to debug", state);
exit(1);
}
if (test_log_file)
{
fclose(cvsfp);
}
else if (cvs_direct_ctx)
{
cvs_rlog_close(cvs_direct_ctx);
}
else
{
if (pclose(cvsfp) < 0)
{
debug(DEBUG_APPERROR, "cvs rlog command exited with error. aborting");
exit(1);
}
}
}
static int usage(const char * str1, const char * str2)
{
if (str1)
debug(DEBUG_APPERROR, "\nbad usage: %s %s\n", str1, str2);
debug(DEBUG_APPERROR, "Usage: cvsps [-h] [-x] [-u] [-z <fuzz>] [-g] [-s <range>[,<range>]] ");
debug(DEBUG_APPERROR, " [-a <author>] [-f <file>] [-d <date1> [-d <date2>]] ");
debug(DEBUG_APPERROR, " [-b <branch>] [-l <regex>] [-r <tag> [-r <tag>]] ");
debug(DEBUG_APPERROR, " [-p <directory>] [-v] [-t] [--norc] [--summary-first]");
debug(DEBUG_APPERROR, " [--test-log <captured cvs log file>] [--bkcvs]");
debug(DEBUG_APPERROR, " [--no-rlog] [--diff-opts <option string>] [--cvs-direct]");
debug(DEBUG_APPERROR, " [--debuglvl <bitmask>] [-Z <compression>] [--root <cvsroot>]");
debug(DEBUG_APPERROR, " [-q] [-A] [<repository>]");
debug(DEBUG_APPERROR, "");
debug(DEBUG_APPERROR, "Where:");
debug(DEBUG_APPERROR, " -h display this informative message");
debug(DEBUG_APPERROR, " -x ignore (and rebuild) cvsps.cache file");
debug(DEBUG_APPERROR, " -u update cvsps.cache file");
debug(DEBUG_APPERROR, " -z <fuzz> set the timestamp fuzz factor for identifying patch sets");
debug(DEBUG_APPERROR, " -g generate diffs of the selected patch sets");
debug(DEBUG_APPERROR, " -s <patch set>[-[<patch set>]][,<patch set>...] restrict patch sets by id");
debug(DEBUG_APPERROR, " -a <author> restrict output to patch sets created by author");
debug(DEBUG_APPERROR, " -f <file> restrict output to patch sets involving file");
debug(DEBUG_APPERROR, " -d <date1> -d <date2> if just one date specified, show");
debug(DEBUG_APPERROR, " revisions newer than date1. If two dates specified,");
debug(DEBUG_APPERROR, " show revisions between two dates.");
debug(DEBUG_APPERROR, " -b <branch> restrict output to patch sets affecting history of branch");
debug(DEBUG_APPERROR, " -l <regex> restrict output to patch sets matching <regex> in log message");
debug(DEBUG_APPERROR, " -r <tag1> -r <tag2> if just one tag specified, show");
debug(DEBUG_APPERROR, " revisions since tag1. If two tags specified, show");
debug(DEBUG_APPERROR, " revisions between the two tags.");
debug(DEBUG_APPERROR, " -p <directory> output patch sets to individual files in <directory>");
debug(DEBUG_APPERROR, " -v show very verbose parsing messages");
debug(DEBUG_APPERROR, " -t show some brief memory usage statistics");
debug(DEBUG_APPERROR, " --norc when invoking cvs, ignore the .cvsrc file");
debug(DEBUG_APPERROR, " --summary-first when multiple patch sets are shown, put all summaries first");
debug(DEBUG_APPERROR, " --test-log <captured cvs log> supply a captured cvs log for testing");
debug(DEBUG_APPERROR, " --diff-opts <option string> supply special set of options to diff");
debug(DEBUG_APPERROR, " --bkcvs special hack for parsing the BK -> CVS log format");
debug(DEBUG_APPERROR, " --no-rlog disable rlog (it's faulty in some setups)");
debug(DEBUG_APPERROR, " --cvs-direct (--no-cvs-direct) enable (disable) built-in cvs client code");
debug(DEBUG_APPERROR, " --debuglvl <bitmask> enable various debug channels.");
debug(DEBUG_APPERROR, " -Z <compression> A value 1-9 which specifies amount of compression");
debug(DEBUG_APPERROR, " --root <cvsroot> specify cvsroot. overrides env. and working directory (cvs-direct only)");
debug(DEBUG_APPERROR, " -q be quiet about warnings");
debug(DEBUG_APPERROR, " -A track and report branch ancestry");
debug(DEBUG_APPERROR, " <repository> apply cvsps to repository. overrides working directory");
debug(DEBUG_APPERROR, "\ncvsps version %s\n", VERSION);
return -1;
}
static int parse_args(int argc, char *argv[])
{
int i = 1;
while (i < argc)
{
if (strcmp(argv[i], "-z") == 0)
{
if (++i >= argc)
return usage("argument to -z missing", "");
timestamp_fuzz_factor = atoi(argv[i++]);
continue;
}
if (strcmp(argv[i], "-g") == 0)
{
do_diff = 1;
i++;
continue;
}
if (strcmp(argv[i], "-s") == 0)
{
PatchSetRange * range;
char * min_str, * max_str;
if (++i >= argc)
return usage("argument to -s missing", "");
min_str = strtok(argv[i++], ",");
do
{
range = create_patch_set_range();
max_str = strrchr(min_str, '-');
if (max_str)
*max_str++ = '\0';
else
max_str = min_str;
range->min_counter = atoi(min_str);
if (*max_str)
range->max_counter = atoi(max_str);
else
range->max_counter = INT_MAX;
list_add(&range->link, show_patch_set_ranges.prev);
}
while ((min_str = strtok(NULL, ",")));
continue;
}
if (strcmp(argv[i], "-a") == 0)
{
if (++i >= argc)
return usage("argument to -a missing", "");
restrict_author = argv[i++];
continue;
}
if (strcmp(argv[i], "-l") == 0)
{
int err;
if (++i >= argc)
return usage("argument to -l missing", "");
if ((err = regcomp(&restrict_log, argv[i++], REG_EXTENDED|REG_NOSUB)) != 0)
{
char errbuf[256];
regerror(err, &restrict_log, errbuf, 256);
return usage("bad regex to -l", errbuf);
}
have_restrict_log = 1;
continue;
}
if (strcmp(argv[i], "-f") == 0)
{
int err;
if (++i >= argc)
return usage("argument to -f missing", "");
if ((err = regcomp(&restrict_file, argv[i++], REG_EXTENDED|REG_NOSUB)) != 0)
{
char errbuf[256];
regerror(err, &restrict_file, errbuf, 256);
return usage("bad regex to -f", errbuf);
}
have_restrict_file = 1;
continue;
}
if (strcmp(argv[i], "-d") == 0)
{
time_t *pt;
if (++i >= argc)
return usage("argument to -d missing", "");
pt = (restrict_date_start == 0) ? &restrict_date_start : &restrict_date_end;
convert_date(pt, argv[i++]);
continue;
}
if (strcmp(argv[i], "-r") == 0)
{
if (++i >= argc)
return usage("argument to -r missing", "");
if (restrict_tag_start)
restrict_tag_end = argv[i];
else
restrict_tag_start = argv[i];
i++;
continue;
}
if (strcmp(argv[i], "-u") == 0)
{
update_cache = 1;
i++;
continue;
}
if (strcmp(argv[i], "-x") == 0)
{
ignore_cache = 1;
update_cache = 1;
i++;
continue;
}
if (strcmp(argv[i], "-b") == 0)
{
if (++i >= argc)
return usage("argument to -b missing", "");
restrict_branch = argv[i++];
/* Warn if the user tries to use TRUNK. Should eventually
* go away as TRUNK may be a valid branch within CVS
*/
if (strcmp(restrict_branch, "TRUNK") == 0)
debug(DEBUG_APPMSG1, "WARNING: The HEAD branch of CVS is called HEAD, not TRUNK");
continue;
}
if (strcmp(argv[i], "-p") == 0)
{
if (++i >= argc)
return usage("argument to -p missing", "");
patch_set_dir = argv[i++];
continue;
}
if (strcmp(argv[i], "-v") == 0)
{
debuglvl = ~0;
i++;
continue;
}
if (strcmp(argv[i], "-t") == 0)
{
statistics = 1;
i++;
continue;
}
if (strcmp(argv[i], "--summary-first") == 0)
{
summary_first = 1;
i++;
continue;
}
if (strcmp(argv[i], "-h") == 0)
return usage(NULL, NULL);
/* see special handling of --norc in main */
if (strcmp(argv[i], "--norc") == 0)
{
norc = "-f";
i++;
continue;
}
if (strcmp(argv[i], "--test-log") == 0)
{
if (++i >= argc)
return usage("argument to --test-log missing", "");
test_log_file = argv[i++];
continue;
}
if (strcmp(argv[i], "--diff-opts") == 0)
{
if (++i >= argc)
return usage("argument to --diff-opts missing", "");
/* allow diff_opts to be turned off by making empty string
* into NULL
*/
if (!strlen(argv[i]))
diff_opts = NULL;
else
diff_opts = argv[i];
i++;
continue;
}
if (strcmp(argv[i], "--bkcvs") == 0)
{
bkcvs = 1;
i++;
continue;
}
if (strcmp(argv[i], "--no-rlog") == 0)
{
no_rlog = 1;
i++;
continue;
}
if (strcmp(argv[i], "--cvs-direct") == 0)
{
cvs_direct = 1;
i++;
continue;
}
if (strcmp(argv[i], "--no-cvs-direct") == 0)
{
cvs_direct = 0;
i++;
continue;
}
if (strcmp(argv[i], "--debuglvl") == 0)
{
if (++i >= argc)
return usage("argument to --debuglvl missing", "");
debuglvl = atoi(argv[i++]);
continue;
}
if (strcmp(argv[i], "-Z") == 0)
{
if (++i >= argc)
return usage("argument to -Z", "");
compress = atoi(argv[i++]);
if (compress < 0 || compress > 9)
return usage("-Z level must be between 1 and 9 inclusive (0 disables compression)", argv[i-1]);
if (compress == 0)
compress_arg[0] = 0;
else
snprintf(compress_arg, 8, "-z%d", compress);
continue;
}
if (strcmp(argv[i], "--root") == 0)
{
if (++i >= argc)
return usage("argument to --root missing", "");
strcpy(root_path, argv[i++]);
continue;
}
if (strcmp(argv[i], "-q") == 0)
{
debuglvl &= ~DEBUG_APPMSG1;
i++;
continue;
}
if (strcmp(argv[i], "-A") == 0)
{
track_branch_ancestry = 1;
i++;
continue;
}
if (argv[i][0] == '-')
return usage("invalid argument", argv[i]);
strcpy(repository_path, argv[i++]);
}
return 0;
}
static int parse_rc()
{
char rcfile[PATH_MAX];
FILE * fp;
snprintf(rcfile, PATH_MAX, "%s/cvspsrc", get_cvsps_dir());
if ((fp = fopen(rcfile, "r")))
{
char buff[BUFSIZ];
while (fgets(buff, BUFSIZ, fp))
{
char * argv[3], *p;
int argc = 2;
chop(buff);
argv[0] = "garbage";
p = strchr(buff, ' ');
if (p)
{
*p++ = '\0';
argv[2] = xstrdup(p);
argc = 3;
}
argv[1] = xstrdup(buff);
if (parse_args(argc, argv) < 0)
return -1;
}
fclose(fp);
}
return 0;
}
static void init_paths()
{
FILE * fp;
char * p;
int len;
/* determine the CVSROOT. precedence:
* 1) command line
* 2) working directory (if present)
* 3) environment variable CVSROOT
*/
if (!root_path[0])
{
if (!(fp = fopen("CVS/Root", "r")))
{
const char * e;
debug(DEBUG_STATUS, "Can't open CVS/Root");
e = getenv("CVSROOT");
if (!e)
{
debug(DEBUG_APPERROR, "cannot determine CVSROOT");
exit(1);
}
strcpy(root_path, e);
}
else
{