1 /* Change RCS file attributes. */
3 /* Copyright 1982, 1988, 1989 Walter Tichy
4 Copyright 1990, 1991, 1992, 1993, 1994, 1995 Paul Eggert
5 Distributed under license by the Free Software Foundation, Inc.
7 This file is part of RCS.
9 RCS is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
14 RCS is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with RCS; see the file COPYING.
21 If not, write to the Free Software Foundation,
22 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 Report problems and direct all questions to:
26 rcs-bugs@cs.purdue.edu
31 * Revision 5.21 1995/06/16 06:19:24 eggert
34 * Revision 5.20 1995/06/01 16:23:43 eggert
35 * (main): Warn if no options were given. Punctuate messages properly.
37 * (sendmail): Rewind mailmess before flushing it.
38 * Output another warning if mail should work but fails.
40 * (buildeltatext): Pass "--binary" if -kb and if --binary makes a difference.
42 * Revision 5.19 1994/03/17 14:05:48 eggert
43 * Use ORCSerror to clean up after a fatal error. Remove lint.
44 * Specify subprocess input via file descriptor, not file name. Remove lint.
45 * Flush stderr after prompt.
47 * Revision 5.18 1993/11/09 17:40:15 eggert
48 * -V now prints version on stdout and exits. Don't print usage twice.
50 * Revision 5.17 1993/11/03 17:42:27 eggert
51 * Add -z. Don't lose track of -m or -t when there are no other changes.
52 * Don't discard ignored phrases. Improve quality of diagnostics.
54 * Revision 5.16 1992/07/28 16:12:44 eggert
55 * rcs -l now asks whether you want to break the lock.
56 * Add -V. Set RCS file's mode and time at right moment.
58 * Revision 5.15 1992/02/17 23:02:20 eggert
61 * Revision 5.14 1992/01/27 16:42:53 eggert
62 * Add -M. Avoid invoking umask(); it's one less thing to configure.
63 * Add support for bad_creat0. lint -> RCS_lint
65 * Revision 5.13 1992/01/06 02:42:34 eggert
66 * Avoid changing RCS file in common cases where no change can occur.
68 * Revision 5.12 1991/11/20 17:58:08 eggert
69 * Don't read the delta tree from a nonexistent RCS file.
71 * Revision 5.11 1991/10/07 17:32:46 eggert
74 * Revision 5.10 1991/08/19 23:17:54 eggert
75 * Add -m, -r$, piece tables. Revision separator is `:', not `-'. Tune.
77 * Revision 5.9 1991/04/21 11:58:18 eggert
78 * Add -x, RCSINIT, MS-DOS support.
80 * Revision 5.8 1991/02/25 07:12:38 eggert
81 * strsave -> str_save (DG/UX name clash)
82 * 0444 -> S_IRUSR|S_IRGRP|S_IROTH for portability
84 * Revision 5.7 1990/12/18 17:19:21 eggert
85 * Fix bug with multiple -n and -N options.
87 * Revision 5.6 1990/12/04 05:18:40 eggert
88 * Use -I for prompts and -q for diagnostics.
90 * Revision 5.5 1990/11/11 00:06:35 eggert
91 * Fix `rcs -e' core dump.
93 * Revision 5.4 1990/11/01 05:03:33 eggert
94 * Add -I and new -t behavior. Permit arbitrary data in logs.
96 * Revision 5.3 1990/10/04 06:30:16 eggert
97 * Accumulate exit status across files.
99 * Revision 5.2 1990/09/04 08:02:17 eggert
100 * Standardize yes-or-no procedure.
102 * Revision 5.1 1990/08/29 07:13:51 eggert
103 * Remove unused setuid support. Clean old log messages too.
105 * Revision 5.0 1990/08/22 08:12:42 eggert
106 * Don't lose names when applying -a option to multiple files.
107 * Remove compile-time limits; use malloc instead. Add setuid support.
108 * Permit dates past 1999/12/31. Make lock and temp files faster and safer.
109 * Ansify and Posixate. Add -V. Fix umask bug. Make linting easier. Tune.
110 * Yield proper exit status. Check diff's output.
112 * Revision 4.11 89/05/01 15:12:06 narten
113 * changed copyright header to reflect current distribution rules
115 * Revision 4.10 88/11/08 16:01:54 narten
116 * didn't install previous patch correctly
118 * Revision 4.9 88/11/08 13:56:01 narten
119 * removed include <sysexits.h> (not needed)
120 * minor fix for -A option
122 * Revision 4.8 88/08/09 19:12:27 eggert
123 * Don't access freed storage.
124 * Use execv(), not system(); yield proper exit status; remove lint.
126 * Revision 4.7 87/12/18 11:37:17 narten
127 * lint cleanups (Guy Harris)
129 * Revision 4.6 87/10/18 10:28:48 narten
130 * Updating verison numbers. Changes relative to 1.1 are actually
133 * Revision 1.4 87/09/24 13:58:52 narten
134 * Sources now pass through lint (if you ignore printf/sprintf/fprintf
137 * Revision 1.3 87/03/27 14:21:55 jenkins
140 * Revision 1.2 85/12/17 13:59:09 albitz
141 * Changed setstate to rcs_setstate because of conflict with random.o.
143 * Revision 4.3 83/12/15 12:27:33 wft
144 * rcs -u now breaks most recent lock if it can't find a lock by the caller.
146 * Revision 4.2 83/12/05 10:18:20 wft
147 * Added conditional compilation for sending mail.
148 * Alternatives: V4_2BSD, V6, USG, and other.
150 * Revision 4.1 83/05/10 16:43:02 wft
151 * Simplified breaklock(); added calls to findlock() and getcaller().
152 * Added option -b (default branch). Updated -s and -w for -b.
153 * Removed calls to stat(); now done by pairfilenames().
154 * Replaced most catchints() calls with restoreints().
155 * Removed check for exit status of delivermail().
156 * Directed all interactive output to stderr.
158 * Revision 3.9.1.1 83/12/02 22:08:51 wft
159 * Added conditional compilation for 4.2 sendmail and 4.1 delivermail.
161 * Revision 3.9 83/02/15 15:38:39 wft
162 * Added call to fastcopy() to copy remainder of RCS file.
164 * Revision 3.8 83/01/18 17:37:51 wft
165 * Changed sendmail(): now uses delivermail, and asks whether to break the lock.
167 * Revision 3.7 83/01/15 18:04:25 wft
168 * Removed putree(); replaced with puttree() in rcssyn.c.
169 * Combined putdellog() and scanlogtext(); deleted putdellog().
170 * Cleaned up diagnostics and error messages. Fixed problem with
171 * mutilated files in case of deletions in 2 files in a single command.
172 * Changed marking of selector from 'D' to DELETE.
174 * Revision 3.6 83/01/14 15:37:31 wft
175 * Added ignoring of interrupts while new RCS file is renamed;
176 * Avoids deletion of RCS files by interrupts.
178 * Revision 3.5 82/12/10 21:11:39 wft
179 * Removed unused variables, fixed checking of return code from diff,
180 * introduced variant COMPAT2 for skipping Suffix on -A files.
182 * Revision 3.4 82/12/04 13:18:20 wft
183 * Replaced getdelta() with gettree(), changed breaklock to update
184 * field lockedby, added some diagnostics.
186 * Revision 3.3 82/12/03 17:08:04 wft
187 * Replaced getlogin() with getpwuid(), flcose() with ffclose(),
188 * /usr/ucb/Mail with macro MAIL. Removed handling of Suffix (-x).
189 * fixed -u for missing revno. Disambiguated structure members.
191 * Revision 3.2 82/10/18 21:05:07 wft
192 * rcs -i now generates a file mode given by the umask minus write permission;
193 * otherwise, rcs keeps the mode, but removes write permission.
194 * I added a check for write error, fixed call to getlogin(), replaced
195 * curdir() with getfullRCSname(), cleaned up handling -U/L, and changed
196 * conflicting, long identifiers.
198 * Revision 3.1 82/10/13 16:11:07 wft
199 * fixed type of variables receiving from getc() (char -> int).
207 struct Lockrev * nextrev;
214 struct Symrev * nextsym;
220 struct Message *nextmessage;
226 struct Status * nextstatus;
229 enum changeaccess {append, erase};
232 enum changeaccess command;
233 struct chaccess *nextchaccess;
242 static int branchpoint P((struct hshentry*,struct hshentry*));
243 static int breaklock P((struct hshentry const*));
244 static int buildeltatext P((struct hshentries const*));
245 static int doaccess P((void));
246 static int doassoc P((void));
247 static int dolocks P((void));
248 static int domessages P((void));
249 static int rcs_setstate P((char const*,char const*));
250 static int removerevs P((void));
251 static int sendmail P((char const*,char const*));
252 static int setlock P((char const*));
253 static struct Lockrev **rmnewlocklst P((char const*));
254 static struct hshentry *searchcutpt P((char const*,int,struct hshentries*));
255 static void buildtree P((void));
256 static void cleanup P((void));
257 static void getaccessor P((char*,enum changeaccess));
258 static void getassoclst P((int,char*));
259 static void getchaccess P((char const*,enum changeaccess));
260 static void getdelrev P((char*));
261 static void getmessage P((char*));
262 static void getstates P((char*));
263 static void scanlogtext P((struct hshentry*,int));
265 static struct buf numrev;
266 static char const *headstate;
267 static int chgheadstate, exitstatus, lockhead, unlockcaller;
268 static int suppress_mail;
269 static struct Lockrev *newlocklst, *rmvlocklst;
270 static struct Message *messagelst, **nextmessage;
271 static struct Status *statelst, **nextstate;
272 static struct Symrev *assoclst, **nextassoc;
273 static struct chaccess *chaccess, **nextchaccess;
274 static struct delrevpair delrev;
275 static struct hshentry *cuthead, *cuttail, *delstrt;
276 static struct hshentries *gendeltas;
278 mainProg(rcsId, "rcs", "$FreeBSD$")
280 static char const cmdusage[] =
281 "\nrcs usage: rcs -{ae}logins -Afile -{blu}[rev] -cstring -{iILqTU} -ksubst -mrev:msg -{nN}name[:[rev]] -orange -sstate[:rev] -t[text] -Vn -xsuff -zzone file ...";
283 char *a, **newargv, *textfile;
284 char const *branchsym, *commsyml;
285 int branchflag, changed, expmode, initflag;
286 int strictlock, strict_selected, textflag;
287 int keepRCStime, Ttimeflag;
289 struct buf branchnum;
290 struct Lockrev *lockpt;
291 struct Lockrev **curlock, **rmvlock;
292 struct Status * curstate;
296 nextassoc = &assoclst;
297 nextchaccess = &chaccess;
298 nextmessage = &messagelst;
299 nextstate = &statelst;
300 branchsym = commsyml = textfile = 0;
301 branchflag = strictlock = false;
302 bufautobegin(&branchnum);
304 curlock = &newlocklst;
305 rmvlock = &rmvlocklst;
307 suffixes = X_DEFAULT;
308 initflag= textflag = false;
312 /* preprocessing command options */
313 if (1 < argc && argv[1][0] != '-')
314 warn("No options were given; this usage is obsolescent.");
316 argc = getRCSINIT(argc, argv, &newargv);
318 while (a = *++argv, 0<--argc && *a++=='-') {
321 case 'i': /* initial version */
325 case 'b': /* change default branch */
326 if (branchflag) redefined('b');
331 case 'c': /* change comment symbol */
332 if (commsyml) redefined('c');
334 commsymlen = strlen(a);
337 case 'a': /* add new accessor */
338 getaccessor(*argv+1, append);
341 case 'A': /* append access list according to accessfile */
343 error("missing pathname after -A");
347 if (0 < pairnames(1,argv,rcsreadopen,true,false)) {
349 getchaccess(str_save(AccessList->login),append);
350 AccessList = AccessList->nextaccess;
356 case 'e': /* remove accessors */
357 getaccessor(*argv+1, erase);
360 case 'l': /* lock a revision if it is unlocked */
362 /* Lock head or default branch. */
366 *curlock = lockpt = talloc(struct Lockrev);
369 curlock = &lockpt->nextrev;
372 case 'u': /* release lock of a locked revision */
377 *rmvlock = lockpt = talloc(struct Lockrev);
380 rmvlock = &lockpt->nextrev;
381 curlock = rmnewlocklst(lockpt->revno);
384 case 'L': /* set strict locking */
385 if (strict_selected) {
386 if (!strictlock) /* Already selected -U? */
387 warn("-U overridden by -L");
390 strict_selected = true;
393 case 'U': /* release strict locking */
394 if (strict_selected) {
395 if (strictlock) /* Already selected -L? */
396 warn("-L overridden by -U");
398 strict_selected = true;
401 case 'n': /* add new association: error, if name exists */
403 error("missing symbolic name after -n");
406 getassoclst(false, (*argv)+1);
409 case 'N': /* add or change association */
411 error("missing symbolic name after -N");
414 getassoclst(true, (*argv)+1);
417 case 'm': /* change log message */
421 case 'M': /* do not send mail */
422 suppress_mail = true;
425 case 'o': /* delete revisions */
426 if (delrev.strt) redefined('o');
428 error("missing revision range after -o");
431 getdelrev( (*argv)+1 );
434 case 's': /* change state attribute of a revision */
436 error("state missing after -s");
439 getstates( (*argv)+1);
442 case 't': /* change descriptive text */
445 if (textfile) redefined('t');
450 case 'T': /* do not update last-mod time for minor changes */
457 interactiveflag = true;
469 setRCSversion(*argv);
476 case 'k': /* set keyword expand mode */
477 if (0 <= expmode) redefined('k');
478 if (0 <= (expmode = str2expmode(a)))
483 error("unknown option: %s%s", *argv, cmdusage);
485 } /* end processing of options */
487 /* Now handle all pathnames. */
488 if (nerror) cleanup();
489 else if (argc < 1) faterror("no input file%s", cmdusage);
490 else for (; 0 < argc; cleanup(), ++argv, --argc) {
495 switch (pairnames(argc, argv, rcswriteopen, false, false)) {
496 case -1: break; /* not exist; ok */
497 case 0: continue; /* error */
498 case 1: rcserror("already exists");
503 switch (pairnames(argc, argv, rcswriteopen, true, false)) {
504 case -1: continue; /* not exist */
505 case 0: continue; /* errors */
506 case 1: break; /* file exists; ok*/
512 * RCSname contains the name of the RCS file, and
513 * workname contains the name of the working file.
514 * if !initflag, finptr contains the file descriptor for the
515 * RCS file. The admin node is initialized.
518 diagnose("RCS file: %s\n", RCSname);
520 changed = initflag | textflag;
521 keepRCStime = Ttimeflag;
523 if (!checkaccesslist()) continue;
524 gettree(); /* Read the delta tree. */
527 /* update admin. node */
528 if (strict_selected) {
529 changed |= StrictLocks ^ strictlock;
530 StrictLocks = strictlock;
535 commsymlen != Comment.size ||
536 memcmp(commsyml, Comment.string, commsymlen) != 0
539 Comment.string = commsyml;
540 Comment.size = strlen(commsyml);
543 if (0 <= expmode && Expand != expmode) {
548 /* update default branch */
549 if (branchflag && expandsym(branchsym, &branchnum)) {
550 if (countnumflds(branchnum.string)) {
551 if (cmpnum(Dbranch, branchnum.string) != 0) {
552 Dbranch = branchnum.string;
562 changed |= doaccess(); /* Update access list. */
564 changed |= doassoc(); /* Update association list. */
566 changed |= dolocks(); /* Update locks. */
568 changed |= domessages(); /* Update log messages. */
570 /* update state attribution */
572 /* change state of default branch or head */
575 rcswarn("can't change states in an empty tree");
576 else if (strcmp(Head->state, headstate) != 0) {
577 Head->state = headstate;
581 changed |= rcs_setstate(Dbranch,headstate);
583 for (curstate = statelst; curstate; curstate = curstate->nextstatus)
584 changed |= rcs_setstate(curstate->revno,curstate->status);
586 cuthead = cuttail = 0;
587 if (delrev.strt && removerevs()) {
588 /* rebuild delta tree if some deltas are deleted */
591 cuttail->num, (char *)0, (char *)0, (char *)0,
604 puttree(Head, frewrite);
605 putdesc(textflag,textfile);
608 if (delrev.strt || messagelst) {
609 if (!cuttail || buildeltatext(gendeltas)) {
610 advise_access(finptr, MADV_SEQUENTIAL);
611 scanlogtext((struct hshentry *)0, false);
612 /* copy rest of delta text nodes that are not deleted */
619 /* Adjust things for donerewrite's sake. */
620 if (stat(workname, &RCSstat) != 0) {
624 RCSstat.st_mode = (S_IRUSR|S_IRGRP|S_IROTH) & ~m;
629 RCSstat.st_nlink = 0;
632 if (donerewrite(changed,
633 keepRCStime ? RCSstat.st_mtime : (time_t)-1
641 exitmain(exitstatus);
642 } /* end of main (rcs) */
647 if (nerror) exitstatus = EXIT_FAILURE;
665 getassoclst(flag, sp)
668 /* Function: associate a symbolic name to a revision or branch, */
669 /* and store in assoclst */
676 while ((c = *++sp) == ' ' || c == '\t' || c =='\n')
679 sp = checksym(sp, ':'); /* check for invalid symbolic name */
681 while( c == ' ' || c == '\t' || c == '\n') c = *++sp;
683 if ( c != ':' && c != '\0') {
684 error("invalid string %s after option -n or -N",sp);
688 pt = talloc(struct Symrev);
691 if (c == '\0') /* delete symbol */
694 while ((c = *++sp) == ' ' || c == '\n' || c == '\t')
700 nextassoc = &pt->nextsym;
705 getchaccess(login, command)
707 enum changeaccess command;
709 register struct chaccess *pt;
711 pt = talloc(struct chaccess);
713 pt->command = command;
714 pt->nextchaccess = 0;
716 nextchaccess = &pt->nextchaccess;
722 getaccessor(opt, command)
724 enum changeaccess command;
725 /* Function: get the accessor list of options -e and -a, */
726 /* and store in chaccess */
734 while ((c = *++sp) == ' ' || c == '\n' || c == '\t' || c == ',')
737 if (command == erase && sp-opt == 1) {
738 getchaccess((char*)0, command);
741 error("missing login name after option -a or -e");
746 getchaccess(sp, command);
747 sp = checkid(sp,',');
749 while( c == ' ' || c == '\n' || c == '\t'|| c == ',')c =(*++sp);
762 if (!(m = strchr(option, ':'))) {
763 error("-m option lacks revision number");
767 cb = cleanlogmsg(m, strlen(m));
769 error("-m option lacks log message");
772 pt = talloc(struct Message);
777 nextmessage = &pt->nextmessage;
784 /* Function: get one state attribute and the corresponding */
785 /* revision and store in statelst */
792 while ((c = *++sp) ==' ' || c == '\t' || c == '\n')
795 sp = checkid(sp,':'); /* check for invalid state attribute */
797 while( c == ' ' || c == '\t' || c == '\n' ) c = *++sp;
799 if ( c == '\0' ) { /* change state of def. branch or Head */
804 else if ( c != ':' ) {
805 error("missing ':' after state in option -s");
809 while ((c = *++sp) == ' ' || c == '\t' || c == '\n')
811 pt = talloc(struct Status);
816 nextstate = &pt->nextstatus;
824 /* Function: get revision range or branch to be deleted, */
825 /* and place in delrev */
828 struct delrevpair *pt;
832 while ((c = (*++sp)) == ' ' || c == '\n' || c == '\t')
835 /* Support old ambiguous '-' syntax; this will go away. */
839 if (strchr(sp,'-') && VERSION(5) <= RCSversion)
840 warn("`-' is obsolete in `-o%s'; use `:' instead", sp);
844 if (c == separator) { /* -o:rev */
845 while ((c = (*++sp)) == ' ' || c == '\n' || c == '\t')
847 pt->strt = sp; pt->code = 1;
848 while( c != ' ' && c != '\n' && c != '\t' && c != '\0') c =(*++sp);
855 while( c != ' ' && c != '\n' && c != '\t' && c != '\0'
856 && c != separator ) c = *++sp;
858 while( c == ' ' || c == '\n' || c == '\t' ) c = *++sp;
859 if ( c == '\0' ) { /* -o rev or branch */
864 if (c != separator) {
865 error("invalid range %s %s after -o", pt->strt, sp);
867 while ((c = *++sp) == ' ' || c == '\n' || c == '\t')
869 if (!c) { /* -orev: */
876 pt->end = sp; pt->code = 3;
877 while( c!= ' ' && c != '\n' && c != '\t' && c != '\0') c = *++sp;
885 scanlogtext(delta,edit)
886 struct hshentry *delta;
888 /* Function: Scans delta text nodes up to and including the one given
889 * by delta, or up to last one present, if !delta.
890 * For the one given by delta (if delta), the log message is saved into
891 * delta->log if delta==cuttail; the text is edited if EDIT is set, else copied.
892 * Assumes the initial lexeme must be read in first.
893 * Does not advance nexttok after it is finished, except if !delta.
896 struct hshentry const *nextdelta;
903 rcsfaterror("can't find delta for revision %s",
906 return; /* no more delta text nodes */
909 if (!(nextdelta=getnum()))
910 fatserror("delta number corrupted");
911 if (nextdelta->selector) {
913 aprintf(frewrite,DELNUMFORM,nextdelta->num,Klog);
916 if (nextdelta == cuttail) {
917 cb = savestring(&curlogbuf);
918 if (!delta->log.string)
919 delta->log = cleanlogmsg(curlogbuf.string, cb.size);
921 delta->igtext = getphrases(Ktext);
923 if (nextdelta->log.string && nextdelta->selector) {
927 putstring(foutptr, false, nextdelta->log, true);
928 afputc(nextc, foutptr);
931 ignorephrases(Ktext);
935 if (delta==nextdelta)
937 readstring(); /* skip over it */
940 /* got the one we're looking for */
942 editstring((struct hshentry*)0);
949 static struct Lockrev **
952 /* Remove lock to revision WHICH from newlocklst. */
954 struct Lockrev *pt, **pre;
958 if (strcmp(pt->revno, which) != 0)
972 register struct chaccess *ch;
973 register struct access **p, *t;
974 register int changed = false;
976 for (ch = chaccess; ch; ch = ch->nextchaccess) {
977 switch (ch->command) {
985 for (p = &AccessList; (t = *p); p = &t->nextaccess)
986 if (strcmp(ch->login, t->login) == 0) {
993 for (p = &AccessList; ; p = &t->nextaccess)
995 *p = t = ftalloc(struct access);
996 t->login = ch->login;
1000 } else if (strcmp(ch->login, t->login) == 0)
1010 sendmail(Delta, who)
1011 char const *Delta, *who;
1012 /* Function: mail to who, informing him that his lock on delta was
1013 * broken by caller. Ask first whether to go ahead. Return false on
1014 * error or if user decides not to break the lock.
1018 char const *messagefile;
1019 int old1, old2, c, status;
1024 aprintf(stderr, "Revision %s is already locked by %s.\n", Delta, who);
1027 if (!yesorno(false, "Do you want to break the lock? [ny](n): "))
1030 /* go ahead with breaking */
1032 messagefile = maketemp(0);
1033 if (!(mailmess = fopenSafer(messagefile, "w+"))) {
1034 efaterror(messagefile);
1037 aprintf(mailmess, "Subject: Broken lock on %s\n\nYour lock on revision %s of file %s\nhas been broken by %s for the following reason:\n",
1038 basefilename(RCSname), Delta, getfullRCSname(), getcaller()
1040 aputs("State the reason for breaking the lock:\n(terminate with single '.' or end of file)\n>> ", stderr);
1043 old1 = '\n'; old2 = ' ';
1047 aprintf(mailmess, "%c\n", old1);
1050 else if ( c == '\n' && old1 == '.' && old2 == '\n')
1053 afputc(old1, mailmess);
1054 old2 = old1; old1 = c;
1056 aputs(">> ", stderr);
1063 status = run(fileno(mailmess), (char*)0, SENDMAIL, who, (char*)0);
1067 warn("Mail failed.");
1069 warn("Mail notification of broken locks is not available.");
1070 warn("Please tell `%s' why you broke the lock.", who);
1078 struct hshentry const *delta;
1079 /* function: Finds the lock held by caller on delta,
1081 * Sends mail if a lock different from the caller's is broken.
1082 * Prints an error message if there is no such lock or error.
1085 register struct rcslock *next, **trail;
1089 for (trail = &Locks; (next = *trail); trail = &next->nextlock)
1090 if (strcmp(num, next->delta->num) == 0) {
1092 strcmp(getcaller(),next->login) != 0
1093 && !sendmail(num, next->login)
1095 rcserror("revision %s still locked by %s",
1100 diagnose("%s unlocked\n", next->delta->num);
1101 *trail = next->nextlock;
1102 next->delta->lockedby = 0;
1105 rcserror("no lock set on revision %s", num);
1111 static struct hshentry *
1112 searchcutpt(object, length, store)
1115 struct hshentries *store;
1116 /* Function: Search store and return entry with number being object. */
1117 /* cuttail = 0, if the entry is Head; otherwise, cuttail */
1118 /* is the entry point to the one with number being object */
1122 while (compartial(store->first->num, object, length)) {
1123 cuthead = store->first;
1124 store = store->rest;
1126 return store->first;
1132 branchpoint(strt, tail)
1133 struct hshentry *strt, *tail;
1134 /* Function: check whether the deltas between strt and tail */
1135 /* are locked or branch point, return 1 if any is */
1136 /* locked or branch point; otherwise, return 0 and */
1140 struct hshentry *pt;
1141 struct rcslock const *lockpt;
1143 for (pt = strt; pt != tail; pt = pt->next) {
1144 if ( pt->branches ){ /* a branch point */
1145 rcserror("can't remove branch point %s", pt->num);
1148 for (lockpt = Locks; lockpt; lockpt = lockpt->nextlock)
1149 if (lockpt->delta == pt) {
1150 rcserror("can't remove locked revision %s", pt->num);
1153 pt->selector = false;
1154 diagnose("deleting revision %s\n",pt->num);
1163 /* Function: get the revision range to be removed, and place the */
1164 /* first revision removed in delstrt, the revision before */
1165 /* delstrt in cuthead (0, if delstrt is head), and the */
1166 /* revision after the last removed revision in cuttail (0 */
1167 /* if the last is a leaf */
1170 struct hshentry *target, *target2, *temp;
1174 if (!expandsym(delrev.strt, &numrev)) return 0;
1175 target = genrevs(numrev.string,(char*)0,(char*)0,(char*)0,&gendeltas);
1176 if ( ! target ) return 0;
1177 cmp = cmpnum(target->num, numrev.string);
1178 length = countnumflds(numrev.string);
1180 if (delrev.code == 0) { /* -o rev or -o branch */
1182 temp=searchcutpt(target->num,length+1,gendeltas);
1184 rcserror("Revision %s doesn't exist.", numrev.string);
1188 temp = searchcutpt(numrev.string, length, gendeltas);
1189 cuttail = target->next;
1190 if ( branchpoint(temp, cuttail) ) {
1194 delstrt = temp; /* first revision to be removed */
1198 if (length & 1) { /* invalid branch after -o */
1199 rcserror("invalid branch range %s after -o", numrev.string);
1203 if (delrev.code == 1) { /* -o -rev */
1205 temp = searchcutpt( target->num, length-1, gendeltas);
1206 cuttail = target->next;
1209 temp = searchcutpt(target->num, length, gendeltas);
1211 while( cuttail && ! cmpnumfld(target->num,cuttail->num,1) )
1212 cuttail = cuttail->next;
1214 if ( branchpoint(temp, cuttail) ){
1222 if (delrev.code == 2) { /* -o rev- */
1223 if ( length == 2 ) {
1224 temp = searchcutpt(target->num, 1,gendeltas);
1228 cuttail = target->next;
1233 if ( !(temp = target->next) ) return 0;
1236 temp = searchcutpt(target->num, length, gendeltas);
1237 getbranchno(temp->num, &numrev); /* get branch number */
1238 VOID genrevs(numrev.string, (char*)0, (char*)0, (char*)0, &gendeltas);
1240 if ( branchpoint( temp, cuttail ) ) {
1249 if (!expandsym(delrev.end, &numrev)) return 0;
1251 length != countnumflds(numrev.string)
1252 || (length>2 && compartial(numrev.string, target->num, length-1))
1254 rcserror("invalid revision range %s-%s",
1255 target->num, numrev.string
1260 target2 = genrevs(numrev.string,(char*)0,(char*)0,(char*)0,&gendeltas);
1261 if ( ! target2 ) return 0;
1263 if ( length > 2) { /* delete revisions on branches */
1264 if ( cmpnum(target->num, target2->num) > 0) {
1265 cmp = cmpnum(target2->num, numrev.string);
1271 if ( ! cmpnum(target->num, target2->num) ) {
1272 rcserror("Revisions %s-%s don't exist.",
1273 delrev.strt, delrev.end
1278 temp = target->next;
1281 temp = searchcutpt(target->num, length, gendeltas);
1282 cuttail = target2->next;
1284 else { /* delete revisions on trunk */
1285 if ( cmpnum( target->num, target2->num) < 0 ) {
1291 cmp = cmpnum(target2->num, numrev.string);
1293 if ( ! cmpnum(target->num, target2->num) ) {
1294 rcserror("Revisions %s-%s don't exist.",
1295 delrev.strt, delrev.end
1302 cuttail = target2->next;
1303 temp = searchcutpt(target->num, length, gendeltas);
1305 if ( branchpoint(temp, cuttail) ) {
1317 /* Add or delete (if !revno) association that is stored in assoclst. */
1320 int changed = false;
1321 struct Symrev const *curassoc;
1322 struct assoc **pre, *pt;
1324 /* add new associations */
1325 for (curassoc = assoclst; curassoc; curassoc = curassoc->nextsym) {
1326 char const *ssymbol = curassoc->ssymbol;
1328 if (!curassoc->revno) { /* delete symbol */
1329 for (pre = &Symbols; ; pre = &pt->nextassoc)
1331 rcswarn("can't delete nonexisting symbol %s", ssymbol);
1333 } else if (strcmp(pt->symbol, ssymbol) == 0) {
1334 *pre = pt->nextassoc;
1340 if (curassoc->revno[0]) {
1342 if (expandsym(curassoc->revno, &numrev))
1343 p = fstr_save(numrev.string);
1344 } else if (!(p = tiprev()))
1345 rcserror("no latest revision to associate with symbol %s",
1349 changed |= addsymbol(p, ssymbol, curassoc->override);
1359 /* Function: remove lock for caller or first lock if unlockcaller is set;
1360 * remove locks which are stored in rmvlocklst,
1361 * add new locks which are stored in newlocklst,
1362 * add lock for Dbranch or Head if lockhead is set.
1365 struct Lockrev const *lockpt;
1366 struct hshentry *target;
1367 int changed = false;
1369 if (unlockcaller) { /* find lock for caller */
1372 switch (findlock(true, &target)) {
1374 /* remove most recent lock */
1375 changed |= breaklock(Locks->delta);
1378 diagnose("%s unlocked\n",target->num);
1383 rcswarn("No locks are set.");
1386 rcswarn("can't unlock an empty tree");
1390 /* remove locks which are stored in rmvlocklst */
1391 for (lockpt = rmvlocklst; lockpt; lockpt = lockpt->nextrev)
1392 if (expandsym(lockpt->revno, &numrev)) {
1393 target = genrevs(numrev.string, (char *)0, (char *)0, (char *)0, &gendeltas);
1395 if (!(countnumflds(numrev.string)&1) && cmpnum(target->num,numrev.string))
1396 rcserror("can't unlock nonexisting revision %s",
1400 changed |= breaklock(target);
1401 /* breaklock does its own diagnose */
1404 /* add new locks which stored in newlocklst */
1405 for (lockpt = newlocklst; lockpt; lockpt = lockpt->nextrev)
1406 changed |= setlock(lockpt->revno);
1408 if (lockhead) /* lock default branch or head */
1410 changed |= setlock(Dbranch);
1412 changed |= setlock(Head->num);
1414 rcswarn("can't lock an empty tree");
1423 /* Function: Given a revision or branch number, finds the corresponding
1424 * delta and locks it for caller.
1427 struct hshentry *target;
1430 if (expandsym(rev, &numrev)) {
1431 target = genrevs(numrev.string, (char*)0, (char*)0,
1432 (char*)0, &gendeltas);
1434 if (!(countnumflds(numrev.string)&1) && cmpnum(target->num,numrev.string))
1435 rcserror("can't lock nonexisting revision %s",
1439 if ((r = addlock(target, false)) < 0 && breaklock(target))
1440 r = addlock(target, true);
1443 diagnose("%s locked\n", target->num);
1455 struct hshentry *target;
1457 int changed = false;
1459 for (p = messagelst; p; p = p->nextmessage)
1461 expandsym(p->revno, &numrev) &&
1463 numrev.string, (char*)0, (char*)0, (char*)0, &gendeltas
1467 * We can't check the old log -- it's much later in the file.
1468 * We pessimistically assume that it changed.
1470 target->log = p->message;
1478 rcs_setstate(rev,status)
1479 char const *rev, *status;
1480 /* Function: Given a revision or branch number, finds the corresponding delta
1481 * and sets its state to status.
1484 struct hshentry *target;
1486 if (expandsym(rev, &numrev)) {
1487 target = genrevs(numrev.string, (char*)0, (char*)0,
1488 (char*)0, &gendeltas);
1490 if (!(countnumflds(numrev.string)&1) && cmpnum(target->num,numrev.string))
1491 rcserror("can't set state of nonexisting revision %s",
1494 else if (strcmp(target->state, status) != 0) {
1495 target->state = status;
1507 buildeltatext(deltas)
1508 struct hshentries const *deltas;
1509 /* Function: put the delta text on frewrite and make necessary */
1510 /* change to delta text */
1512 register FILE *fcut; /* temporary file to rebuild delta tree */
1513 char const *cutname;
1516 cuttail->selector = false;
1517 scanlogtext(deltas->first, false);
1519 cutname = maketemp(3);
1520 if (!(fcut = fopenSafer(cutname, FOPEN_WPLUS_WORK))) {
1524 while (deltas->first != cuthead) {
1525 deltas = deltas->rest;
1526 scanlogtext(deltas->first, true);
1534 while (deltas->first != cuttail)
1535 scanlogtext((deltas = deltas->rest)->first, true);
1536 finishedit((struct hshentry*)0, (FILE*)0, true);
1540 char const *diffname = maketemp(0);
1541 char const *diffv[6 + !!OPEN_O_BINARY];
1542 char const **diffp = diffv;
1544 *++diffp = DIFFFLAGS;
1546 if (Expand == BINARY_EXPAND)
1547 *++diffp == "--binary";
1550 *++diffp = resultname;
1552 switch (runv(fileno(fcut), diffname, diffv)) {
1553 case DIFF_FAILURE: case DIFF_SUCCESS: break;
1554 default: rcsfaterror("diff failed");
1557 return putdtext(cuttail,diffname,frewrite,true);
1559 return putdtext(cuttail,resultname,frewrite,false);
1566 /* Function: actually removes revisions whose selector field */
1567 /* is false, and rebuilds the linkage of deltas. */
1568 /* asks for reconfirmation if deleting last revision*/
1570 struct hshentry * Delta;
1571 struct branchhead *pt, *pre;
1574 if ( cuthead->next == delstrt )
1575 cuthead->next = cuttail;
1577 pre = pt = cuthead->branches;
1578 while( pt && pt->hsh != delstrt ) {
1580 pt = pt->nextbranch;
1584 else if ( pt == pre )
1585 cuthead->branches = pt->nextbranch;
1587 pre->nextbranch = pt->nextbranch;
1590 if (!cuttail && !quietflag) {
1591 if (!yesorno(false, "Do you really want to delete all revisions? [ny](n): ")) {
1592 rcserror("No revision deleted");
1595 Delta->selector = true;
1596 Delta = Delta->next;
1607 /* This lets us lint everything all at once. */
1609 char const cmdid[] = "";
1611 #define go(p,e) {int p P((int,char**)); void e P((void)); if(*argv)return p(argc,argv);if(*argv[1])e();}
1620 go(identId, identExit);
1621 go(mergeId, mergeExit);
1623 go(rcscleanId, rcscleanExit);
1624 go(rcsdiffId, rdiffExit);
1625 go(rcsmergeId, rmergeExit);
1626 go(rlogId, rlogExit);