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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
|
/*
* Copyright (C) 1986-2005 The Free Software Foundation, Inc.
*
* Portions Copyright (C) 1998-2005 Derek Price, Ximbiot <http://ximbiot.com>,
* and others.
*
* Portions Copyright (C) 1992, Brian Berliner and Jeff Polk
* Portions Copyright (C) 1989-1992, Brian Berliner
*
* You may distribute under the terms of the GNU General Public License as
* specified in the README file that comes with the CVS source distribution.
*
* Tag and Rtag
*
* Add or delete a symbolic name to an RCS file, or a collection of RCS files.
* Tag uses the checked out revision in the current directory, rtag uses
* the modules database, if necessary.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: tag.c,v 1.5 2019/01/05 00:27:58 christos Exp $");
#include "cvs.h"
#include <grp.h>
#include "save-cwd.h"
static int rtag_proc (int argc, char **argv, char *xwhere,
char *mwhere, char *mfile, int shorten,
int local_specified, char *mname, char *msg);
static int check_fileproc (void *callerdat, struct file_info *finfo);
static int check_filesdoneproc (void *callerdat, int err,
const char *repos, const char *update_dir,
List *entries);
static int pretag_proc (const char *_repository, const char *_filter,
void *_closure);
static void masterlist_delproc (Node *_p);
static void tag_delproc (Node *_p);
static int pretag_list_to_args_proc (Node *_p, void *_closure);
static Dtype tag_dirproc (void *callerdat, const char *dir,
const char *repos, const char *update_dir,
List *entries);
static int rtag_fileproc (void *callerdat, struct file_info *finfo);
static int rtag_delete (RCSNode *rcsfile);
static int tag_fileproc (void *callerdat, struct file_info *finfo);
static char *numtag; /* specific revision to tag */
static bool numtag_validated = false;
static char *date = NULL;
static char *symtag; /* tag to add or delete */
static bool delete_flag; /* adding a tag by default */
static bool branch_mode; /* make an automagic "branch" tag */
static bool disturb_branch_tags = false;/* allow -F,-d to disturb branch tags */
static bool force_tag_match = true; /* force tag to match by default */
static bool force_tag_move; /* don't force tag to move by default */
static bool check_uptodate; /* no uptodate-check by default */
static bool attic_too; /* remove tag from Attic files */
static bool is_rtag;
struct tag_info
{
Ctype status;
char *oldrev;
char *rev;
char *tag;
char *options;
};
struct master_lists
{
List *tlist;
};
static List *mtlist;
static const char rtag_opts[] = "+aBbdFflnQqRr:D:";
static const char *const rtag_usage[] =
{
"Usage: %s %s [-abdFflnR] [-r rev|-D date] tag modules...\n",
"\t-a\tClear tag from removed files that would not otherwise be tagged.\n",
"\t-b\tMake the tag a \"branch\" tag, allowing concurrent development.\n",
"\t-B\tAllows -F and -d to disturb branch tags. Use with extreme care.\n",
"\t-d\tDelete the given tag.\n",
"\t-F\tMove tag if it already exists.\n",
"\t-f\tForce a head revision match if tag/date not found.\n",
"\t-l\tLocal directory only, not recursive.\n",
"\t-n\tNo execution of 'tag program'.\n",
"\t-R\tProcess directories recursively.\n",
"\t-r rev\tExisting revision/tag.\n",
"\t-D\tExisting date.\n",
"(Specify the --help global option for a list of other help options)\n",
NULL
};
static const char tag_opts[] = "+BbcdFflQqRr:D:";
static const char *const tag_usage[] =
{
"Usage: %s %s [-bcdFflR] [-r rev|-D date] tag [files...]\n",
"\t-b\tMake the tag a \"branch\" tag, allowing concurrent development.\n",
"\t-B\tAllows -F and -d to disturb branch tags. Use with extreme care.\n",
"\t-c\tCheck that working files are unmodified.\n",
"\t-d\tDelete the given tag.\n",
"\t-F\tMove tag if it already exists.\n",
"\t-f\tForce a head revision match if tag/date not found.\n",
"\t-l\tLocal directory only, not recursive.\n",
"\t-R\tProcess directories recursively.\n",
"\t-r rev\tExisting revision/tag.\n",
"\t-D\tExisting date.\n",
"(Specify the --help global option for a list of other help options)\n",
NULL
};
char *UserTagOptions = "bcflRrD";
int
cvstag (int argc, char **argv)
{
struct group *grp;
bool local = false; /* recursive by default */
int c;
int err = 0;
bool run_module_prog = true;
int only_allowed_options;
is_rtag = (strcmp (cvs_cmd_name, "rtag") == 0);
if (argc == -1)
usage (is_rtag ? rtag_usage : tag_usage);
getoptreset ();
only_allowed_options = 1;
while ((c = getopt (argc, argv, is_rtag ? rtag_opts : tag_opts)) != -1)
{
if (!strchr(UserTagOptions, c))
only_allowed_options = 0;
switch (c)
{
case 'a':
attic_too = true;
break;
case 'b':
branch_mode = true;
break;
case 'B':
disturb_branch_tags = true;
break;
case 'c':
check_uptodate = true;
break;
case 'd':
delete_flag = true;
break;
case 'F':
force_tag_move = true;
break;
case 'f':
force_tag_match = false;
break;
case 'l':
local = true;
break;
case 'n':
run_module_prog = false;
break;
case 'Q':
case 'q':
/* The CVS 1.5 client sends these options (in addition to
Global_option requests), so we must ignore them. */
if (!server_active)
error (1, 0,
"-q or -Q must be specified before \"%s\"",
cvs_cmd_name);
break;
case 'R':
local = false;
break;
case 'r':
parse_tagdate (&numtag, &date, optarg);
break;
case 'D':
if (date) free (date);
date = Make_Date (optarg);
break;
case '?':
default:
usage (is_rtag ? rtag_usage : tag_usage);
break;
}
}
argc -= optind;
argv += optind;
if (argc < (is_rtag ? 2 : 1))
usage (is_rtag ? rtag_usage : tag_usage);
symtag = argv[0];
argc--;
argv++;
if (date && delete_flag)
error (1, 0, "-d makes no sense with a date specification.");
if (delete_flag && branch_mode)
error (0, 0, "warning: -b ignored with -d options");
RCS_check_tag (symtag);
#ifdef CVS_ADMIN_GROUP
if (!only_allowed_options &&
(grp = getgrnam(CVS_ADMIN_GROUP)) != NULL)
{
#ifdef HAVE_GETGROUPS
gid_t *grps;
int i, n;
/* get number of auxiliary groups */
n = getgroups (0, NULL);
if (n < 0)
error (1, errno, "unable to get number of auxiliary groups");
grps = (gid_t *) xmalloc((n + 1) * sizeof *grps);
n = getgroups (n, grps);
if (n < 0)
error (1, errno, "unable to get list of auxiliary groups");
grps[n] = getgid();
for (i = 0; i <= n; i++)
if (grps[i] == grp->gr_gid) break;
free (grps);
if (i > n)
error (1, 0, "usage is restricted to members of the group %s",
CVS_ADMIN_GROUP);
#else
char *me = getcaller();
char **grnam;
for (grnam = grp->gr_mem; *grnam; grnam++)
if (strcmp (*grnam, me) == 0) break;
if (!*grnam && getgid() != grp->gr_gid)
error (1, 0, "usage is restricted to members of the group %s",
CVS_ADMIN_GROUP);
#endif
}
#endif /* defined CVS_ADMIN_GROUP */
#ifdef CLIENT_SUPPORT
if (current_parsed_root->isremote)
{
/* We're the client side. Fire up the remote server. */
start_server ();
ign_setup ();
if (attic_too)
send_arg ("-a");
if (branch_mode)
send_arg ("-b");
if (disturb_branch_tags)
send_arg ("-B");
if (check_uptodate)
send_arg ("-c");
if (delete_flag)
send_arg ("-d");
if (force_tag_move)
send_arg ("-F");
if (!force_tag_match)
send_arg ("-f");
if (local)
send_arg ("-l");
if (!run_module_prog)
send_arg ("-n");
if (numtag)
option_with_arg ("-r", numtag);
if (date)
client_senddate (date);
send_arg ("--");
send_arg (symtag);
if (is_rtag)
{
int i;
for (i = 0; i < argc; ++i)
send_arg (argv[i]);
send_to_server ("rtag\012", 0);
}
else
{
send_files (argc, argv, local, 0,
/* I think the -c case is like "cvs status", in
which we really better be correct rather than
being fast; it is just too confusing otherwise. */
check_uptodate ? 0 : SEND_NO_CONTENTS);
send_file_names (argc, argv, SEND_EXPAND_WILD);
send_to_server ("tag\012", 0);
}
return get_responses_and_close ();
}
#endif
if (is_rtag)
{
DBM *db;
int i;
db = open_module ();
for (i = 0; i < argc; i++)
{
/* XXX last arg should be repository, but doesn't make sense here */
history_write ('T', (delete_flag ? "D" : (numtag ? numtag :
(date ? date : "A"))), symtag, argv[i], "");
err += do_module (db, argv[i], TAG,
delete_flag ? "Untagging" : "Tagging",
rtag_proc, NULL, 0, local, run_module_prog,
0, symtag);
}
close_module (db);
}
else
{
int i;
for (i = 0; i < argc; i++)
{
/* XXX last arg should be repository, but doesn't make sense here */
history_write ('T', (delete_flag ? "D" : (numtag ? numtag :
(date ? date : "A"))), symtag, argv[i], "");
}
err = rtag_proc (argc + 1, argv - 1, NULL, NULL, NULL, 0, local, NULL,
NULL);
}
return err;
}
struct pretag_proc_data {
List *tlist;
bool delete_flag;
bool force_tag_move;
char *symtag;
};
/*
* called from Parse_Info, this routine processes a line that came out
* of the posttag file and turns it into a command and executes it.
*
* RETURNS
* the absolute value of the return value of run_exec, which may or
* may not be the return value of the child process. this is
* contrained to return positive values because Parse_Info is summing
* return values and testing for non-zeroness to signify one or more
* of its callbacks having returned an error.
*/
static int
posttag_proc (const char *repository, const char *filter, void *closure)
{
char *cmdline;
const char *srepos = Short_Repository (repository);
struct pretag_proc_data *ppd = closure;
/* %t = tag being added/moved/removed
* %o = operation = "add" | "mov" | "del"
* %b = branch mode = "?" (delete ops - unknown) | "T" (branch)
* | "N" (not branch)
* %c = cvs_cmd_name
* %p = path from $CVSROOT
* %r = path from root
* %{sVv} = attribute list = file name, old version tag will be deleted
* from, new version tag will be added to (or
* deleted from until
* SUPPORT_OLD_INFO_FMT_STRINGS is undefined).
*/
/*
* Cast any NULL arguments as appropriate pointers as this is an
* stdarg function and we need to be certain the caller gets what
* is expected.
*/
cmdline = format_cmdline (
#ifdef SUPPORT_OLD_INFO_FMT_STRINGS
false, srepos,
#endif /* SUPPORT_OLD_INFO_FMT_STRINGS */
filter,
"t", "s", ppd->symtag,
"o", "s", ppd->delete_flag
? "del" : ppd->force_tag_move ? "mov" : "add",
"b", "c", delete_flag
? '?' : branch_mode ? 'T' : 'N',
"c", "s", cvs_cmd_name,
#ifdef SERVER_SUPPORT
"R", "s", referrer ? referrer->original : "NONE",
#endif /* SERVER_SUPPORT */
"p", "s", srepos,
"r", "s", current_parsed_root->directory,
"sVv", ",", ppd->tlist,
pretag_list_to_args_proc, (void *) NULL,
(char *) NULL);
if (!cmdline || !strlen (cmdline))
{
if (cmdline) free (cmdline);
error (0, 0, "pretag proc resolved to the empty string!");
return 1;
}
run_setup (cmdline);
free (cmdline);
return abs (run_exec (RUN_TTY, RUN_TTY, RUN_TTY, RUN_NORMAL));
}
/*
* Call any postadmin procs.
*/
static int
tag_filesdoneproc (void *callerdat, int err, const char *repository,
const char *update_dir, List *entries)
{
Node *p;
List *mtlist, *tlist;
struct pretag_proc_data ppd;
TRACE (TRACE_FUNCTION, "tag_filesdoneproc (%d, %s, %s)", err, repository,
update_dir);
mtlist = callerdat;
p = findnode (mtlist, update_dir);
if (p != NULL)
tlist = ((struct master_lists *) p->data)->tlist;
else
tlist = NULL;
if (tlist == NULL || tlist->list->next == tlist->list)
return err;
ppd.tlist = tlist;
ppd.delete_flag = delete_flag;
ppd.force_tag_move = force_tag_move;
ppd.symtag = symtag;
Parse_Info (CVSROOTADM_POSTTAG, repository, posttag_proc,
PIOPT_ALL, &ppd);
return err;
}
/*
* callback proc for doing the real work of tagging
*/
/* ARGSUSED */
static int
rtag_proc (int argc, char **argv, char *xwhere, char *mwhere, char *mfile,
int shorten, int local_specified, char *mname, char *msg)
{
/* Begin section which is identical to patch_proc--should this
be abstracted out somehow? */
char *myargv[2];
int err = 0;
int which;
char *repository;
char *where;
#ifdef HAVE_PRINTF_PTR
TRACE (TRACE_FUNCTION,
"rtag_proc (argc=%d, argv=%p, xwhere=%s,\n"
" mwhere=%s, mfile=%s, shorten=%d,\n"
" local_specified=%d, mname=%s, msg=%s)",
argc, (void *)argv, xwhere ? xwhere : "(null)",
mwhere ? mwhere : "(null)", mfile ? mfile : "(null)",
shorten, local_specified,
mname ? mname : "(null)", msg ? msg : "(null)" );
#else
TRACE (TRACE_FUNCTION,
"rtag_proc (argc=%d, argv=%lx, xwhere=%s,\n"
" mwhere=%s, mfile=%s, shorten=%d,\n"
" local_specified=%d, mname=%s, msg=%s )",
argc, (unsigned long)argv, xwhere ? xwhere : "(null)",
mwhere ? mwhere : "(null)", mfile ? mfile : "(null)",
shorten, local_specified,
mname ? mname : "(null)", msg ? msg : "(null)" );
#endif
if (is_rtag)
{
repository = xmalloc (strlen (current_parsed_root->directory)
+ strlen (argv[0])
+ (mfile == NULL ? 0 : strlen (mfile) + 1)
+ 2);
(void) sprintf (repository, "%s/%s", current_parsed_root->directory,
argv[0]);
where = xmalloc (strlen (argv[0])
+ (mfile == NULL ? 0 : strlen (mfile) + 1)
+ 1);
(void) strcpy (where, argv[0]);
/* If MFILE isn't null, we need to set up to do only part of the
* module.
*/
if (mfile != NULL)
{
char *cp;
char *path;
/* If the portion of the module is a path, put the dir part on
* REPOS.
*/
if ((cp = strrchr (mfile, '/')) != NULL)
{
*cp = '\0';
(void) strcat (repository, "/");
(void) strcat (repository, mfile);
(void) strcat (where, "/");
(void) strcat (where, mfile);
mfile = cp + 1;
}
/* take care of the rest */
path = xmalloc (strlen (repository) + strlen (mfile) + 5);
(void) sprintf (path, "%s/%s", repository, mfile);
if (isdir (path))
{
/* directory means repository gets the dir tacked on */
(void) strcpy (repository, path);
(void) strcat (where, "/");
(void) strcat (where, mfile);
}
else
{
myargv[0] = argv[0];
myargv[1] = mfile;
argc = 2;
argv = myargv;
}
free (path);
}
/* cd to the starting repository */
if (CVS_CHDIR (repository) < 0)
{
error (0, errno, "cannot chdir to %s", repository);
free (repository);
free (where);
return 1;
}
/* End section which is identical to patch_proc. */
if (delete_flag || attic_too || (force_tag_match && numtag))
which = W_REPOS | W_ATTIC;
else
which = W_REPOS;
}
else
{
where = NULL;
which = W_LOCAL;
repository = "";
}
if (numtag != NULL && !numtag_validated)
{
tag_check_valid (numtag, argc - 1, argv + 1, local_specified, 0,
repository, false);
numtag_validated = true;
}
/* check to make sure they are authorized to tag all the
specified files in the repository */
mtlist = getlist ();
err = start_recursion (check_fileproc, check_filesdoneproc,
NULL, NULL, NULL,
argc - 1, argv + 1, local_specified, which, 0,
CVS_LOCK_READ, where, 1, repository);
if (err)
{
error (1, 0, "correct the above errors first!");
}
/* It would be nice to provide consistency with respect to
commits; however CVS lacks the infrastructure to do that (see
Concurrency in cvs.texinfo and comment in do_recursion). */
/* start the recursion processor */
err = start_recursion
(is_rtag ? rtag_fileproc : tag_fileproc,
tag_filesdoneproc, tag_dirproc, NULL, mtlist, argc - 1, argv + 1,
local_specified, which, 0, CVS_LOCK_WRITE, where, 1,
repository);
dellist (&mtlist);
if (which & W_REPOS) free (repository);
if (where != NULL)
free (where);
return err;
}
/* check file that is to be tagged */
/* All we do here is add it to our list */
static int
check_fileproc (void *callerdat, struct file_info *finfo)
{
const char *xdir;
Node *p;
Vers_TS *vers;
List *tlist;
struct tag_info *ti;
int addit = 1;
TRACE (TRACE_FUNCTION, "check_fileproc (%s, %s, %s)",
finfo->repository ? finfo->repository : "(null)",
finfo->fullname ? finfo->fullname : "(null)",
finfo->rcs ? (finfo->rcs->path ? finfo->rcs->path : "(null)")
: "NULL");
if (check_uptodate)
{
switch (Classify_File (finfo, NULL, NULL, NULL, 1, 0, &vers, 0))
{
case T_UPTODATE:
case T_CHECKOUT:
case T_PATCH:
case T_REMOVE_ENTRY:
break;
case T_UNKNOWN:
case T_CONFLICT:
case T_NEEDS_MERGE:
case T_MODIFIED:
case T_ADDED:
case T_REMOVED:
default:
error (0, 0, "%s is locally modified", finfo->fullname);
freevers_ts (&vers);
return 1;
}
}
else
vers = Version_TS (finfo, NULL, NULL, NULL, 0, 0);
if (finfo->update_dir[0] == '\0')
xdir = ".";
else
xdir = finfo->update_dir;
if ((p = findnode (mtlist, xdir)) != NULL)
{
tlist = ((struct master_lists *) p->data)->tlist;
}
else
{
struct master_lists *ml;
tlist = getlist ();
p = getnode ();
p->key = xstrdup (xdir);
p->type = UPDATE;
ml = xmalloc (sizeof (struct master_lists));
ml->tlist = tlist;
p->data = ml;
p->delproc = masterlist_delproc;
(void) addnode (mtlist, p);
}
/* do tlist */
p = getnode ();
p->key = xstrdup (finfo->file);
p->type = UPDATE;
p->delproc = tag_delproc;
if (vers->srcfile == NULL)
{
if (!really_quiet)
error (0, 0, "nothing known about %s", finfo->file);
freevers_ts (&vers);
freenode (p);
return 1;
}
/* Here we duplicate the calculation in tag_fileproc about which
version we are going to tag. There probably are some subtle races
(e.g. numtag is "foo" which gets moved between here and
tag_fileproc). */
p->data = ti = xmalloc (sizeof (struct tag_info));
ti->tag = xstrdup (numtag ? numtag : vers->tag);
if (!is_rtag && numtag == NULL && date == NULL)
ti->rev = xstrdup (vers->vn_user);
else
ti->rev = RCS_getversion (vers->srcfile, numtag, date,
force_tag_match, NULL);
if (ti->rev != NULL)
{
ti->oldrev = RCS_getversion (vers->srcfile, symtag, NULL, 1, NULL);
if (ti->oldrev == NULL)
{
if (delete_flag)
{
/* Deleting a tag which did not exist is a noop and
should not be logged. */
addit = 0;
}
}
else if (delete_flag)
{
free (ti->rev);
#ifdef SUPPORT_OLD_INFO_FMT_STRINGS
/* a hack since %v used to mean old or new rev */
ti->rev = xstrdup (ti->oldrev);
#else /* SUPPORT_OLD_INFO_FMT_STRINGS */
ti->rev = NULL;
#endif /* SUPPORT_OLD_INFO_FMT_STRINGS */
}
else if (strcmp(ti->oldrev, p->data) == 0)
addit = 0;
else if (!force_tag_move)
addit = 0;
}
else
addit = 0;
if (!addit)
{
free(p->data);
p->data = NULL;
}
freevers_ts (&vers);
(void)addnode (tlist, p);
return 0;
}
static int
check_filesdoneproc (void *callerdat, int err, const char *repos,
const char *update_dir, List *entries)
{
int n;
Node *p;
List *tlist;
struct pretag_proc_data ppd;
p = findnode (mtlist, update_dir);
if (p != NULL)
tlist = ((struct master_lists *) p->data)->tlist;
else
tlist = NULL;
if (tlist == NULL || tlist->list->next == tlist->list)
return err;
ppd.tlist = tlist;
ppd.delete_flag = delete_flag;
ppd.force_tag_move = force_tag_move;
ppd.symtag = symtag;
if ((n = Parse_Info (CVSROOTADM_TAGINFO, repos, pretag_proc, PIOPT_ALL,
&ppd)) > 0)
{
error (0, 0, "Pre-tag check failed");
err += n;
}
return err;
}
/*
* called from Parse_Info, this routine processes a line that came out
* of a taginfo file and turns it into a command and executes it.
*
* RETURNS
* the absolute value of the return value of run_exec, which may or
* may not be the return value of the child process. this is
* contrained to return positive values because Parse_Info is adding up
* return values and testing for non-zeroness to signify one or more
* of its callbacks having returned an error.
*/
static int
pretag_proc (const char *repository, const char *filter, void *closure)
{
char *newfilter = NULL;
char *cmdline;
const char *srepos = Short_Repository (repository);
struct pretag_proc_data *ppd = closure;
#ifdef SUPPORT_OLD_INFO_FMT_STRINGS
if (!strchr (filter, '%'))
{
error (0,0,
"warning: taginfo line contains no format strings:\n"
" \"%s\"\n"
"Filling in old defaults ('%%t %%o %%p %%{sv}'), but please be aware that this\n"
"usage is deprecated.", filter);
newfilter = xmalloc (strlen (filter) + 16);
strcpy (newfilter, filter);
strcat (newfilter, " %t %o %p %{sv}");
filter = newfilter;
}
#endif /* SUPPORT_OLD_INFO_FMT_STRINGS */
/* %t = tag being added/moved/removed
* %o = operation = "add" | "mov" | "del"
* %b = branch mode = "?" (delete ops - unknown) | "T" (branch)
* | "N" (not branch)
* %c = cvs_cmd_name
* %p = path from $CVSROOT
* %r = path from root
* %{sVv} = attribute list = file name, old version tag will be deleted
* from, new version tag will be added to (or
* deleted from until
* SUPPORT_OLD_INFO_FMT_STRINGS is undefined)
*/
/*
* Cast any NULL arguments as appropriate pointers as this is an
* stdarg function and we need to be certain the caller gets what
* is expected.
*/
cmdline = format_cmdline (
#ifdef SUPPORT_OLD_INFO_FMT_STRINGS
false, srepos,
#endif /* SUPPORT_OLD_INFO_FMT_STRINGS */
filter,
"t", "s", ppd->symtag,
"o", "s", ppd->delete_flag ? "del" :
ppd->force_tag_move ? "mov" : "add",
"b", "c", delete_flag
? '?' : branch_mode ? 'T' : 'N',
"c", "s", cvs_cmd_name,
#ifdef SERVER_SUPPORT
"R", "s", referrer ? referrer->original : "NONE",
#endif /* SERVER_SUPPORT */
"p", "s", srepos,
"r", "s", current_parsed_root->directory,
"sVv", ",", ppd->tlist,
pretag_list_to_args_proc, (void *) NULL,
(char *) NULL);
if (newfilter) free (newfilter);
if (!cmdline || !strlen (cmdline))
{
if (cmdline) free (cmdline);
error (0, 0, "pretag proc resolved to the empty string!");
return 1;
}
run_setup (cmdline);
/* FIXME - the old code used to run the following here:
*
* if (!isfile(s))
* {
* error (0, errno, "cannot find pre-tag filter '%s'", s);
* free(s);
* return (1);
* }
*
* not sure this is really necessary. it might give a little finer grained
* error than letting the execution attempt fail but i'm not sure. in any
* case it should be easy enough to add a function in run.c to test its
* first arg for fileness & executability.
*/
free (cmdline);
return abs (run_exec (RUN_TTY, RUN_TTY, RUN_TTY, RUN_NORMAL));
}
static void
masterlist_delproc (Node *p)
{
struct master_lists *ml = p->data;
dellist (&ml->tlist);
free (ml);
return;
}
static void
tag_delproc (Node *p)
{
struct tag_info *ti;
if (p->data)
{
ti = (struct tag_info *) p->data;
if (ti->oldrev) free (ti->oldrev);
if (ti->rev) free (ti->rev);
free (ti->tag);
free (p->data);
p->data = NULL;
}
return;
}
/* to be passed into walklist with a list of tags
* p->key = tagname
* p->data = struct tag_info *
* p->data->oldrev = rev tag will be deleted from
* p->data->rev = rev tag will be added to
* p->data->tag = tag oldrev is attached to, if any
*
* closure will be a struct format_cmdline_walklist_closure
* where closure is undefined
*/
static int
pretag_list_to_args_proc (Node *p, void *closure)
{
struct tag_info *taginfo = (struct tag_info *)p->data;
struct format_cmdline_walklist_closure *c =
(struct format_cmdline_walklist_closure *)closure;
char *arg = NULL;
const char *f;
char *d;
size_t doff;
if (!p->data) return 1;
f = c->format;
d = *c->d;
/* foreach requested attribute */
while (*f)
{
switch (*f++)
{
case 's':
arg = p->key;
break;
case 'T':
arg = taginfo->tag ? taginfo->tag : "";
break;
case 'v':
arg = taginfo->rev ? taginfo->rev : "NONE";
break;
case 'V':
arg = taginfo->oldrev ? taginfo->oldrev : "NONE";
break;
default:
error(1,0,
"Unknown format character or not a list attribute: %c",
f[-1]);
break;
}
/* copy the attribute into an argument */
if (c->quotes)
{
arg = cmdlineescape (c->quotes, arg);
}
else
{
arg = cmdlinequote ('"', arg);
}
doff = d - *c->buf;
expand_string (c->buf, c->length, doff + strlen (arg));
d = *c->buf + doff;
strncpy (d, arg, strlen (arg));
d += strlen (arg);
free (arg);
/* and always put the extra space on. we'll have to back up a char when we're
* done, but that seems most efficient
*/
doff = d - *c->buf;
expand_string (c->buf, c->length, doff + 1);
d = *c->buf + doff;
*d++ = ' ';
}
/* correct our original pointer into the buff */
*c->d = d;
return 0;
}
/*
* Called to rtag a particular file, as appropriate with the options that were
* set above.
*/
/* ARGSUSED */
static int
rtag_fileproc (void *callerdat, struct file_info *finfo)
{
RCSNode *rcsfile;
char *version = NULL, *rev = NULL;
int retcode = 0;
int retval = 0;
static bool valtagged = false;
/* find the parsed RCS data */
if ((rcsfile = finfo->rcs) == NULL)
{
retval = 1;
goto free_vars_and_return;
}
/*
* For tagging an RCS file which is a symbolic link, you'd best be
* running with RCS 5.6, since it knows how to handle symbolic links
* correctly without breaking your link!
*/
/* cvsacl patch */
#ifdef SERVER_SUPPORT
if (use_cvs_acl /* && server_active */)
{
if (!access_allowed (finfo->file, finfo->repository, numtag, 4,
NULL, NULL, 1))
{
if (stop_at_first_permission_denied)
error (1, 0, "permission denied for %s",
Short_Repository (finfo->repository));
else
error (0, 0, "permission denied for %s/%s",
Short_Repository (finfo->repository), finfo->file);
return (0);
}
}
#endif
if (delete_flag)
{
retval = rtag_delete (rcsfile);
goto free_vars_and_return;
}
/*
* If we get here, we are adding a tag. But, if -a was specified, we
* need to check to see if a -r or -D option was specified. If neither
* was specified and the file is in the Attic, remove the tag.
*/
if (attic_too && (!numtag && !date))
{
if ((rcsfile->flags & VALID) && (rcsfile->flags & INATTIC))
{
retval = rtag_delete (rcsfile);
goto free_vars_and_return;
}
}
version = RCS_getversion (rcsfile, numtag, date, force_tag_match, NULL);
if (version == NULL)
{
/* If -a specified, clean up any old tags */
if (attic_too)
(void)rtag_delete (rcsfile);
if (!quiet && !force_tag_match)
{
error (0, 0, "cannot find tag `%s' in `%s'",
numtag ? numtag : "head", rcsfile->path);
retval = 1;
}
goto free_vars_and_return;
}
if (numtag
&& isdigit ((unsigned char)*numtag)
&& strcmp (numtag, version) != 0)
{
/*
* We didn't find a match for the numeric tag that was specified, but
* that's OK. just pass the numeric tag on to rcs, to be tagged as
* specified. Could get here if one tried to tag "1.1.1" and there
* was a 1.1.1 branch with some head revision. In this case, we want
* the tag to reference "1.1.1" and not the revision at the head of
* the branch. Use a symbolic tag for that.
*/
rev = branch_mode ? RCS_magicrev (rcsfile, version) : numtag;
retcode = RCS_settag(rcsfile, symtag, numtag);
if (retcode == 0)
RCS_rewrite (rcsfile, NULL, NULL);
}
else
{
char *oversion;
/*
* As an enhancement for the case where a tag is being re-applied to
* a large body of a module, make one extra call to RCS_getversion to
* see if the tag is already set in the RCS file. If so, check to
* see if it needs to be moved. If not, do nothing. This will
* likely save a lot of time when simply moving the tag to the
* "current" head revisions of a module -- which I have found to be a
* typical tagging operation.
*/
rev = branch_mode ? RCS_magicrev (rcsfile, version) : version;
oversion = RCS_getversion (rcsfile, symtag, NULL, 1, NULL);
if (oversion != NULL)
{
int isbranch = RCS_nodeisbranch (finfo->rcs, symtag);
/*
* if versions the same and neither old or new are branches don't
* have to do anything
*/
if (strcmp (version, oversion) == 0 && !branch_mode && !isbranch)
{
free (oversion);
goto free_vars_and_return;
}
if (!force_tag_move)
{
/* we're NOT going to move the tag */
(void)printf ("W %s", finfo->fullname);
(void)printf (" : %s already exists on %s %s",
symtag, isbranch ? "branch" : "version",
oversion);
(void)printf (" : NOT MOVING tag to %s %s\n",
branch_mode ? "branch" : "version", rev);
free (oversion);
goto free_vars_and_return;
}
else /* force_tag_move is set and... */
if ((isbranch && !disturb_branch_tags) ||
(!isbranch && disturb_branch_tags))
{
error(0,0, "%s: Not moving %s tag `%s' from %s to %s%s.",
finfo->fullname,
isbranch ? "branch" : "non-branch",
symtag, oversion, rev,
isbranch ? "" : " due to `-B' option");
free (oversion);
goto free_vars_and_return;
}
free (oversion);
}
retcode = RCS_settag (rcsfile, symtag, rev);
if (retcode == 0)
RCS_rewrite (rcsfile, NULL, NULL);
}
if (retcode != 0)
{
error (1, retcode == -1 ? errno : 0,
"failed to set tag `%s' to revision `%s' in `%s'",
symtag, rev, rcsfile->path);
retval = 1;
goto free_vars_and_return;
}
free_vars_and_return:
if (branch_mode && rev) free (rev);
if (version) free (version);
if (!delete_flag && !retval && !valtagged)
{
tag_check_valid (symtag, 0, NULL, 0, 0, NULL, true);
valtagged = true;
}
return retval;
}
/*
* If -d is specified, "force_tag_match" is set, so that this call to
* RCS_getversion() will return a NULL version string if the symbolic
* tag does not exist in the RCS file.
*
* If the -r flag was used, numtag is set, and we only delete the
* symtag from files that have numtag.
*
* This is done here because it's MUCH faster than just blindly calling
* "rcs" to remove the tag... trust me.
*/
static int
rtag_delete (RCSNode *rcsfile)
{
char *version;
int retcode, isbranch;
if (numtag)
{
version = RCS_getversion (rcsfile, numtag, NULL, 1, NULL);
if (version == NULL)
return (0);
free (version);
}
version = RCS_getversion (rcsfile, symtag, NULL, 1, NULL);
if (version == NULL)
return 0;
free (version);
isbranch = RCS_nodeisbranch (rcsfile, symtag);
if ((isbranch && !disturb_branch_tags) ||
(!isbranch && disturb_branch_tags))
{
if (!really_quiet)
error (0, 0,
"Not removing %s tag `%s' from `%s'%s.",
isbranch ? "branch" : "non-branch",
symtag, rcsfile->path,
isbranch ? "" : " due to `-B' option");
return 1;
}
if ((retcode = RCS_deltag(rcsfile, symtag)) != 0)
{
if (!really_quiet)
error (0, retcode == -1 ? errno : 0,
"failed to remove tag `%s' from `%s'", symtag,
rcsfile->path);
return 1;
}
RCS_rewrite (rcsfile, NULL, NULL);
return 0;
}
/*
* Called to tag a particular file (the currently checked out version is
* tagged with the specified tag - or the specified tag is deleted).
*/
/* ARGSUSED */
static int
tag_fileproc (void *callerdat, struct file_info *finfo)
{
char *version, *oversion;
char *nversion = NULL;
char *rev;
Vers_TS *vers;
int retcode = 0;
int retval = 0;
static bool valtagged = false;
vers = Version_TS (finfo, NULL, NULL, NULL, 0, 0);
if (numtag || date)
{
nversion = RCS_getversion (vers->srcfile, numtag, date,
force_tag_match, NULL);
if (!nversion)
goto free_vars_and_return;
}
/* cvsacl patch */
#ifdef SERVER_SUPPORT
if (use_cvs_acl /* && server_active */)
{
if (!access_allowed (finfo->file, finfo->repository, vers->tag, 4,
NULL, NULL, 1))
{
error (0, 0, "permission denied for %s/%s",
Short_Repository (finfo->repository), finfo->file);
return (0);
}
}
#endif
if (delete_flag)
{
int isbranch;
/*
* If -d is specified, "force_tag_match" is set, so that this call to
* RCS_getversion() will return a NULL version string if the symbolic
* tag does not exist in the RCS file.
*
* This is done here because it's MUCH faster than just blindly calling
* "rcs" to remove the tag... trust me.
*/
version = RCS_getversion (vers->srcfile, symtag, NULL, 1, NULL);
if (version == NULL || vers->srcfile == NULL)
goto free_vars_and_return;
free (version);
isbranch = RCS_nodeisbranch (finfo->rcs, symtag);
if ((isbranch && !disturb_branch_tags) ||
(!isbranch && disturb_branch_tags))
{
if (!really_quiet)
error(0, 0,
"Not removing %s tag `%s' from `%s'%s.",
isbranch ? "branch" : "non-branch",
symtag, vers->srcfile->path,
isbranch ? "" : " due to `-B' option");
retval = 1;
goto free_vars_and_return;
}
if ((retcode = RCS_deltag (vers->srcfile, symtag)) != 0)
{
if (!really_quiet)
error (0, retcode == -1 ? errno : 0,
"failed to remove tag %s from %s", symtag,
vers->srcfile->path);
retval = 1;
goto free_vars_and_return;
}
RCS_rewrite (vers->srcfile, NULL, NULL);
/* warm fuzzies */
if (!really_quiet)
{
cvs_output ("D ", 2);
cvs_output (finfo->fullname, 0);
cvs_output ("\n", 1);
}
goto free_vars_and_return;
}
/*
* If we are adding a tag, we need to know which version we have checked
* out and we'll tag that version.
*/
if (!nversion)
version = vers->vn_user;
else
version = nversion;
if (!version)
goto free_vars_and_return;
else if (strcmp (version, "0") == 0)
{
if (!quiet)
error (0, 0, "couldn't tag added but un-commited file `%s'",
finfo->file);
goto free_vars_and_return;
}
else if (version[0] == '-')
{
if (!quiet)
error (0, 0, "skipping removed but un-commited file `%s'",
finfo->file);
goto free_vars_and_return;
}
else if (vers->srcfile == NULL)
{
if (!quiet)
error (0, 0, "cannot find revision control file for `%s'",
finfo->file);
goto free_vars_and_return;
}
/*
* As an enhancement for the case where a tag is being re-applied to a
* large number of files, make one extra call to RCS_getversion to see
* if the tag is already set in the RCS file. If so, check to see if it
* needs to be moved. If not, do nothing. This will likely save a lot of
* time when simply moving the tag to the "current" head revisions of a
* module -- which I have found to be a typical tagging operation.
*/
rev = branch_mode ? RCS_magicrev (vers->srcfile, version) : version;
oversion = RCS_getversion (vers->srcfile, symtag, NULL, 1, NULL);
if (oversion != NULL)
{
int isbranch = RCS_nodeisbranch (finfo->rcs, symtag);
/*
* if versions the same and neither old or new are branches don't have
* to do anything
*/
if (strcmp (version, oversion) == 0 && !branch_mode && !isbranch)
{
free (oversion);
if (branch_mode)
free (rev);
goto free_vars_and_return;
}
if (!force_tag_move)
{
/* we're NOT going to move the tag */
cvs_output ("W ", 2);
cvs_output (finfo->fullname, 0);
cvs_output (" : ", 0);
cvs_output (symtag, 0);
cvs_output (" already exists on ", 0);
cvs_output (isbranch ? "branch" : "version", 0);
cvs_output (" ", 0);
cvs_output (oversion, 0);
cvs_output (" : NOT MOVING tag to ", 0);
cvs_output (branch_mode ? "branch" : "version", 0);
cvs_output (" ", 0);
cvs_output (rev, 0);
cvs_output ("\n", 1);
free (oversion);
if (branch_mode)
free (rev);
goto free_vars_and_return;
}
else /* force_tag_move == 1 and... */
if ((isbranch && !disturb_branch_tags) ||
(!isbranch && disturb_branch_tags))
{
error (0,0, "%s: Not moving %s tag `%s' from %s to %s%s.",
finfo->fullname,
isbranch ? "branch" : "non-branch",
symtag, oversion, rev,
isbranch ? "" : " due to `-B' option");
free (oversion);
if (branch_mode)
free (rev);
goto free_vars_and_return;
}
free (oversion);
}
if ((retcode = RCS_settag(vers->srcfile, symtag, rev)) != 0)
{
error (1, retcode == -1 ? errno : 0,
"failed to set tag %s to revision %s in %s",
symtag, rev, vers->srcfile->path);
if (branch_mode)
free (rev);
retval = 1;
goto free_vars_and_return;
}
if (branch_mode)
free (rev);
RCS_rewrite (vers->srcfile, NULL, NULL);
/* more warm fuzzies */
if (!really_quiet)
{
cvs_output ("T ", 2);
cvs_output (finfo->fullname, 0);
cvs_output ("\n", 1);
}
free_vars_and_return:
if (nversion != NULL)
free (nversion);
freevers_ts (&vers);
if (!delete_flag && !retval && !valtagged)
{
tag_check_valid (symtag, 0, NULL, 0, 0, NULL, true);
valtagged = true;
}
return retval;
}
/*
* Print a warm fuzzy message
*/
/* ARGSUSED */
static Dtype
tag_dirproc (void *callerdat, const char *dir, const char *repos,
const char *update_dir, List *entries)
{
if (ignore_directory (update_dir))
{
/* print the warm fuzzy message */
if (!quiet)
error (0, 0, "Ignoring %s", update_dir);
return R_SKIP_ALL;
}
if (!quiet)
error (0, 0, "%s %s", delete_flag ? "Untagging" : "Tagging",
update_dir);
return R_PROCESS;
}
/* Code relating to the val-tags file. Note that this file has no way
of knowing when a tag has been deleted. The problem is that there
is no way of knowing whether a tag still exists somewhere, when we
delete it some places. Using per-directory val-tags files (in
CVSREP) might be better, but that might slow down the process of
verifying that a tag is correct (maybe not, for the likely cases,
if carefully done), and/or be harder to implement correctly. */
struct val_args {
const char *name;
int found;
};
static int
val_fileproc (void *callerdat, struct file_info *finfo)
{
RCSNode *rcsdata;
struct val_args *args = callerdat;
char *tag;
if ((rcsdata = finfo->rcs) == NULL)
/* Not sure this can happen, after all we passed only
W_REPOS | W_ATTIC. */
return 0;
tag = RCS_gettag (rcsdata, args->name, 1, NULL);
if (tag != NULL)
{
/* FIXME: should find out a way to stop the search at this point. */
args->found = 1;
free (tag);
}
return 0;
}
/* This routine determines whether a tag appears in CVSROOT/val-tags.
*
* The val-tags file will be open read-only when IDB is NULL. Since writes to
* val-tags always append to it, the lack of locking is okay. The worst case
* race condition might misinterpret a partially written "foobar" matched, for
* instance, a request for "f", "foo", of "foob". Such a mismatch would be
* caught harmlessly later.
*
* Before CVS adds a tag to val-tags, it will lock val-tags for write and
* verify that the tag is still not present to avoid adding it twice.
*
* NOTES
* This function expects its parent to handle any necessary locking of the
* val-tags file.
*
* INPUTS
* idb When this value is NULL, the val-tags file is opened in
* in read-only mode. When present, the val-tags file is opened
* in read-write mode and the DBM handle is stored in *IDB.
* name The tag to search for.
*
* OUTPUTS
* *idb The val-tags file opened for read/write, or NULL if it couldn't
* be opened.
*
* ERRORS
* Exits with an error message if the val-tags file cannot be opened for
* read (failure to open val-tags read/write is harmless - see below).
*
* RETURNS
* true 1. If NAME exists in val-tags.
* 2. If IDB is non-NULL and val-tags cannot be opened for write.
* This allows callers to ignore the harmless inability to
* update the val-tags cache.
* false If the file could be opened and the tag is not present.
*/
static int is_in_val_tags (DBM **idb, const char *name)
{
DBM *db = NULL;
char *valtags_filename;
datum mytag;
int status;
/* Casting out const should be safe here - input datums are not
* written to by the myndbm functions.
*/
mytag.dptr = (char *)name;
mytag.dsize = strlen (name);
valtags_filename = Xasprintf ("%s/%s/%s", current_parsed_root->directory,
CVSROOTADM, CVSROOTADM_VALTAGS);
if (idb)
{
mode_t omask;
omask = umask (cvsumask);
db = dbm_open (valtags_filename, O_RDWR | O_CREAT, 0666);
umask (omask);
if (!db)
{
error (0, errno, "warning: cannot open `%s' read/write",
valtags_filename);
*idb = NULL;
return 1;
}
*idb = db;
}
else
{
db = dbm_open (valtags_filename, O_RDONLY, 0444);
if (!db && !existence_error (errno))
error (1, errno, "cannot read %s", valtags_filename);
}
/* If the file merely fails to exist, we just keep going and create
it later if need be. */
status = 0;
if (db)
{
datum val;
val = dbm_fetch (db, mytag);
if (val.dptr != NULL)
/* Found. The tag is valid. */
status = 1;
/* FIXME: should check errors somehow (add dbm_error to myndbm.c?). */
if (!idb) dbm_close (db);
}
free (valtags_filename);
return status;
}
/* Add a tag to the CVSROOT/val-tags cache. Establishes a write lock and
* reverifies that the tag does not exist before adding it.
*/
static void add_to_val_tags (const char *name)
{
DBM *db;
datum mytag;
datum value;
if (noexec) return;
val_tags_lock (current_parsed_root->directory);
/* Check for presence again since we have a lock now. */
if (is_in_val_tags (&db, name)) return;
/* Casting out const should be safe here - input datums are not
* written to by the myndbm functions.
*/
mytag.dptr = (char *)name;
mytag.dsize = strlen (name);
value.dptr = "y";
value.dsize = 1;
if (dbm_store (db, mytag, value, DBM_REPLACE) < 0)
error (0, errno, "failed to store %s into val-tags", name);
dbm_close (db);
clear_val_tags_lock ();
}
static Dtype
val_direntproc (void *callerdat, const char *dir, const char *repository,
const char *update_dir, List *entries)
{
/* This is not quite right--it doesn't get right the case of "cvs
update -d -r foobar" where foobar is a tag which exists only in
files in a directory which does not exist yet, but which is
about to be created. */
if (isdir (dir))
return R_PROCESS;
return R_SKIP_ALL;
}
/* With VALID set, insert NAME into val-tags if it is not already present
* there.
*
* Without VALID set, check to see whether NAME is a valid tag. If so, return.
* If not print an error message and exit.
*
* INPUTS
*
* ARGC, ARGV, LOCAL, and AFLAG specify which files we will be operating on.
*
* REPOSITORY is the repository if we need to cd into it, or NULL if
* we are already there, or "" if we should do a W_LOCAL recursion.
* Sorry for three cases, but the "" case is needed in case the
* working directories come from diverse parts of the repository, the
* NULL case avoids an unneccesary chdir, and the non-NULL, non-""
* case is needed for checkout, where we don't want to chdir if the
* tag is found in CVSROOTADM_VALTAGS, but there is not (yet) any
* local directory.
*
* ERRORS
* Errors may be encountered opening and accessing the DBM file. Write
* errors generate warnings and read errors are fatal. When !VALID and NAME
* is not in val-tags, errors may also be generated as per start_recursion.
* When !VALID, non-existance of tags both in val-tags and in the archive
* files also causes a fatal error.
*
* RETURNS
* Nothing.
*/
void
tag_check_valid (const char *name, int argc, char **argv, int local, int aflag,
char *repository, bool valid)
{
struct val_args the_val_args;
struct saved_cwd cwd;
int which;
#ifdef HAVE_PRINTF_PTR
TRACE (TRACE_FUNCTION,
"tag_check_valid (name=%s, argc=%d, argv=%p, local=%d,\n"
" aflag=%d, repository=%s, valid=%s)",
name ? name : "(name)", argc, (void *)argv, local, aflag,
repository ? repository : "(null)",
valid ? "true" : "false");
#else
TRACE (TRACE_FUNCTION,
"tag_check_valid (name=%s, argc=%d, argv=%lx, local=%d,\n"
" aflag=%d, repository=%s, valid=%s)",
name ? name : "(name)", argc, (unsigned long)argv, local, aflag,
repository ? repository : "(null)",
valid ? "true" : "false");
#endif
/* Numeric tags require only a syntactic check. */
if (isdigit ((unsigned char) name[0]))
{
/* insert is not possible for numeric revisions */
assert (!valid);
if (RCS_valid_rev (name)) return;
else
error (1, 0, "\
Numeric tag %s invalid. Numeric tags should be of the form X[.X]...", name);
}
/* Special tags are always valid. */
if (strcmp (name, TAG_BASE) == 0
|| strcmp (name, TAG_HEAD) == 0)
{
/* insert is not possible for numeric revisions */
assert (!valid);
return;
}
/* Verify that the tag is valid syntactically. Some later code once made
* assumptions about this.
*/
RCS_check_tag (name);
if (is_in_val_tags (NULL, name)) return;
if (!valid)
{
/* We didn't find the tag in val-tags, so look through all the RCS files
* to see whether it exists there. Yes, this is expensive, but there
* is no other way to cope with a tag which might have been created
* by an old version of CVS, from before val-tags was invented
*/
the_val_args.name = name;
the_val_args.found = 0;
which = W_REPOS | W_ATTIC;
if (repository == NULL || repository[0] == '\0')
which |= W_LOCAL;
else
{
if (save_cwd (&cwd))
error (1, errno, "Failed to save current directory.");
if (CVS_CHDIR (repository) < 0)
error (1, errno, "cannot change to %s directory", repository);
}
start_recursion
(val_fileproc, NULL, val_direntproc, NULL,
&the_val_args, argc, argv, local, which, aflag,
CVS_LOCK_READ, NULL, 1, repository);
if (repository != NULL && repository[0] != '\0')
{
if (restore_cwd (&cwd))
error (1, errno, "Failed to restore current directory, `%s'.",
cwd.name);
free_cwd (&cwd);
}
if (!the_val_args.found)
error (1, 0, "no such tag `%s'", name);
}
/* The tags is valid but not mentioned in val-tags. Add it. */
add_to_val_tags (name);
}
|