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 * $FreeBSD: src/gnu/usr.bin/rcs/rcs/rcs.c,v 1.7 1999/08/27 23:36:52 peter Exp $
32 * $DragonFly: src/gnu/usr.bin/rcs/rcs/rcs.c,v 1.2 2003/06/17 04:25:47 dillon Exp $
34 * Revision 5.21 1995/06/16 06:19:24 eggert
37 * Revision 5.20 1995/06/01 16:23:43 eggert
38 * (main): Warn if no options were given. Punctuate messages properly.
40 * (sendmail): Rewind mailmess before flushing it.
41 * Output another warning if mail should work but fails.
43 * (buildeltatext): Pass "--binary" if -kb and if --binary makes a difference.
45 * Revision 5.19 1994/03/17 14:05:48 eggert
46 * Use ORCSerror to clean up after a fatal error. Remove lint.
47 * Specify subprocess input via file descriptor, not file name. Remove lint.
48 * Flush stderr after prompt.
50 * Revision 5.18 1993/11/09 17:40:15 eggert
51 * -V now prints version on stdout and exits. Don't print usage twice.
53 * Revision 5.17 1993/11/03 17:42:27 eggert
54 * Add -z. Don't lose track of -m or -t when there are no other changes.
55 * Don't discard ignored phrases. Improve quality of diagnostics.
57 * Revision 5.16 1992/07/28 16:12:44 eggert
58 * rcs -l now asks whether you want to break the lock.
59 * Add -V. Set RCS file's mode and time at right moment.
61 * Revision 5.15 1992/02/17 23:02:20 eggert
64 * Revision 5.14 1992/01/27 16:42:53 eggert
65 * Add -M. Avoid invoking umask(); it's one less thing to configure.
66 * Add support for bad_creat0. lint -> RCS_lint
68 * Revision 5.13 1992/01/06 02:42:34 eggert
69 * Avoid changing RCS file in common cases where no change can occur.
71 * Revision 5.12 1991/11/20 17:58:08 eggert
72 * Don't read the delta tree from a nonexistent RCS file.
74 * Revision 5.11 1991/10/07 17:32:46 eggert
77 * Revision 5.10 1991/08/19 23:17:54 eggert
78 * Add -m, -r$, piece tables. Revision separator is `:', not `-'. Tune.
80 * Revision 5.9 1991/04/21 11:58:18 eggert
81 * Add -x, RCSINIT, MS-DOS support.
83 * Revision 5.8 1991/02/25 07:12:38 eggert
84 * strsave -> str_save (DG/UX name clash)
85 * 0444 -> S_IRUSR|S_IRGRP|S_IROTH for portability
87 * Revision 5.7 1990/12/18 17:19:21 eggert
88 * Fix bug with multiple -n and -N options.
90 * Revision 5.6 1990/12/04 05:18:40 eggert
91 * Use -I for prompts and -q for diagnostics.
93 * Revision 5.5 1990/11/11 00:06:35 eggert
94 * Fix `rcs -e' core dump.
96 * Revision 5.4 1990/11/01 05:03:33 eggert
97 * Add -I and new -t behavior. Permit arbitrary data in logs.
99 * Revision 5.3 1990/10/04 06:30:16 eggert
100 * Accumulate exit status across files.
102 * Revision 5.2 1990/09/04 08:02:17 eggert
103 * Standardize yes-or-no procedure.
105 * Revision 5.1 1990/08/29 07:13:51 eggert
106 * Remove unused setuid support. Clean old log messages too.
108 * Revision 5.0 1990/08/22 08:12:42 eggert
109 * Don't lose names when applying -a option to multiple files.
110 * Remove compile-time limits; use malloc instead. Add setuid support.
111 * Permit dates past 1999/12/31. Make lock and temp files faster and safer.
112 * Ansify and Posixate. Add -V. Fix umask bug. Make linting easier. Tune.
113 * Yield proper exit status. Check diff's output.
115 * Revision 4.11 89/05/01 15:12:06 narten
116 * changed copyright header to reflect current distribution rules
118 * Revision 4.10 88/11/08 16:01:54 narten
119 * didn't install previous patch correctly
121 * Revision 4.9 88/11/08 13:56:01 narten
122 * removed include <sysexits.h> (not needed)
123 * minor fix for -A option
125 * Revision 4.8 88/08/09 19:12:27 eggert
126 * Don't access freed storage.
127 * Use execv(), not system(); yield proper exit status; remove lint.
129 * Revision 4.7 87/12/18 11:37:17 narten
130 * lint cleanups (Guy Harris)
132 * Revision 4.6 87/10/18 10:28:48 narten
133 * Updating verison numbers. Changes relative to 1.1 are actually
136 * Revision 1.4 87/09/24 13:58:52 narten
137 * Sources now pass through lint (if you ignore printf/sprintf/fprintf
140 * Revision 1.3 87/03/27 14:21:55 jenkins
143 * Revision 1.2 85/12/17 13:59:09 albitz
144 * Changed setstate to rcs_setstate because of conflict with random.o.
146 * Revision 4.3 83/12/15 12:27:33 wft
147 * rcs -u now breaks most recent lock if it can't find a lock by the caller.
149 * Revision 4.2 83/12/05 10:18:20 wft
150 * Added conditional compilation for sending mail.
151 * Alternatives: V4_2BSD, V6, USG, and other.
153 * Revision 4.1 83/05/10 16:43:02 wft
154 * Simplified breaklock(); added calls to findlock() and getcaller().
155 * Added option -b (default branch). Updated -s and -w for -b.
156 * Removed calls to stat(); now done by pairfilenames().
157 * Replaced most catchints() calls with restoreints().
158 * Removed check for exit status of delivermail().
159 * Directed all interactive output to stderr.
161 * Revision 3.9.1.1 83/12/02 22:08:51 wft
162 * Added conditional compilation for 4.2 sendmail and 4.1 delivermail.
164 * Revision 3.9 83/02/15 15:38:39 wft
165 * Added call to fastcopy() to copy remainder of RCS file.
167 * Revision 3.8 83/01/18 17:37:51 wft
168 * Changed sendmail(): now uses delivermail, and asks whether to break the lock.
170 * Revision 3.7 83/01/15 18:04:25 wft
171 * Removed putree(); replaced with puttree() in rcssyn.c.
172 * Combined putdellog() and scanlogtext(); deleted putdellog().
173 * Cleaned up diagnostics and error messages. Fixed problem with
174 * mutilated files in case of deletions in 2 files in a single command.
175 * Changed marking of selector from 'D' to DELETE.
177 * Revision 3.6 83/01/14 15:37:31 wft
178 * Added ignoring of interrupts while new RCS file is renamed;
179 * Avoids deletion of RCS files by interrupts.
181 * Revision 3.5 82/12/10 21:11:39 wft
182 * Removed unused variables, fixed checking of return code from diff,
183 * introduced variant COMPAT2 for skipping Suffix on -A files.
185 * Revision 3.4 82/12/04 13:18:20 wft
186 * Replaced getdelta() with gettree(), changed breaklock to update
187 * field lockedby, added some diagnostics.
189 * Revision 3.3 82/12/03 17:08:04 wft
190 * Replaced getlogin() with getpwuid(), flcose() with ffclose(),
191 * /usr/ucb/Mail with macro MAIL. Removed handling of Suffix (-x).
192 * fixed -u for missing revno. Disambiguated structure members.
194 * Revision 3.2 82/10/18 21:05:07 wft
195 * rcs -i now generates a file mode given by the umask minus write permission;
196 * otherwise, rcs keeps the mode, but removes write permission.
197 * I added a check for write error, fixed call to getlogin(), replaced
198 * curdir() with getfullRCSname(), cleaned up handling -U/L, and changed
199 * conflicting, long identifiers.
201 * Revision 3.1 82/10/13 16:11:07 wft
202 * fixed type of variables receiving from getc() (char -> int).
210 struct Lockrev * nextrev;
217 struct Symrev * nextsym;
223 struct Message *nextmessage;
229 struct Status * nextstatus;
232 enum changeaccess {append, erase};
235 enum changeaccess command;
236 struct chaccess *nextchaccess;
245 static int branchpoint P((struct hshentry*,struct hshentry*));
246 static int breaklock P((struct hshentry const*));
247 static int buildeltatext P((struct hshentries const*));
248 static int doaccess P((void));
249 static int doassoc P((void));
250 static int dolocks P((void));
251 static int domessages P((void));
252 static int rcs_setstate P((char const*,char const*));
253 static int removerevs P((void));
254 static int sendmail P((char const*,char const*));
255 static int setlock P((char const*));
256 static struct Lockrev **rmnewlocklst P((char const*));
257 static struct hshentry *searchcutpt P((char const*,int,struct hshentries*));
258 static void buildtree P((void));
259 static void cleanup P((void));
260 static void getaccessor P((char*,enum changeaccess));
261 static void getassoclst P((int,char*));
262 static void getchaccess P((char const*,enum changeaccess));
263 static void getdelrev P((char*));
264 static void getmessage P((char*));
265 static void getstates P((char*));
266 static void scanlogtext P((struct hshentry*,int));
268 static struct buf numrev;
269 static char const *headstate;
270 static int chgheadstate, exitstatus, lockhead, unlockcaller;
271 static int suppress_mail;
272 static struct Lockrev *newlocklst, *rmvlocklst;
273 static struct Message *messagelst, **nextmessage;
274 static struct Status *statelst, **nextstate;
275 static struct Symrev *assoclst, **nextassoc;
276 static struct chaccess *chaccess, **nextchaccess;
277 static struct delrevpair delrev;
278 static struct hshentry *cuthead, *cuttail, *delstrt;
279 static struct hshentries *gendeltas;
281 mainProg(rcsId, "rcs", "$DragonFly: src/gnu/usr.bin/rcs/rcs/rcs.c,v 1.2 2003/06/17 04:25:47 dillon Exp $")
283 static char const cmdusage[] =
284 "\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 ...";
286 char *a, **newargv, *textfile;
287 char const *branchsym, *commsyml;
288 int branchflag, changed, expmode, initflag;
289 int strictlock, strict_selected, textflag;
290 int keepRCStime, Ttimeflag;
292 struct buf branchnum;
293 struct Lockrev *lockpt;
294 struct Lockrev **curlock, **rmvlock;
295 struct Status * curstate;
299 nextassoc = &assoclst;
300 nextchaccess = &chaccess;
301 nextmessage = &messagelst;
302 nextstate = &statelst;
303 branchsym = commsyml = textfile = 0;
304 branchflag = strictlock = false;
305 bufautobegin(&branchnum);
307 curlock = &newlocklst;
308 rmvlock = &rmvlocklst;
310 suffixes = X_DEFAULT;
311 initflag= textflag = false;
315 /* preprocessing command options */
316 if (1 < argc && argv[1][0] != '-')
317 warn("No options were given; this usage is obsolescent.");
319 argc = getRCSINIT(argc, argv, &newargv);
321 while (a = *++argv, 0<--argc && *a++=='-') {
324 case 'i': /* initial version */
328 case 'b': /* change default branch */
329 if (branchflag) redefined('b');
334 case 'c': /* change comment symbol */
335 if (commsyml) redefined('c');
337 commsymlen = strlen(a);
340 case 'a': /* add new accessor */
341 getaccessor(*argv+1, append);
344 case 'A': /* append access list according to accessfile */
346 error("missing pathname after -A");
350 if (0 < pairnames(1,argv,rcsreadopen,true,false)) {
352 getchaccess(str_save(AccessList->login),append);
353 AccessList = AccessList->nextaccess;
359 case 'e': /* remove accessors */
360 getaccessor(*argv+1, erase);
363 case 'l': /* lock a revision if it is unlocked */
365 /* Lock head or default branch. */
369 *curlock = lockpt = talloc(struct Lockrev);
372 curlock = &lockpt->nextrev;
375 case 'u': /* release lock of a locked revision */
380 *rmvlock = lockpt = talloc(struct Lockrev);
383 rmvlock = &lockpt->nextrev;
384 curlock = rmnewlocklst(lockpt->revno);
387 case 'L': /* set strict locking */
388 if (strict_selected) {
389 if (!strictlock) /* Already selected -U? */
390 warn("-U overridden by -L");
393 strict_selected = true;
396 case 'U': /* release strict locking */
397 if (strict_selected) {
398 if (strictlock) /* Already selected -L? */
399 warn("-L overridden by -U");
401 strict_selected = true;
404 case 'n': /* add new association: error, if name exists */
406 error("missing symbolic name after -n");
409 getassoclst(false, (*argv)+1);
412 case 'N': /* add or change association */
414 error("missing symbolic name after -N");
417 getassoclst(true, (*argv)+1);
420 case 'm': /* change log message */
424 case 'M': /* do not send mail */
425 suppress_mail = true;
428 case 'o': /* delete revisions */
429 if (delrev.strt) redefined('o');
431 error("missing revision range after -o");
434 getdelrev( (*argv)+1 );
437 case 's': /* change state attribute of a revision */
439 error("state missing after -s");
442 getstates( (*argv)+1);
445 case 't': /* change descriptive text */
448 if (textfile) redefined('t');
453 case 'T': /* do not update last-mod time for minor changes */
460 interactiveflag = true;
472 setRCSversion(*argv);
479 case 'k': /* set keyword expand mode */
480 if (0 <= expmode) redefined('k');
481 if (0 <= (expmode = str2expmode(a)))
486 error("unknown option: %s%s", *argv, cmdusage);
488 } /* end processing of options */
490 /* Now handle all pathnames. */
491 if (nerror) cleanup();
492 else if (argc < 1) faterror("no input file%s", cmdusage);
493 else for (; 0 < argc; cleanup(), ++argv, --argc) {
498 switch (pairnames(argc, argv, rcswriteopen, false, false)) {
499 case -1: break; /* not exist; ok */
500 case 0: continue; /* error */
501 case 1: rcserror("already exists");
506 switch (pairnames(argc, argv, rcswriteopen, true, false)) {
507 case -1: continue; /* not exist */
508 case 0: continue; /* errors */
509 case 1: break; /* file exists; ok*/
515 * RCSname contains the name of the RCS file, and
516 * workname contains the name of the working file.
517 * if !initflag, finptr contains the file descriptor for the
518 * RCS file. The admin node is initialized.
521 diagnose("RCS file: %s\n", RCSname);
523 changed = initflag | textflag;
524 keepRCStime = Ttimeflag;
526 if (!checkaccesslist()) continue;
527 gettree(); /* Read the delta tree. */
530 /* update admin. node */
531 if (strict_selected) {
532 changed |= StrictLocks ^ strictlock;
533 StrictLocks = strictlock;
538 commsymlen != Comment.size ||
539 memcmp(commsyml, Comment.string, commsymlen) != 0
542 Comment.string = commsyml;
543 Comment.size = strlen(commsyml);
546 if (0 <= expmode && Expand != expmode) {
551 /* update default branch */
552 if (branchflag && expandsym(branchsym, &branchnum)) {
553 if (countnumflds(branchnum.string)) {
554 if (cmpnum(Dbranch, branchnum.string) != 0) {
555 Dbranch = branchnum.string;
565 changed |= doaccess(); /* Update access list. */
567 changed |= doassoc(); /* Update association list. */
569 changed |= dolocks(); /* Update locks. */
571 changed |= domessages(); /* Update log messages. */
573 /* update state attribution */
575 /* change state of default branch or head */
578 rcswarn("can't change states in an empty tree");
579 else if (strcmp(Head->state, headstate) != 0) {
580 Head->state = headstate;
584 changed |= rcs_setstate(Dbranch,headstate);
586 for (curstate = statelst; curstate; curstate = curstate->nextstatus)
587 changed |= rcs_setstate(curstate->revno,curstate->status);
589 cuthead = cuttail = 0;
590 if (delrev.strt && removerevs()) {
591 /* rebuild delta tree if some deltas are deleted */
594 cuttail->num, (char *)0, (char *)0, (char *)0,
607 puttree(Head, frewrite);
608 putdesc(textflag,textfile);
611 if (delrev.strt || messagelst) {
612 if (!cuttail || buildeltatext(gendeltas)) {
613 advise_access(finptr, MADV_SEQUENTIAL);
614 scanlogtext((struct hshentry *)0, false);
615 /* copy rest of delta text nodes that are not deleted */
622 /* Adjust things for donerewrite's sake. */
623 if (stat(workname, &RCSstat) != 0) {
627 RCSstat.st_mode = (S_IRUSR|S_IRGRP|S_IROTH) & ~m;
632 RCSstat.st_nlink = 0;
635 if (donerewrite(changed,
636 keepRCStime ? RCSstat.st_mtime : (time_t)-1
644 exitmain(exitstatus);
645 } /* end of main (rcs) */
650 if (nerror) exitstatus = EXIT_FAILURE;
668 getassoclst(flag, sp)
671 /* Function: associate a symbolic name to a revision or branch, */
672 /* and store in assoclst */
679 while ((c = *++sp) == ' ' || c == '\t' || c =='\n')
682 sp = checksym(sp, ':'); /* check for invalid symbolic name */
684 while( c == ' ' || c == '\t' || c == '\n') c = *++sp;
686 if ( c != ':' && c != '\0') {
687 error("invalid string %s after option -n or -N",sp);
691 pt = talloc(struct Symrev);
694 if (c == '\0') /* delete symbol */
697 while ((c = *++sp) == ' ' || c == '\n' || c == '\t')
703 nextassoc = &pt->nextsym;
708 getchaccess(login, command)
710 enum changeaccess command;
712 register struct chaccess *pt;
714 pt = talloc(struct chaccess);
716 pt->command = command;
717 pt->nextchaccess = 0;
719 nextchaccess = &pt->nextchaccess;
725 getaccessor(opt, command)
727 enum changeaccess command;
728 /* Function: get the accessor list of options -e and -a, */
729 /* and store in chaccess */
737 while ((c = *++sp) == ' ' || c == '\n' || c == '\t' || c == ',')
740 if (command == erase && sp-opt == 1) {
741 getchaccess((char*)0, command);
744 error("missing login name after option -a or -e");
749 getchaccess(sp, command);
750 sp = checkid(sp,',');
752 while( c == ' ' || c == '\n' || c == '\t'|| c == ',')c =(*++sp);
765 if (!(m = strchr(option, ':'))) {
766 error("-m option lacks revision number");
770 cb = cleanlogmsg(m, strlen(m));
772 error("-m option lacks log message");
775 pt = talloc(struct Message);
780 nextmessage = &pt->nextmessage;
787 /* Function: get one state attribute and the corresponding */
788 /* revision and store in statelst */
795 while ((c = *++sp) ==' ' || c == '\t' || c == '\n')
798 sp = checkid(sp,':'); /* check for invalid state attribute */
800 while( c == ' ' || c == '\t' || c == '\n' ) c = *++sp;
802 if ( c == '\0' ) { /* change state of def. branch or Head */
807 else if ( c != ':' ) {
808 error("missing ':' after state in option -s");
812 while ((c = *++sp) == ' ' || c == '\t' || c == '\n')
814 pt = talloc(struct Status);
819 nextstate = &pt->nextstatus;
827 /* Function: get revision range or branch to be deleted, */
828 /* and place in delrev */
831 struct delrevpair *pt;
835 while ((c = (*++sp)) == ' ' || c == '\n' || c == '\t')
838 /* Support old ambiguous '-' syntax; this will go away. */
842 if (strchr(sp,'-') && VERSION(5) <= RCSversion)
843 warn("`-' is obsolete in `-o%s'; use `:' instead", sp);
847 if (c == separator) { /* -o:rev */
848 while ((c = (*++sp)) == ' ' || c == '\n' || c == '\t')
850 pt->strt = sp; pt->code = 1;
851 while( c != ' ' && c != '\n' && c != '\t' && c != '\0') c =(*++sp);
858 while( c != ' ' && c != '\n' && c != '\t' && c != '\0'
859 && c != separator ) c = *++sp;
861 while( c == ' ' || c == '\n' || c == '\t' ) c = *++sp;
862 if ( c == '\0' ) { /* -o rev or branch */
867 if (c != separator) {
868 error("invalid range %s %s after -o", pt->strt, sp);
870 while ((c = *++sp) == ' ' || c == '\n' || c == '\t')
872 if (!c) { /* -orev: */
879 pt->end = sp; pt->code = 3;
880 while( c!= ' ' && c != '\n' && c != '\t' && c != '\0') c = *++sp;
888 scanlogtext(delta,edit)
889 struct hshentry *delta;
891 /* Function: Scans delta text nodes up to and including the one given
892 * by delta, or up to last one present, if !delta.
893 * For the one given by delta (if delta), the log message is saved into
894 * delta->log if delta==cuttail; the text is edited if EDIT is set, else copied.
895 * Assumes the initial lexeme must be read in first.
896 * Does not advance nexttok after it is finished, except if !delta.
899 struct hshentry const *nextdelta;
906 rcsfaterror("can't find delta for revision %s",
909 return; /* no more delta text nodes */
912 if (!(nextdelta=getnum()))
913 fatserror("delta number corrupted");
914 if (nextdelta->selector) {
916 aprintf(frewrite,DELNUMFORM,nextdelta->num,Klog);
919 if (nextdelta == cuttail) {
920 cb = savestring(&curlogbuf);
921 if (!delta->log.string)
922 delta->log = cleanlogmsg(curlogbuf.string, cb.size);
924 delta->igtext = getphrases(Ktext);
926 if (nextdelta->log.string && nextdelta->selector) {
930 putstring(foutptr, false, nextdelta->log, true);
931 afputc(nextc, foutptr);
934 ignorephrases(Ktext);
938 if (delta==nextdelta)
940 readstring(); /* skip over it */
943 /* got the one we're looking for */
945 editstring((struct hshentry*)0);
952 static struct Lockrev **
955 /* Remove lock to revision WHICH from newlocklst. */
957 struct Lockrev *pt, **pre;
961 if (strcmp(pt->revno, which) != 0)
975 register struct chaccess *ch;
976 register struct access **p, *t;
977 register int changed = false;
979 for (ch = chaccess; ch; ch = ch->nextchaccess) {
980 switch (ch->command) {
988 for (p = &AccessList; (t = *p); p = &t->nextaccess)
989 if (strcmp(ch->login, t->login) == 0) {
996 for (p = &AccessList; ; p = &t->nextaccess)
998 *p = t = ftalloc(struct access);
999 t->login = ch->login;
1003 } else if (strcmp(ch->login, t->login) == 0)
1013 sendmail(Delta, who)
1014 char const *Delta, *who;
1015 /* Function: mail to who, informing him that his lock on delta was
1016 * broken by caller. Ask first whether to go ahead. Return false on
1017 * error or if user decides not to break the lock.
1021 char const *messagefile;
1022 int old1, old2, c, status;
1027 aprintf(stderr, "Revision %s is already locked by %s.\n", Delta, who);
1030 if (!yesorno(false, "Do you want to break the lock? [ny](n): "))
1033 /* go ahead with breaking */
1035 messagefile = maketemp(0);
1036 if (!(mailmess = fopenSafer(messagefile, "w+"))) {
1037 efaterror(messagefile);
1040 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",
1041 basefilename(RCSname), Delta, getfullRCSname(), getcaller()
1043 aputs("State the reason for breaking the lock:\n(terminate with single '.' or end of file)\n>> ", stderr);
1046 old1 = '\n'; old2 = ' ';
1050 aprintf(mailmess, "%c\n", old1);
1053 else if ( c == '\n' && old1 == '.' && old2 == '\n')
1056 afputc(old1, mailmess);
1057 old2 = old1; old1 = c;
1059 aputs(">> ", stderr);
1066 status = run(fileno(mailmess), (char*)0, SENDMAIL, who, (char*)0);
1070 warn("Mail failed.");
1072 warn("Mail notification of broken locks is not available.");
1073 warn("Please tell `%s' why you broke the lock.", who);
1081 struct hshentry const *delta;
1082 /* function: Finds the lock held by caller on delta,
1084 * Sends mail if a lock different from the caller's is broken.
1085 * Prints an error message if there is no such lock or error.
1088 register struct rcslock *next, **trail;
1092 for (trail = &Locks; (next = *trail); trail = &next->nextlock)
1093 if (strcmp(num, next->delta->num) == 0) {
1095 strcmp(getcaller(),next->login) != 0
1096 && !sendmail(num, next->login)
1098 rcserror("revision %s still locked by %s",
1103 diagnose("%s unlocked\n", next->delta->num);
1104 *trail = next->nextlock;
1105 next->delta->lockedby = 0;
1108 rcserror("no lock set on revision %s", num);
1114 static struct hshentry *
1115 searchcutpt(object, length, store)
1118 struct hshentries *store;
1119 /* Function: Search store and return entry with number being object. */
1120 /* cuttail = 0, if the entry is Head; otherwise, cuttail */
1121 /* is the entry point to the one with number being object */
1125 while (compartial(store->first->num, object, length)) {
1126 cuthead = store->first;
1127 store = store->rest;
1129 return store->first;
1135 branchpoint(strt, tail)
1136 struct hshentry *strt, *tail;
1137 /* Function: check whether the deltas between strt and tail */
1138 /* are locked or branch point, return 1 if any is */
1139 /* locked or branch point; otherwise, return 0 and */
1143 struct hshentry *pt;
1144 struct rcslock const *lockpt;
1146 for (pt = strt; pt != tail; pt = pt->next) {
1147 if ( pt->branches ){ /* a branch point */
1148 rcserror("can't remove branch point %s", pt->num);
1151 for (lockpt = Locks; lockpt; lockpt = lockpt->nextlock)
1152 if (lockpt->delta == pt) {
1153 rcserror("can't remove locked revision %s", pt->num);
1156 pt->selector = false;
1157 diagnose("deleting revision %s\n",pt->num);
1166 /* Function: get the revision range to be removed, and place the */
1167 /* first revision removed in delstrt, the revision before */
1168 /* delstrt in cuthead (0, if delstrt is head), and the */
1169 /* revision after the last removed revision in cuttail (0 */
1170 /* if the last is a leaf */
1173 struct hshentry *target, *target2, *temp;
1177 if (!expandsym(delrev.strt, &numrev)) return 0;
1178 target = genrevs(numrev.string,(char*)0,(char*)0,(char*)0,&gendeltas);
1179 if ( ! target ) return 0;
1180 cmp = cmpnum(target->num, numrev.string);
1181 length = countnumflds(numrev.string);
1183 if (delrev.code == 0) { /* -o rev or -o branch */
1185 temp=searchcutpt(target->num,length+1,gendeltas);
1187 rcserror("Revision %s doesn't exist.", numrev.string);
1191 temp = searchcutpt(numrev.string, length, gendeltas);
1192 cuttail = target->next;
1193 if ( branchpoint(temp, cuttail) ) {
1197 delstrt = temp; /* first revision to be removed */
1201 if (length & 1) { /* invalid branch after -o */
1202 rcserror("invalid branch range %s after -o", numrev.string);
1206 if (delrev.code == 1) { /* -o -rev */
1208 temp = searchcutpt( target->num, length-1, gendeltas);
1209 cuttail = target->next;
1212 temp = searchcutpt(target->num, length, gendeltas);
1214 while( cuttail && ! cmpnumfld(target->num,cuttail->num,1) )
1215 cuttail = cuttail->next;
1217 if ( branchpoint(temp, cuttail) ){
1225 if (delrev.code == 2) { /* -o rev- */
1226 if ( length == 2 ) {
1227 temp = searchcutpt(target->num, 1,gendeltas);
1231 cuttail = target->next;
1236 if ( !(temp = target->next) ) return 0;
1239 temp = searchcutpt(target->num, length, gendeltas);
1240 getbranchno(temp->num, &numrev); /* get branch number */
1241 VOID genrevs(numrev.string, (char*)0, (char*)0, (char*)0, &gendeltas);
1243 if ( branchpoint( temp, cuttail ) ) {
1252 if (!expandsym(delrev.end, &numrev)) return 0;
1254 length != countnumflds(numrev.string)
1255 || (length>2 && compartial(numrev.string, target->num, length-1))
1257 rcserror("invalid revision range %s-%s",
1258 target->num, numrev.string
1263 target2 = genrevs(numrev.string,(char*)0,(char*)0,(char*)0,&gendeltas);
1264 if ( ! target2 ) return 0;
1266 if ( length > 2) { /* delete revisions on branches */
1267 if ( cmpnum(target->num, target2->num) > 0) {
1268 cmp = cmpnum(target2->num, numrev.string);
1274 if ( ! cmpnum(target->num, target2->num) ) {
1275 rcserror("Revisions %s-%s don't exist.",
1276 delrev.strt, delrev.end
1281 temp = target->next;
1284 temp = searchcutpt(target->num, length, gendeltas);
1285 cuttail = target2->next;
1287 else { /* delete revisions on trunk */
1288 if ( cmpnum( target->num, target2->num) < 0 ) {
1294 cmp = cmpnum(target2->num, numrev.string);
1296 if ( ! cmpnum(target->num, target2->num) ) {
1297 rcserror("Revisions %s-%s don't exist.",
1298 delrev.strt, delrev.end
1305 cuttail = target2->next;
1306 temp = searchcutpt(target->num, length, gendeltas);
1308 if ( branchpoint(temp, cuttail) ) {
1320 /* Add or delete (if !revno) association that is stored in assoclst. */
1323 int changed = false;
1324 struct Symrev const *curassoc;
1325 struct assoc **pre, *pt;
1327 /* add new associations */
1328 for (curassoc = assoclst; curassoc; curassoc = curassoc->nextsym) {
1329 char const *ssymbol = curassoc->ssymbol;
1331 if (!curassoc->revno) { /* delete symbol */
1332 for (pre = &Symbols; ; pre = &pt->nextassoc)
1334 rcswarn("can't delete nonexisting symbol %s", ssymbol);
1336 } else if (strcmp(pt->symbol, ssymbol) == 0) {
1337 *pre = pt->nextassoc;
1343 if (curassoc->revno[0]) {
1345 if (expandsym(curassoc->revno, &numrev))
1346 p = fstr_save(numrev.string);
1347 } else if (!(p = tiprev()))
1348 rcserror("no latest revision to associate with symbol %s",
1352 changed |= addsymbol(p, ssymbol, curassoc->override);
1362 /* Function: remove lock for caller or first lock if unlockcaller is set;
1363 * remove locks which are stored in rmvlocklst,
1364 * add new locks which are stored in newlocklst,
1365 * add lock for Dbranch or Head if lockhead is set.
1368 struct Lockrev const *lockpt;
1369 struct hshentry *target;
1370 int changed = false;
1372 if (unlockcaller) { /* find lock for caller */
1375 switch (findlock(true, &target)) {
1377 /* remove most recent lock */
1378 changed |= breaklock(Locks->delta);
1381 diagnose("%s unlocked\n",target->num);
1386 rcswarn("No locks are set.");
1389 rcswarn("can't unlock an empty tree");
1393 /* remove locks which are stored in rmvlocklst */
1394 for (lockpt = rmvlocklst; lockpt; lockpt = lockpt->nextrev)
1395 if (expandsym(lockpt->revno, &numrev)) {
1396 target = genrevs(numrev.string, (char *)0, (char *)0, (char *)0, &gendeltas);
1398 if (!(countnumflds(numrev.string)&1) && cmpnum(target->num,numrev.string))
1399 rcserror("can't unlock nonexisting revision %s",
1403 changed |= breaklock(target);
1404 /* breaklock does its own diagnose */
1407 /* add new locks which stored in newlocklst */
1408 for (lockpt = newlocklst; lockpt; lockpt = lockpt->nextrev)
1409 changed |= setlock(lockpt->revno);
1411 if (lockhead) /* lock default branch or head */
1413 changed |= setlock(Dbranch);
1415 changed |= setlock(Head->num);
1417 rcswarn("can't lock an empty tree");
1426 /* Function: Given a revision or branch number, finds the corresponding
1427 * delta and locks it for caller.
1430 struct hshentry *target;
1433 if (expandsym(rev, &numrev)) {
1434 target = genrevs(numrev.string, (char*)0, (char*)0,
1435 (char*)0, &gendeltas);
1437 if (!(countnumflds(numrev.string)&1) && cmpnum(target->num,numrev.string))
1438 rcserror("can't lock nonexisting revision %s",
1442 if ((r = addlock(target, false)) < 0 && breaklock(target))
1443 r = addlock(target, true);
1446 diagnose("%s locked\n", target->num);
1458 struct hshentry *target;
1460 int changed = false;
1462 for (p = messagelst; p; p = p->nextmessage)
1464 expandsym(p->revno, &numrev) &&
1466 numrev.string, (char*)0, (char*)0, (char*)0, &gendeltas
1470 * We can't check the old log -- it's much later in the file.
1471 * We pessimistically assume that it changed.
1473 target->log = p->message;
1481 rcs_setstate(rev,status)
1482 char const *rev, *status;
1483 /* Function: Given a revision or branch number, finds the corresponding delta
1484 * and sets its state to status.
1487 struct hshentry *target;
1489 if (expandsym(rev, &numrev)) {
1490 target = genrevs(numrev.string, (char*)0, (char*)0,
1491 (char*)0, &gendeltas);
1493 if (!(countnumflds(numrev.string)&1) && cmpnum(target->num,numrev.string))
1494 rcserror("can't set state of nonexisting revision %s",
1497 else if (strcmp(target->state, status) != 0) {
1498 target->state = status;
1510 buildeltatext(deltas)
1511 struct hshentries const *deltas;
1512 /* Function: put the delta text on frewrite and make necessary */
1513 /* change to delta text */
1515 register FILE *fcut; /* temporary file to rebuild delta tree */
1516 char const *cutname;
1519 cuttail->selector = false;
1520 scanlogtext(deltas->first, false);
1522 cutname = maketemp(3);
1523 if (!(fcut = fopenSafer(cutname, FOPEN_WPLUS_WORK))) {
1527 while (deltas->first != cuthead) {
1528 deltas = deltas->rest;
1529 scanlogtext(deltas->first, true);
1537 while (deltas->first != cuttail)
1538 scanlogtext((deltas = deltas->rest)->first, true);
1539 finishedit((struct hshentry*)0, (FILE*)0, true);
1543 char const *diffname = maketemp(0);
1544 char const *diffv[6 + !!OPEN_O_BINARY];
1545 char const **diffp = diffv;
1547 *++diffp = DIFFFLAGS;
1549 if (Expand == BINARY_EXPAND)
1550 *++diffp == "--binary";
1553 *++diffp = resultname;
1555 switch (runv(fileno(fcut), diffname, diffv)) {
1556 case DIFF_FAILURE: case DIFF_SUCCESS: break;
1557 default: rcsfaterror("diff failed");
1560 return putdtext(cuttail,diffname,frewrite,true);
1562 return putdtext(cuttail,resultname,frewrite,false);
1569 /* Function: actually removes revisions whose selector field */
1570 /* is false, and rebuilds the linkage of deltas. */
1571 /* asks for reconfirmation if deleting last revision*/
1573 struct hshentry * Delta;
1574 struct branchhead *pt, *pre;
1577 if ( cuthead->next == delstrt )
1578 cuthead->next = cuttail;
1580 pre = pt = cuthead->branches;
1581 while( pt && pt->hsh != delstrt ) {
1583 pt = pt->nextbranch;
1587 else if ( pt == pre )
1588 cuthead->branches = pt->nextbranch;
1590 pre->nextbranch = pt->nextbranch;
1593 if (!cuttail && !quietflag) {
1594 if (!yesorno(false, "Do you really want to delete all revisions? [ny](n): ")) {
1595 rcserror("No revision deleted");
1598 Delta->selector = true;
1599 Delta = Delta->next;
1610 /* This lets us lint everything all at once. */
1612 char const cmdid[] = "";
1614 #define go(p,e) {int p P((int,char**)); void e P((void)); if(*argv)return p(argc,argv);if(*argv[1])e();}
1623 go(identId, identExit);
1624 go(mergeId, mergeExit);
1626 go(rcscleanId, rcscleanExit);
1627 go(rcsdiffId, rdiffExit);
1628 go(rcsmergeId, rmergeExit);
1629 go(rlogId, rlogExit);