summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorJoris Vink <joris@cvs.openbsd.org>2005-10-23 04:07:07 +0000
committerJoris Vink <joris@cvs.openbsd.org>2005-10-23 04:07:07 +0000
commita63d92e86e386815a61d3074fa0feb7c2fd298c6 (patch)
treeffba29457330f210477f90d5b05a61a3e326082c /usr.bin
parent45538afa139c3dd50b9f6851eb2e28419c04d973 (diff)
with recent diff3 support, rcsmerge now works;
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/rcs/Makefile7
-rw-r--r--usr.bin/rcs/rcsmerge.c56
2 files changed, 54 insertions, 9 deletions
diff --git a/usr.bin/rcs/Makefile b/usr.bin/rcs/Makefile
index d1f2828400e..780e082ccab 100644
--- a/usr.bin/rcs/Makefile
+++ b/usr.bin/rcs/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.20 2005/10/22 17:41:13 joris Exp $
+# $OpenBSD: Makefile,v 1.21 2005/10/23 04:07:06 joris Exp $
.PATH: ${.CURDIR}/../cvs
@@ -6,11 +6,12 @@ PROG= rcs
MAN= ci.1 co.1 ident.1 rcs.1 rcsclean.1 rcsdiff.1 rcsmerge.1 rlog.1
SRCS= ci.c co.c ident.c rcsclean.c rcsdiff.c rcsmerge.c rcsprog.c rlog.c \
- buf.c date.y diff.c log.c rcs.c rcsnum.c strtab.c util.c
+ buf.c date.y diff.c diff3.c log.c rcs.c rcsnum.c strtab.c util.c
CPPFLAGS+=-I${.CURDIR}/../cvs -DRCSPROG
LINKS= ${BINDIR}/rcs ${BINDIR}/ci ${BINDIR}/rcs ${BINDIR}/co \
- ${BINDIR}/rcs ${BINDIR}/rcsclean ${BINDIR}/rcs ${BINDIR}/rcsdiff
+ ${BINDIR}/rcs ${BINDIR}/rcsclean ${BINDIR}/rcs ${BINDIR}/rcsdiff \
+ ${BINDIR}/rcs ${BINDIR}/rcsmerge
#MLINKS= rcs.1 ci.1 rcs.1 co.1 rcs.1 rcsclean.1 rcs.1 rcsdiff.1
CFLAGS+= -Wall
diff --git a/usr.bin/rcs/rcsmerge.c b/usr.bin/rcs/rcsmerge.c
index edcb09e9b5b..d1f5e38b072 100644
--- a/usr.bin/rcs/rcsmerge.c
+++ b/usr.bin/rcs/rcsmerge.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcsmerge.c,v 1.1 2005/10/18 16:16:39 xsa Exp $ */
+/* $OpenBSD: rcsmerge.c,v 1.2 2005/10/23 04:07:06 joris Exp $ */
/*
* Copyright (c) 2005 Xavier Santolaria <xsa@openbsd.org>
* All rights reserved.
@@ -44,13 +44,14 @@ int
rcsmerge_main(int argc, char **argv)
{
int i, ch;
- char fpath[MAXPATHLEN];
+ char *fcont, fpath[MAXPATHLEN];
RCSFILE *file;
- RCSNUM *rev;
+ RCSNUM *baserev, *rev2, *frev;
+ BUF *bp;
- rev = RCS_HEAD_REV;
+ baserev = rev2 = RCS_HEAD_REV;
- while ((ch = rcs_getopt(argc, argv, "k:qr:TV")) != -1) {
+ while ((ch = rcs_getopt(argc, argv, "k:p::qr:TV")) != -1) {
switch (ch) {
case 'k':
kflag = rcs_kflag_get(rcs_optarg);
@@ -61,11 +62,20 @@ rcsmerge_main(int argc, char **argv)
exit(1);
}
break;
+ case 'p':
+ rcs_set_rev(rcs_optarg, &baserev);
+ pipeout = 1;
+ break;
case 'q':
verbose = 0;
break;
case 'r':
- rcs_set_rev(rcs_optarg, &rev);
+ if (baserev == RCS_HEAD_REV)
+ rcs_set_rev(rcs_optarg, &baserev);
+ else if (rev2 == RCS_HEAD_REV)
+ rcs_set_rev(rcs_optarg, &rev2);
+ else
+ cvs_log(LP_WARN, "ignored excessive -r option");
break;
case 'T':
/*
@@ -89,6 +99,12 @@ rcsmerge_main(int argc, char **argv)
exit(1);
}
+ if (baserev == RCS_HEAD_REV) {
+ cvs_log(LP_ERR, "missing base revision");
+ (usage)();
+ exit(1);
+ }
+
for (i = 0; i < argc; i++) {
if (rcs_statfile(argv[i], fpath, sizeof(fpath)) < 0)
continue;
@@ -96,6 +112,34 @@ rcsmerge_main(int argc, char **argv)
if ((file = rcs_open(fpath, RCS_READ)) == NULL)
continue;
+ if (rev2 == RCS_HEAD_REV)
+ frev = file->rf_head;
+ else
+ frev = rev2;
+
+ if ((bp = cvs_diff3(file, argv[i], baserev, frev)) == NULL) {
+ cvs_log(LP_ERR, "failed to merge");
+ rcs_close(file);
+ continue;
+ }
+
+ if (pipeout == 1) {
+ if (cvs_buf_putc(bp, '\0') < 0) {
+ rcs_close(file);
+ continue;
+ }
+
+ fcont = cvs_buf_release(bp);
+ printf("%s", fcont);
+ free(fcont);
+ } else {
+ /* XXX mode */
+ if (cvs_buf_write(bp, argv[i], 0644) < 0)
+ cvs_log(LP_ERR, "failed to write new file");
+
+ cvs_buf_free(bp);
+ }
+
rcs_close(file);
}