1 /* $NetBSD: rcsmerge.c,v 1.1.1.2 1996/10/13 21:57:19 veego Exp $ */
3 /* Merge RCS revisions. */
5 /* Copyright 1982, 1988, 1989 Walter Tichy
6 Copyright 1990, 1991, 1992, 1993, 1994, 1995 Paul Eggert
7 Distributed under license by the Free Software Foundation, Inc.
9 This file is part of RCS.
11 RCS is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2, or (at your option)
16 RCS is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with RCS; see the file COPYING.
23 If not, write to the Free Software Foundation,
24 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 Report problems and direct all questions to:
28 rcs-bugs@cs.purdue.edu
33 * $Log: rcsmerge.c,v $
34 * Revision 5.15 1995/06/16 06:19:24 eggert
37 * Revision 5.14 1995/06/01 16:23:43 eggert
38 * (main): Report an error if -kb, so don't worry about binary stdout.
39 * Punctuate messages properly. Rewrite to avoid `goto end'.
41 * Revision 5.13 1994/03/17 14:05:48 eggert
42 * Specify subprocess input via file descriptor, not file name. Remove lint.
44 * Revision 5.12 1993/11/09 17:40:15 eggert
45 * -V now prints version on stdout and exits. Don't print usage twice.
47 * Revision 5.11 1993/11/03 17:42:27 eggert
48 * Add -A, -E, -e, -z. Ignore -T. Allow up to three file labels.
49 * Pass -Vn to `co'. Pass unexpanded revision name to `co', so that Name works.
51 * Revision 5.10 1992/07/28 16:12:44 eggert
54 * Revision 5.9 1992/01/24 18:44:19 eggert
57 * Revision 5.8 1992/01/06 02:42:34 eggert
58 * Update usage string.
60 * Revision 5.7 1991/11/20 17:58:09 eggert
61 * Don't Iopen(f, "r+"); it's not portable.
63 * Revision 5.6 1991/08/19 03:13:55 eggert
66 * Revision 5.5 1991/04/21 11:58:27 eggert
67 * Add -x, RCSINIT, MS-DOS support.
69 * Revision 5.4 1991/02/25 07:12:43 eggert
70 * Merging a revision to itself is no longer an error.
72 * Revision 5.3 1990/11/01 05:03:50 eggert
73 * Remove unneeded setid check.
75 * Revision 5.2 1990/09/04 08:02:28 eggert
76 * Check for I/O error when reading working file.
78 * Revision 5.1 1990/08/29 07:14:04 eggert
79 * Add -q. Pass -L options to merge.
81 * Revision 5.0 1990/08/22 08:13:41 eggert
82 * Propagate merge's exit status.
83 * Remove compile-time limits; use malloc instead.
84 * Make lock and temp files faster and safer. Ansify and Posixate. Add -V.
85 * Don't use access(). Tune.
87 * Revision 4.5 89/05/01 15:13:16 narten
88 * changed copyright header to reflect current distribution rules
90 * Revision 4.4 88/08/09 19:13:13 eggert
91 * Beware merging into a readonly file.
92 * Beware merging a revision to itself (no change).
93 * Use execv(), not system(); yield exit status like diff(1)'s.
95 * Revision 4.3 87/10/18 10:38:02 narten
96 * Updating version numbers. Changes relative to version 1.1
97 * actually relative to 4.1
99 * Revision 1.3 87/09/24 14:00:31 narten
100 * Sources now pass through lint (if you ignore printf/sprintf/fprintf
103 * Revision 1.2 87/03/27 14:22:36 jenkins
106 * Revision 4.1 83/03/28 11:14:57 wft
107 * Added handling of default branch.
109 * Revision 3.3 82/12/24 15:29:00 wft
110 * Added call to catchsig().
112 * Revision 3.2 82/12/10 21:32:02 wft
113 * Replaced getdelta() with gettree(); improved error messages.
115 * Revision 3.1 82/11/28 19:27:44 wft
121 static char const co
[] = CO
;
123 mainProg(rcsmergeId
, "rcsmerge", "Id: rcsmerge.c,v 5.15 1995/06/16 06:19:24 eggert Exp")
125 static char const cmdusage
[] =
126 "\nrcsmerge usage: rcsmerge -rrev1 [-rrev2] -ksubst -{pq}[rev] -Vn -xsuff -zzone file";
127 static char const quietarg
[] = "-q";
132 char const *rev
[3], *xrev
[3]; /*revision numbers*/
133 char const *edarg
, *expandarg
, *suffixarg
, *versionarg
, *zonearg
;
138 struct buf numericrev
; /* holds expanded revision number */
139 struct hshentries
*gendeltas
; /* deltas to be generated */
140 struct hshentry
* target
;
142 bufautobegin(&commarg
);
143 bufautobegin(&numericrev
);
144 edarg
= rev
[1] = rev
[2] = 0;
145 status
= 0; /* Keep lint happy. */
147 expandarg
= suffixarg
= versionarg
= zonearg
= quietarg
; /* no-op */
148 suffixes
= X_DEFAULT
;
150 argc
= getRCSINIT(argc
, argv
, &newargv
);
152 while (a
= *++argv
, 0<--argc
&& *a
++=='-') {
170 error("too many revision numbers");
173 case 'A': case 'E': case 'e':
188 /* Ignore -T, so that RCSINIT can contain -T. */
194 setRCSversion(versionarg
);
199 if (0 <= str2expmode(expandarg
+2))
204 error("unknown option: %s%s", *argv
, cmdusage
);
206 } /* end of option processing */
208 if (!rev
[1]) faterror("no base revision number given");
210 /* Now handle all pathnames. */
214 faterror("no input file%s", cmdusage
);
215 if (0 < pairnames(argc
, argv
, rcsreadopen
, true, false)) {
217 if (argc
>2 || (argc
==2 && argv
[1]))
218 warn("excess arguments ignored");
219 if (Expand
== BINARY_EXPAND
)
220 workerror("merging binary files");
221 diagnose("RCS file: %s\n", RCSname
);
222 if (!(workptr
= Iopen(workname
, FOPEN_R_WORK
, (struct stat
*)0)))
225 gettree(); /* reads in the delta tree */
227 if (!Head
) rcsfaterror("no revisions present");
230 rev
[1] = Dbranch
? Dbranch
: Head
->num
;
231 if (fexpandsym(rev
[1], &numericrev
, workptr
)
232 && (target
=genrevs(numericrev
.string
, (char *)0, (char *)0, (char*)0, &gendeltas
))
234 xrev
[1] = target
->num
;
235 if (!rev
[2] || !*rev
[2])
236 rev
[2] = Dbranch
? Dbranch
: Head
->num
;
237 if (fexpandsym(rev
[2], &numericrev
, workptr
)
238 && (target
=genrevs(numericrev
.string
, (char *)0, (char *)0, (char *)0, &gendeltas
))
240 xrev
[2] = target
->num
;
242 if (strcmp(xrev
[1],xrev
[2]) == 0) {
244 fastcopy(workptr
, stdout
);
250 for (i
=1; i
<=2; i
++) {
251 diagnose("retrieving revision %s\n", xrev
[i
]);
252 bufscpy(&commarg
, "-p");
253 bufscat(&commarg
, rev
[i
]); /* not xrev[i], for $Name's sake */
256 /* Do not collide with merger.c maketemp(). */
257 arg
[i
] = maketemp(i
+2),
258 co
, quietarg
, commarg
.string
,
259 expandarg
, suffixarg
, versionarg
, zonearg
,
262 rcsfaterror("co failed");
264 diagnose("Merging differences between %s and %s into %s%s\n",
265 xrev
[1], xrev
[2], workname
,
266 tostdout
?"; result to stdout":"");
268 arg
[0] = xrev
[0] = workname
;
269 status
= merge(tostdout
, edarg
, xrev
, arg
);
278 exitmain(nerror
? DIFF_TROUBLE
: status
);
282 # define exiterr rmergeExit