Annotation of src/usr.bin/rcs/rcsmerge.c, Revision 1.13
1.13 ! xsa 1: /* $OpenBSD: rcsmerge.c,v 1.12 2006/01/02 08:13:28 xsa Exp $ */
1.1 xsa 2: /*
3: * Copyright (c) 2005 Xavier Santolaria <xsa@openbsd.org>
4: * All rights reserved.
5: *
6: * Redistribution and use in source and binary forms, with or without
7: * modification, are permitted provided that the following conditions
8: * are met:
9: *
10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
12: * 2. The name of the author may not be used to endorse or promote products
13: * derived from this software without specific prior written permission.
14: *
15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16: * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17: * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18: * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25: */
26:
1.12 xsa 27: #include "includes.h"
1.1 xsa 28:
1.13 ! xsa 29: #include "rcsprog.h"
1.1 xsa 30: #include "diff.h"
31:
32: static int kflag = RCS_KWEXP_ERR;
33:
34: int
35: rcsmerge_main(int argc, char **argv)
36: {
37: int i, ch;
1.2 joris 38: char *fcont, fpath[MAXPATHLEN];
1.1 xsa 39: RCSFILE *file;
1.2 joris 40: RCSNUM *baserev, *rev2, *frev;
41: BUF *bp;
1.1 xsa 42:
1.2 joris 43: baserev = rev2 = RCS_HEAD_REV;
1.1 xsa 44:
1.9 xsa 45: while ((ch = rcs_getopt(argc, argv, "k:p::q::r:TVx:")) != -1) {
1.1 xsa 46: switch (ch) {
47: case 'k':
48: kflag = rcs_kflag_get(rcs_optarg);
49: if (RCS_KWEXP_INVAL(kflag)) {
50: cvs_log(LP_ERR,
51: "invalid RCS keyword expansion mode");
52: (usage)();
53: exit(1);
54: }
55: break;
1.2 joris 56: case 'p':
57: rcs_set_rev(rcs_optarg, &baserev);
58: pipeout = 1;
59: break;
1.1 xsa 60: case 'q':
1.7 xsa 61: rcs_set_rev(rcs_optarg, &baserev);
1.1 xsa 62: verbose = 0;
63: break;
64: case 'r':
1.2 joris 65: if (baserev == RCS_HEAD_REV)
66: rcs_set_rev(rcs_optarg, &baserev);
67: else if (rev2 == RCS_HEAD_REV)
68: rcs_set_rev(rcs_optarg, &rev2);
69: else
70: cvs_log(LP_WARN, "ignored excessive -r option");
1.1 xsa 71: break;
72: case 'T':
73: /*
74: * kept for compatibility
75: */
76: break;
77: case 'V':
78: printf("%s\n", rcs_version);
79: exit(0);
1.9 xsa 80: case 'x':
81: rcs_suffixes = rcs_optarg;
82: break;
1.1 xsa 83: default:
84: break;
85: }
86: }
87:
88: argc -= rcs_optind;
89: argv += rcs_optind;
90:
91: if (argc < 0) {
92: cvs_log(LP_ERR, "no input file");
93: (usage)();
94: exit(1);
95: }
96:
1.2 joris 97: if (baserev == RCS_HEAD_REV) {
1.4 xsa 98: cvs_log(LP_ERR, "no base revision number given");
1.2 joris 99: (usage)();
100: exit(1);
101: }
102:
1.1 xsa 103: for (i = 0; i < argc; i++) {
104: if (rcs_statfile(argv[i], fpath, sizeof(fpath)) < 0)
105: continue;
106:
107: if ((file = rcs_open(fpath, RCS_READ)) == NULL)
108: continue;
1.2 joris 109:
110: if (rev2 == RCS_HEAD_REV)
111: frev = file->rf_head;
112: else
113: frev = rev2;
1.8 xsa 114:
115: printf("RCS file: %s\n", fpath);
1.2 joris 116:
117: if ((bp = cvs_diff3(file, argv[i], baserev, frev)) == NULL) {
118: cvs_log(LP_ERR, "failed to merge");
119: rcs_close(file);
120: continue;
121: }
122:
123: if (pipeout == 1) {
124: if (cvs_buf_putc(bp, '\0') < 0) {
125: rcs_close(file);
126: continue;
127: }
128:
129: fcont = cvs_buf_release(bp);
130: printf("%s", fcont);
1.11 joris 131: xfree(fcont);
1.2 joris 132: } else {
133: /* XXX mode */
134: if (cvs_buf_write(bp, argv[i], 0644) < 0)
135: cvs_log(LP_ERR, "failed to write new file");
136:
137: cvs_buf_free(bp);
1.3 joris 138: }
139:
140: if (diff3_conflicts > 0) {
141: cvs_log(LP_WARN, "%d conflict%s found during merge",
142: diff3_conflicts, (diff3_conflicts > 1) ? "s": "");
1.2 joris 143: }
1.1 xsa 144:
145: rcs_close(file);
146: }
147:
148: return (0);
149: }
150:
151: void
152: rcsmerge_usage(void)
153: {
154: fprintf(stderr,
1.7 xsa 155: "usage: rcsmerge [-TV] [-kmode] [-p[rev]] [-q[rev]] "
1.10 xsa 156: "[-rrev] [-xsuffixes] file ...\n");
1.1 xsa 157: }