summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiall O'Higgins <niallo@cvs.openbsd.org>2005-10-07 23:59:57 +0000
committerNiall O'Higgins <niallo@cvs.openbsd.org>2005-10-07 23:59:57 +0000
commit8c14afd804dddf81413f508ee62036600588f087 (patch)
tree6b5287ade3624027cc3ab4d319789beb5bb2e865
parent729e2be54438175b4e009f5657af93614a328875 (diff)
basic `ci' support is here! more coming soon.
combined effort with joris. ok joris@
-rw-r--r--usr.bin/cvs/diff.c157
-rw-r--r--usr.bin/cvs/diff.h5
-rw-r--r--usr.bin/cvs/rcs.c51
-rw-r--r--usr.bin/cvs/rcs.h3
-rw-r--r--usr.bin/rcs/ci.c161
-rw-r--r--usr.bin/rcs/rcsclean.c4
-rw-r--r--usr.bin/rcs/rcsdiff.c6
-rw-r--r--usr.bin/rcs/rlog.c4
8 files changed, 270 insertions, 121 deletions
diff --git a/usr.bin/cvs/diff.c b/usr.bin/cvs/diff.c
index b305b57c17c..33ecb88e15a 100644
--- a/usr.bin/cvs/diff.c
+++ b/usr.bin/cvs/diff.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: diff.c,v 1.57 2005/10/07 21:47:32 reyk Exp $ */
+/* $OpenBSD: diff.c,v 1.58 2005/10/07 23:59:56 niallo Exp $ */
/*
* Copyright (C) Caldera International Inc. 2001-2002.
* All rights reserved.
@@ -159,7 +159,7 @@ struct line {
} *file[2];
/*
- * The following struct is used to record change information when
+ * The following struct is used to record change in formation when
* doing a "context" or "unified" diff. (see routine "change" to
* understand the highly mnemonic field names)
*/
@@ -185,6 +185,7 @@ static int cvs_diff_pre_exec(struct cvsroot *);
static int cvs_diff_cleanup(void);
#endif
+static void diff_output(const char *, ...);
static void output(const char *, FILE *, const char *, FILE *);
static void check(FILE *, FILE *);
static void range(int, int, char *);
@@ -219,7 +220,7 @@ static char diffargs[128];
#endif
static int aflag, bflag, dflag, iflag, pflag, tflag, Tflag, wflag;
static int context;
-static int format = D_NORMAL;
+int diff_format = D_NORMAL;
static struct stat stb1, stb2;
static char *ifdefname, *ignore_pats;
static const char *diff_file;
@@ -249,6 +250,8 @@ static struct context_vec *context_vec_ptr;
static char lastbuf[FUNCTION_CONTEXT_SIZE];
static int lastline;
static int lastmatchline;
+static BUF *diffbuf = NULL;
+
/*
* chrtran points to one of 2 translation tables: cup2low if folding upper to
* lower case clow2low if not folding case
@@ -365,7 +368,7 @@ cvs_diff_init(struct cvs_cmd *cmd, int argc, char **argv, int *arg)
switch (ch) {
case 'c':
strlcat(diffargs, " -c", sizeof(diffargs));
- format = D_CONTEXT;
+ diff_format = D_CONTEXT;
break;
case 'D':
if (dap->date1 == NULL && dap->rev1 == NULL) {
@@ -393,7 +396,7 @@ cvs_diff_init(struct cvs_cmd *cmd, int argc, char **argv, int *arg)
break;
case 'n':
strlcat(diffargs, " -n", sizeof(diffargs));
- format = D_RCSDIFF;
+ diff_format = D_RCSDIFF;
break;
case 'p':
strlcat(diffargs, " -p", sizeof(diffargs));
@@ -417,7 +420,7 @@ cvs_diff_init(struct cvs_cmd *cmd, int argc, char **argv, int *arg)
break;
case 'u':
strlcat(diffargs, " -u", sizeof(diffargs));
- format = D_UNIFIED;
+ diff_format = D_UNIFIED;
break;
default:
return (CVS_EX_USAGE);
@@ -452,10 +455,10 @@ cvs_diff_pre_exec(struct cvsroot *root)
if (pflag && (cvs_sendarg(root, "-p", 0) < 0))
return (CVS_EX_PROTO);
- if (format == D_CONTEXT) {
+ if (diff_format == D_CONTEXT) {
if (cvs_sendarg(root, "-c", 0) < 0)
return (CVS_EX_PROTO);
- } else if (format == D_UNIFIED) {
+ } else if (diff_format == D_UNIFIED) {
if (cvs_sendarg(root, "-u", 0) < 0)
return (CVS_EX_PROTO);
}
@@ -669,7 +672,7 @@ cvs_diff_local(CVSFILE *cf, void *arg)
}
cvs_buf_free(b2);
- cvs_diffreg(path_tmp1, path_tmp2);
+ cvs_diffreg(path_tmp1, path_tmp2, NULL);
(void)unlink(path_tmp1);
(void)unlink(path_tmp2);
@@ -679,7 +682,7 @@ cvs_diff_local(CVSFILE *cf, void *arg)
int
-cvs_diffreg(const char *file1, const char *file2)
+cvs_diffreg(const char *file1, const char *file2, BUF *out)
{
FILE *f1, *f2;
int i, rval;
@@ -692,6 +695,8 @@ cvs_diffreg(const char *file1, const char *file2)
lastmatchline = 0;
context_vec_ptr = context_vec_start - 1;
chrtran = (iflag ? cup2low : clow2low);
+ if (out != NULL)
+ diffbuf = out;
f1 = fopen(file1, "r");
if (f1 == NULL) {
@@ -1238,19 +1243,19 @@ output(const char *file1, FILE *f1, const char *file2, FILE *f2)
}
if (m == 0)
change(file1, f1, file2, f2, 1, 0, 1, diff_len[1]);
- if (format == D_IFDEF) {
+ if (diff_format == D_IFDEF) {
for (;;) {
#define c i0
if ((c = getc(f1)) == EOF)
return;
- cvs_putchar(c);
+ diff_output("%c", c);
}
#undef c
}
if (anychange != 0) {
- if (format == D_CONTEXT)
+ if (diff_format == D_CONTEXT)
dump_context_vec(f1, f2);
- else if (format == D_UNIFIED)
+ else if (diff_format == D_UNIFIED)
dump_unified_vec(f1, f2);
}
}
@@ -1258,20 +1263,20 @@ output(const char *file1, FILE *f1, const char *file2, FILE *f2)
static __inline void
range(int a, int b, char *separator)
{
- cvs_printf("%d", a > b ? b : a);
+ diff_output("%d", a > b ? b : a);
if (a < b)
- cvs_printf("%s%d", separator, b);
+ diff_output("%s%d", separator, b);
}
static __inline void
uni_range(int a, int b)
{
if (a < b)
- cvs_printf("%d,%d", a, b - a + 1);
+ diff_output("%d,%d", a, b - a + 1);
else if (a == b)
- cvs_printf("%d", b);
+ diff_output("%d", b);
else
- cvs_printf("%d,0", b);
+ diff_output("%d,0", b);
}
static char *
@@ -1317,7 +1322,7 @@ change(const char *file1, FILE *f1, const char *file2, FILE *f2,
static size_t max_context = 64;
int i;
- if (format != D_IFDEF && a > b && c > d)
+ if (diff_format != D_IFDEF && a > b && c > d)
return;
if (ignore_pats != NULL) {
char *line;
@@ -1345,7 +1350,7 @@ change(const char *file1, FILE *f1, const char *file2, FILE *f2,
return;
}
proceed:
- if (format == D_CONTEXT || format == D_UNIFIED) {
+ if (diff_format == D_CONTEXT || diff_format == D_UNIFIED) {
/*
* Allocate change records as needed.
*/
@@ -1369,11 +1374,11 @@ proceed:
/*
* Print the context/unidiff header first time through.
*/
- cvs_printf("%s %s %s",
- format == D_CONTEXT ? "***" : "---", diff_file,
+ diff_output("%s %s %s",
+ diff_format == D_CONTEXT ? "***" : "---", diff_file,
ctime(&stb1.st_mtime));
- cvs_printf("%s %s %s",
- format == D_CONTEXT ? "---" : "+++", diff_file,
+ diff_output("%s %s %s",
+ diff_format == D_CONTEXT ? "---" : "+++", diff_file,
ctime(&stb2.st_mtime));
anychange = 1;
} else if (a > context_vec_ptr->b + (2 * context) + 1 &&
@@ -1382,7 +1387,7 @@ proceed:
* If this change is more than 'context' lines from the
* previous change, dump the record and reset it.
*/
- if (format == D_CONTEXT)
+ if (diff_format == D_CONTEXT)
dump_context_vec(f1, f2);
else
dump_unified_vec(f1, f2);
@@ -1396,35 +1401,35 @@ proceed:
}
if (anychange == 0)
anychange = 1;
- switch (format) {
+ switch (diff_format) {
case D_BRIEF:
return;
case D_NORMAL:
range(a, b, ",");
- cvs_putchar(a > b ? 'a' : c > d ? 'd' : 'c');
- if (format == D_NORMAL)
+ diff_output("%c", a > b ? 'a' : c > d ? 'd' : 'c');
+ if (diff_format == D_NORMAL)
range(c, d, ",");
- cvs_putchar('\n');
+ diff_output("\n");
break;
case D_RCSDIFF:
if (a > b)
- cvs_printf("a%d %d\n", b, d - c + 1);
+ diff_output("a%d %d\n", b, d - c + 1);
else {
- cvs_printf("d%d %d\n", a, b - a + 1);
+ diff_output("d%d %d\n", a, b - a + 1);
if (!(c > d)) /* add changed lines */
- cvs_printf("a%d %d\n", b, d - c + 1);
+ diff_output("a%d %d\n", b, d - c + 1);
}
break;
}
- if (format == D_NORMAL || format == D_IFDEF) {
+ if (diff_format == D_NORMAL || diff_format == D_IFDEF) {
fetch(ixold, a, b, f1, '<', 1);
- if (a <= b && c <= d && format == D_NORMAL)
- puts("---");
+ if (a <= b && c <= d && diff_format == D_NORMAL)
+ diff_output("---");
}
- i = fetch(ixnew, c, d, f2, format == D_NORMAL ? '>' : '\0', 0);
+ i = fetch(ixnew, c, d, f2, diff_format == D_NORMAL ? '>' : '\0', 0);
if (inifdef) {
- cvs_printf("#endif /* %s */\n", ifdefname);
+ diff_output("#endif /* %s */\n", ifdefname);
inifdef = 0;
}
}
@@ -1438,53 +1443,53 @@ fetch(long *f, int a, int b, FILE *lb, int ch, int oldfile)
* When doing #ifdef's, copy down to current line
* if this is the first file, so that stuff makes it to output.
*/
- if (format == D_IFDEF && oldfile) {
+ if (diff_format == D_IFDEF && oldfile) {
long curpos = ftell(lb);
/* print through if append (a>b), else to (nb: 0 vs 1 orig) */
nc = f[a > b ? b : a - 1] - curpos;
for (i = 0; i < nc; i++)
- cvs_putchar(getc(lb));
+ diff_output("%c", getc(lb));
}
if (a > b)
return (0);
- if (format == D_IFDEF) {
+ if (diff_format == D_IFDEF) {
if (inifdef) {
- cvs_printf("#else /* %s%s */\n",
+ diff_output("#else /* %s%s */\n",
oldfile == 1 ? "!" : "", ifdefname);
} else {
if (oldfile)
- cvs_printf("#ifndef %s\n", ifdefname);
+ diff_output("#ifndef %s\n", ifdefname);
else
- cvs_printf("#ifdef %s\n", ifdefname);
+ diff_output("#ifdef %s\n", ifdefname);
}
inifdef = 1 + oldfile;
}
for (i = a; i <= b; i++) {
fseek(lb, f[i - 1], SEEK_SET);
nc = f[i] - f[i - 1];
- if (format != D_IFDEF && ch != '\0') {
- cvs_putchar(ch);
- if (Tflag && (format == D_NORMAL || format == D_CONTEXT
- || format == D_UNIFIED))
- cvs_putchar('\t');
- else if (format != D_UNIFIED)
- cvs_putchar(' ');
+ if (diff_format != D_IFDEF && ch != '\0') {
+ diff_output("%c", ch);
+ if (Tflag && (diff_format == D_NORMAL || diff_format == D_CONTEXT
+ || diff_format == D_UNIFIED))
+ diff_output("\t");
+ else if (diff_format != D_UNIFIED)
+ diff_output(" ");
}
col = 0;
for (j = 0, lastc = '\0'; j < nc; j++, lastc = c) {
if ((c = getc(lb)) == EOF) {
- if (format == D_RCSDIFF)
+ if (diff_format == D_RCSDIFF)
warnx("No newline at end of file");
else
- puts("\n\\ No newline at end of file");
+ diff_output("\n\\ No newline at end of file");
return (0);
}
if (c == '\t' && tflag) {
do {
- cvs_putchar(' ');
+ diff_output(" ");
} while (++col & 7);
} else {
- cvs_putchar(c);
+ diff_output("%c", c);
col++;
}
}
@@ -1622,17 +1627,17 @@ dump_context_vec(FILE *f1, FILE *f2)
lowc = MAX(1, cvp->c - context);
upd = MIN(diff_len[1], context_vec_ptr->d + context);
- cvs_printf("***************");
+ diff_output("***************");
if (pflag) {
f = match_function(ixold, lowa - 1, f1);
if (f != NULL) {
- cvs_putchar(' ');
- cvs_printf("%s", f);
+ diff_output(" ");
+ diff_output("%s", f);
}
}
- cvs_printf("\n*** ");
+ diff_output("\n*** ");
range(lowa, upb, ",");
- cvs_printf(" ****\n");
+ diff_output(" ****\n");
/*
* Output changes to the "old" file. The first loop suppresses
@@ -1671,9 +1676,9 @@ dump_context_vec(FILE *f1, FILE *f2)
fetch(ixold, b + 1, upb, f1, ' ', 0);
}
/* output changes to the "new" file */
- cvs_printf("--- ");
+ diff_output("--- ");
range(lowc, upd, ",");
- cvs_printf(" ----\n");
+ diff_output(" ----\n");
do_output = 0;
for (cvp = context_vec_start; cvp <= context_vec_ptr; cvp++)
@@ -1727,19 +1732,19 @@ dump_unified_vec(FILE *f1, FILE *f2)
lowc = MAX(1, cvp->c - context);
upd = MIN(diff_len[1], context_vec_ptr->d + context);
- cvs_printf("@@ -");
+ diff_output("@@ -");
uni_range(lowa, upb);
- cvs_printf(" +");
+ diff_output(" +");
uni_range(lowc, upd);
- cvs_printf(" @@");
+ diff_output(" @@");
if (pflag) {
f = match_function(ixold, lowa - 1, f1);
if (f != NULL) {
- cvs_putchar(' ');
- cvs_printf("%s", f);
+ diff_output(" ");
+ diff_output("%s", f);
}
}
- cvs_putchar('\n');
+ diff_output("\n");
/*
* Output changes in "unified" diff format--the old and new lines
@@ -1783,3 +1788,19 @@ dump_unified_vec(FILE *f1, FILE *f2)
context_vec_ptr = context_vec_start - 1;
}
+
+static void
+diff_output(const char *fmt, ...)
+{
+ va_list vap;
+ char *str;
+
+ va_start(vap, fmt);
+ vasprintf(&str, fmt, vap);
+ if (diffbuf != NULL)
+ cvs_buf_append(diffbuf, str, strlen(str));
+ else
+ cvs_printf("%s", str);
+ free(str);
+ va_end(vap);
+}
diff --git a/usr.bin/cvs/diff.h b/usr.bin/cvs/diff.h
index 3702077375b..4400dae9e61 100644
--- a/usr.bin/cvs/diff.h
+++ b/usr.bin/cvs/diff.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: diff.h,v 1.1 2005/10/05 23:11:07 niallo Exp $ */
+/* $OpenBSD: diff.h,v 1.2 2005/10/07 23:59:56 niallo Exp $ */
/*
* Copyright (C) Caldera International Inc. 2001-2002.
* All rights reserved.
@@ -94,5 +94,6 @@
-int cvs_diffreg(const char *, const char *);
+int cvs_diffreg(const char *, const char *, BUF *out);
+extern int diff_format;
#endif
diff --git a/usr.bin/cvs/rcs.c b/usr.bin/cvs/rcs.c
index 430277de907..b7bf27193a7 100644
--- a/usr.bin/cvs/rcs.c
+++ b/usr.bin/cvs/rcs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcs.c,v 1.80 2005/10/07 21:47:32 reyk Exp $ */
+/* $OpenBSD: rcs.c,v 1.81 2005/10/07 23:59:56 niallo Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -38,9 +38,9 @@
#include <string.h>
#include <unistd.h>
-#include "diff.h"
#include "log.h"
#include "rcs.h"
+#include "diff.h"
#include "strtab.h"
#define RCS_BUFSIZE 16384
@@ -1452,23 +1452,9 @@ rcs_rev_add(RCSFILE *rf, RCSNUM *rev, const char *msg, time_t date)
time_t now;
struct passwd *pw;
struct rcs_delta *rdp;
- RCSNUM *tmprev = NULL;
if (rev == RCS_HEAD_REV) {
- const RCSNUM *head_rev;
- char version_str[10];
-
- head_rev = rcs_head_get(rf);
- if ((tmprev = rcsnum_alloc()) == NULL) {
- cvs_log(LP_ERR, "could not allocate rcsnum");
- return (-1);
- }
- if (rcsnum_cpy(head_rev, tmprev, sizeof(version_str)) != 0) {
- cvs_log(LP_ERR, "could not perform rcsnum_cpy");
- rcsnum_free(tmprev);
- return (-1);
- }
- rev = rcsnum_inc(tmprev);
+ rev = rcsnum_inc(rf->rf_head);
} else if ((rdp = rcs_findrev(rf, rev)) != NULL) {
rcs_errno = RCS_ERR_DUPENT;
return (-1);
@@ -1493,8 +1479,6 @@ rcs_rev_add(RCSFILE *rf, RCSNUM *rev, const char *msg, time_t date)
return (-1);
}
rcsnum_cpy(rev, rdp->rd_num, 0);
- if (tmprev != NULL)
- rcsnum_free(tmprev);
if ((rdp->rd_author = cvs_strdup(pw->pw_name)) == NULL) {
rcs_freedelta(rdp);
@@ -1520,6 +1504,7 @@ rcs_rev_add(RCSFILE *rf, RCSNUM *rev, const char *msg, time_t date)
TAILQ_INSERT_HEAD(&(rf->rf_delta), rdp, rd_list);
rf->rf_ndelta++;
+
/* not synced anymore */
rf->rf_flags &= ~RCS_SYNCED;
@@ -2972,3 +2957,31 @@ rcs_expand_keywords(char *rcsfile, struct rcs_delta *rdp, char *line, char *out,
return (0);
}
+
+/*
+ * rcs_deltatext_set()
+ *
+ * Set deltatext for <rev> in RCS file <rfp> to <dtext>
+ * Returns -1 on error, 0 on success.
+ */
+int
+rcs_deltatext_set(RCSFILE *rfp, RCSNUM *rev, const char *dtext)
+{
+ size_t len;
+ struct rcs_delta *rdp;
+
+ if ((rdp = rcs_findrev(rfp, rev)) == NULL)
+ return (-1);
+
+ if (rdp->rd_text != NULL)
+ free(rdp->rd_text);
+
+ len = strlen(dtext);
+ if ((rdp->rd_text = (u_char *)malloc(len)) == NULL)
+ return (-1);
+
+ rdp->rd_tlen = len - 1;
+ strlcpy(rdp->rd_text, dtext, len);
+
+ return (0);
+}
diff --git a/usr.bin/cvs/rcs.h b/usr.bin/cvs/rcs.h
index f46194a6e85..f76e621ac67 100644
--- a/usr.bin/cvs/rcs.h
+++ b/usr.bin/cvs/rcs.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcs.h,v 1.31 2005/08/02 11:48:56 joris Exp $ */
+/* $OpenBSD: rcs.h,v 1.32 2005/10/07 23:59:56 niallo Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -201,6 +201,7 @@ int rcs_lock_setmode(RCSFILE *, int);
int rcs_lock_add(RCSFILE *, const char *, RCSNUM *);
int rcs_lock_remove(RCSFILE *, const RCSNUM *);
BUF *rcs_getrev(RCSFILE *, RCSNUM *);
+int rcs_deltatext_set(RCSFILE *, RCSNUM *, const char *);
const char *rcs_desc_get(RCSFILE *);
int rcs_desc_set(RCSFILE *, const char *);
const char *rcs_comment_lookup(const char *);
diff --git a/usr.bin/rcs/ci.c b/usr.bin/rcs/ci.c
index a294003f412..ceebde0397a 100644
--- a/usr.bin/rcs/ci.c
+++ b/usr.bin/rcs/ci.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ci.c,v 1.3 2005/09/30 17:39:48 joris Exp $ */
+/* $OpenBSD: ci.c,v 1.4 2005/10/07 23:59:56 niallo Exp $ */
/*
* Copyright (c) 2005 Niall O'Higgins <niallo@openbsd.org>
* All rights reserved.
@@ -41,10 +41,13 @@
#include "log.h"
#include "rcs.h"
+#include "diff.h"
#include "rcsprog.h"
extern char *__progname;
+static char * checkin_diff_file(RCSFILE *, RCSNUM *, const char *);
+
void
checkin_usage(void)
{
@@ -81,13 +84,15 @@ checkin_main(int argc, char **argv)
int i, ch, dflag, flags, lkmode;
mode_t fmode;
RCSFILE *file;
+ RCSNUM *frev;
char fpath[MAXPATHLEN];
- char *rcs_msg, *rev;
+ char *rcs_msg, *rev, *filec, *deltatext;
+ BUF *bp;
lkmode = -1;
flags = RCS_RDWR;
file = NULL;
- rev = rcs_msg = NULL;
+ rcs_msg = rev = NULL;
fmode = dflag = 0;
while ((ch = getopt(argc, argv, "j:l:M:N:qu:d:r::m:k:V")) != -1) {
@@ -95,18 +100,12 @@ checkin_main(int argc, char **argv)
case 'h':
(usage)();
exit(0);
- case 'l':
- lkmode = RCS_LOCK_STRICT;
- break;
case 'm':
rcs_msg = optarg;
break;
case 'q':
verbose = 0;
break;
- case 'r':
- rev = optarg;
- break;
case 'V':
printf("%s\n", rcs_version);
exit(0);
@@ -128,31 +127,145 @@ checkin_main(int argc, char **argv)
if (rcs_statfile(argv[i], fpath, sizeof(fpath)) < 0)
continue;
- flags = RCS_RDWR;
- file = rcs_open(fpath, flags, fmode);
+ file = rcs_open(fpath, RCS_RDWR, fmode);
if (file == NULL) {
+ cvs_log(LP_ERR, "failed to open rcsfile '%s'", fpath);
exit(1);
}
+
if (rcs_msg == NULL) {
cvs_log(LP_ERR, "no log message");
exit(1);
}
- if (rev != NULL ) {
- /* XXX */
- } else {
- if (dflag) {
+
+ if (dflag) {
/* XXX */
- } else {
- if (rcs_rev_add(file, RCS_HEAD_REV, rcs_msg, -1)
- != 0) {
- cvs_log(LP_ERR,
- "rcs_rev_add() failure");
- exit(1);
- }
- }
}
+
+ if (rev == NULL)
+ frev = file->rf_head;
+
+ /*
+ * Load file contents
+ */
+ if ((bp = cvs_buf_load(argv[i], BUF_AUTOEXT)) == NULL) {
+ cvs_log(LP_ERR, "failed to load '%s'", argv[i]);
+ exit(1);
+ }
+
+ if (cvs_buf_putc(bp, '\0') < 0)
+ exit(1);
+
+ filec = cvs_buf_release(bp);
+
+ /*
+ * Remove the lock
+ */
+ if (rcs_lock_remove(file, frev) < 0) {
+ if (rcs_errno != RCS_ERR_NOENT)
+ cvs_log(LP_WARN, "failed to remove lock");
+ }
+
+ /*
+ * Get RCS patch
+ */
+ if ((deltatext = checkin_diff_file(file, frev, argv[i])) == NULL) {
+ cvs_log(LP_ERR, "failed to get diff");
+ exit(1);
+ }
+
+ /*
+ * Current head revision gets the RCS patch as rd_text
+ */
+ if (rcs_deltatext_set(file, file->rf_head, deltatext) == -1) {
+ cvs_log(LP_ERR, "failed to set new rd_text for head rev");
+ exit (1);
+ }
+
+ /*
+ * Now add our new revision
+ */
+ if (rcs_rev_add(file, RCS_HEAD_REV, rcs_msg, -1) != 0) {
+ cvs_log(LP_ERR, "failed to add new revision");
+ exit(1);
+ }
+
+ /*
+ * New head revision has to contain entire file;
+ */
+ if (rcs_deltatext_set(file, frev, filec) == -1) {
+ cvs_log(LP_ERR, "failed to set new head revision");
+ exit(1);
+ }
+
+ free(deltatext);
+ free(filec);
+
+ /* File will NOW be synced */
rcs_close(file);
+
+ /* XXX:
+ * Delete the working file - we do not support -u/-l just yet
+ */
+ (void)unlink(argv[i]);
+ }
+
+ return (0);
+}
+
+static char *
+checkin_diff_file(RCSFILE *rfp, RCSNUM *rev, const char *filename)
+{
+ char path1[MAXPATHLEN], path2[MAXPATHLEN];
+ BUF *b1, *b2, *b3;
+ char rbuf[64], *deltatext;
+
+ rcsnum_tostr(rev, rbuf, sizeof(rbuf));
+ if (verbose)
+ printf("retrieving revision %s\n", rbuf);
+
+ if ((b1 = cvs_buf_load(filename, BUF_AUTOEXT)) == NULL) {
+ cvs_log(LP_ERR, "failed to load file: '%s'", filename);
+ return (NULL);
+ }
+
+ if ((b2 = rcs_getrev(rfp, rev)) == NULL) {
+ cvs_log(LP_ERR, "failed to load revision");
+ cvs_buf_free(b1);
+ return (NULL);
}
- exit(0);
+ if ((b3 = cvs_buf_alloc(128, BUF_AUTOEXT)) == NULL) {
+ cvs_log(LP_ERR, "failed to allocated buffer for diff");
+ cvs_buf_free(b1);
+ cvs_buf_free(b2);
+ return (NULL);
+ }
+
+ strlcpy(path1, "/tmp/diff1.XXXXXXXXXX", sizeof(path1));
+ if (cvs_buf_write_stmp(b1, path1, 0600) == -1) {
+ cvs_log(LP_ERRNO, "could not write temporary file");
+ cvs_buf_free(b1);
+ cvs_buf_free(b2);
+ return (NULL);
+ }
+ cvs_buf_free(b1);
+
+ strlcpy(path2, "/tmp/diff2.XXXXXXXXXX", sizeof(path2));
+ if (cvs_buf_write_stmp(b2, path2, 0600) == -1) {
+ cvs_buf_free(b2);
+ (void)unlink(path1);
+ return (NULL);
+ }
+ cvs_buf_free(b2);
+
+ diff_format = D_RCSDIFF;
+ cvs_diffreg(path1, path2, b3);
+ (void)unlink(path1);
+ (void)unlink(path2);
+
+ cvs_buf_putc(b3, '\0');
+ deltatext = (char *)cvs_buf_release(b3);
+
+ return (deltatext);
}
diff --git a/usr.bin/rcs/rcsclean.c b/usr.bin/rcs/rcsclean.c
index 69485e0d019..ba3c4e2a984 100644
--- a/usr.bin/rcs/rcsclean.c
+++ b/usr.bin/rcs/rcsclean.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcsclean.c,v 1.3 2005/10/06 11:46:03 joris Exp $ */
+/* $OpenBSD: rcsclean.c,v 1.4 2005/10/07 23:59:56 niallo Exp $ */
/*
* Copyright (c) 2005 Joris Vink <joris@openbsd.org>
* All rights reserved.
@@ -33,9 +33,9 @@
#include <string.h>
#include <unistd.h>
-#include "diff.h"
#include "log.h"
#include "rcs.h"
+#include "diff.h"
#include "rcsprog.h"
extern char *__progname;
diff --git a/usr.bin/rcs/rcsdiff.c b/usr.bin/rcs/rcsdiff.c
index 067cbb5be4f..4605647d75e 100644
--- a/usr.bin/rcs/rcsdiff.c
+++ b/usr.bin/rcs/rcsdiff.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcsdiff.c,v 1.1 2005/10/06 01:24:25 joris Exp $ */
+/* $OpenBSD: rcsdiff.c,v 1.2 2005/10/07 23:59:56 niallo Exp $ */
/*
* Copyright (c) 2005 Joris Vink <joris@openbsd.org>
* All rights reserved.
@@ -32,9 +32,9 @@
#include <string.h>
#include <unistd.h>
-#include "diff.h"
#include "log.h"
#include "rcs.h"
+#include "diff.h"
#include "rcsprog.h"
extern char *__progname;
@@ -144,7 +144,7 @@ rcsdiff_file(RCSFILE *rfp, RCSNUM *rev, const char *filename)
}
cvs_buf_free(b2);
- cvs_diffreg(path1, path2);
+ cvs_diffreg(path1, path2, NULL);
(void)unlink(path1);
(void)unlink(path2);
diff --git a/usr.bin/rcs/rlog.c b/usr.bin/rcs/rlog.c
index ef1c5f4bff0..7d9e88fecc0 100644
--- a/usr.bin/rcs/rlog.c
+++ b/usr.bin/rcs/rlog.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rlog.c,v 1.2 2005/10/06 13:36:53 niallo Exp $ */
+/* $OpenBSD: rlog.c,v 1.3 2005/10/07 23:59:56 niallo Exp $ */
/*
* Copyright (c) 2005 Joris Vink <joris@openbsd.org>
* All rights reserved.
@@ -33,9 +33,9 @@
#include <string.h>
#include <unistd.h>
-#include "diff.h"
#include "log.h"
#include "rcs.h"
+#include "diff.h"
#include "rcsprog.h"
extern char *__progname;