1 /* Merge RCS revisions. */
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.15 1995/06/16 06:19:24 eggert
34 * Revision 5.14 1995/06/01 16:23:43 eggert
35 * (main): Report an error if -kb, so don't worry about binary stdout.
36 * Punctuate messages properly. Rewrite to avoid `goto end'.
38 * Revision 5.13 1994/03/17 14:05:48 eggert
39 * Specify subprocess input via file descriptor, not file name. Remove lint.
41 * Revision 5.12 1993/11/09 17:40:15 eggert
42 * -V now prints version on stdout and exits. Don't print usage twice.
44 * Revision 5.11 1993/11/03 17:42:27 eggert
45 * Add -A, -E, -e, -z. Ignore -T. Allow up to three file labels.
46 * Pass -Vn to `co'. Pass unexpanded revision name to `co', so that Name works.
48 * Revision 5.10 1992/07/28 16:12:44 eggert
51 * Revision 5.9 1992/01/24 18:44:19 eggert
54 * Revision 5.8 1992/01/06 02:42:34 eggert
55 * Update usage string.
57 * Revision 5.7 1991/11/20 17:58:09 eggert
58 * Don't Iopen(f, "r+"); it's not portable.
60 * Revision 5.6 1991/08/19 03:13:55 eggert
63 * Revision 5.5 1991/04/21 11:58:27 eggert
64 * Add -x, RCSINIT, MS-DOS support.
66 * Revision 5.4 1991/02/25 07:12:43 eggert
67 * Merging a revision to itself is no longer an error.
69 * Revision 5.3 1990/11/01 05:03:50 eggert
70 * Remove unneeded setid check.
72 * Revision 5.2 1990/09/04 08:02:28 eggert
73 * Check for I/O error when reading working file.
75 * Revision 5.1 1990/08/29 07:14:04 eggert
76 * Add -q. Pass -L options to merge.
78 * Revision 5.0 1990/08/22 08:13:41 eggert
79 * Propagate merge's exit status.
80 * Remove compile-time limits; use malloc instead.
81 * Make lock and temp files faster and safer. Ansify and Posixate. Add -V.
82 * Don't use access(). Tune.
84 * Revision 4.5 89/05/01 15:13:16 narten
85 * changed copyright header to reflect current distribution rules
87 * Revision 4.4 88/08/09 19:13:13 eggert
88 * Beware merging into a readonly file.
89 * Beware merging a revision to itself (no change).
90 * Use execv(), not system(); yield exit status like diff(1)'s.
92 * Revision 4.3 87/10/18 10:38:02 narten
93 * Updating version numbers. Changes relative to version 1.1
94 * actually relative to 4.1
96 * Revision 1.3 87/09/24 14:00:31 narten
97 * Sources now pass through lint (if you ignore printf/sprintf/fprintf
100 * Revision 1.2 87/03/27 14:22:36 jenkins
103 * Revision 4.1 83/03/28 11:14:57 wft
104 * Added handling of default branch.
106 * Revision 3.3 82/12/24 15:29:00 wft
107 * Added call to catchsig().
109 * Revision 3.2 82/12/10 21:32:02 wft
110 * Replaced getdelta() with gettree(); improved error messages.
112 * Revision 3.1 82/11/28 19:27:44 wft
118 static char const co[] = CO;
120 mainProg(rcsmergeId, "rcsmerge", "$FreeBSD$")
122 static char const cmdusage[] =
123 "\nrcsmerge usage: rcsmerge -rrev1 [-rrev2] -ksubst -{pq}[rev] -Vn -xsuff -zzone file";
124 static char const quietarg[] = "-q";
129 char const *rev[3], *xrev[3]; /*revision numbers*/
130 char const *edarg, *expandarg, *suffixarg, *versionarg, *zonearg;
135 struct buf numericrev; /* holds expanded revision number */
136 struct hshentries *gendeltas; /* deltas to be generated */
137 struct hshentry * target;
139 bufautobegin(&commarg);
140 bufautobegin(&numericrev);
141 edarg = rev[1] = rev[2] = 0;
142 status = 0; /* Keep lint happy. */
144 expandarg = suffixarg = versionarg = zonearg = quietarg; /* no-op */
145 suffixes = X_DEFAULT;
147 argc = getRCSINIT(argc, argv, &newargv);
149 while (a = *++argv, 0<--argc && *a++=='-') {
167 error("too many revision numbers");
170 case 'A': case 'E': case 'e':
185 /* Ignore -T, so that RCSINIT can contain -T. */
191 setRCSversion(versionarg);
196 if (0 <= str2expmode(expandarg+2))
201 error("unknown option: %s%s", *argv, cmdusage);
203 } /* end of option processing */
205 if (!rev[1]) faterror("no base revision number given");
207 /* Now handle all pathnames. */
211 faterror("no input file%s", cmdusage);
212 if (0 < pairnames(argc, argv, rcsreadopen, true, false)) {
214 if (argc>2 || (argc==2 && argv[1]))
215 warn("excess arguments ignored");
216 if (Expand == BINARY_EXPAND)
217 workerror("merging binary files");
218 diagnose("RCS file: %s\n", RCSname);
219 if (!(workptr = Iopen(workname, FOPEN_R_WORK, (struct stat*)0)))
222 gettree(); /* reads in the delta tree */
224 if (!Head) rcsfaterror("no revisions present");
227 rev[1] = Dbranch ? Dbranch : Head->num;
228 if (fexpandsym(rev[1], &numericrev, workptr)
229 && (target=genrevs(numericrev.string, (char *)0, (char *)0, (char*)0, &gendeltas))
231 xrev[1] = target->num;
232 if (!rev[2] || !*rev[2])
233 rev[2] = Dbranch ? Dbranch : Head->num;
234 if (fexpandsym(rev[2], &numericrev, workptr)
235 && (target=genrevs(numericrev.string, (char *)0, (char *)0, (char *)0, &gendeltas))
237 xrev[2] = target->num;
239 if (strcmp(xrev[1],xrev[2]) == 0) {
241 fastcopy(workptr, stdout);
247 for (i=1; i<=2; i++) {
248 diagnose("retrieving revision %s\n", xrev[i]);
249 bufscpy(&commarg, "-p");
250 bufscat(&commarg, rev[i]); /* not xrev[i], for $Name's sake */
253 /* Do not collide with merger.c maketemp(). */
254 arg[i] = maketemp(i+2),
255 co, quietarg, commarg.string,
256 expandarg, suffixarg, versionarg, zonearg,
259 rcsfaterror("co failed");
261 diagnose("Merging differences between %s and %s into %s%s\n",
262 xrev[1], xrev[2], workname,
263 tostdout?"; result to stdout":"");
265 arg[0] = xrev[0] = workname;
266 status = merge(tostdout, edarg, xrev, arg);
275 exitmain(nerror ? DIFF_TROUBLE : status);
279 # define exiterr rmergeExit