summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2010-07-28 21:19:31 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2010-07-28 21:19:31 +0000
commite3d2d3e6e203081f26c8422b05f95b04468c8e20 (patch)
tree1a0e099763a85c57eaa7228adb1165feb706f8ad
parentd3fe148f190500558e404fcd928ce6c61d6ea1c4 (diff)
Support -U and -C to specify the context length for "cvs diff".
This doesn't alter cvs rdiff, where -U and -C are not support by GNU cvs. ok sthen zinovik
-rw-r--r--usr.bin/cvs/diff.c35
-rw-r--r--usr.bin/cvs/diff.h3
-rw-r--r--usr.bin/cvs/diff_internals.c24
3 files changed, 45 insertions, 17 deletions
diff --git a/usr.bin/cvs/diff.c b/usr.bin/cvs/diff.c
index 4900eda2b32..a9ee2ab448f 100644
--- a/usr.bin/cvs/diff.c
+++ b/usr.bin/cvs/diff.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: diff.c,v 1.157 2010/07/23 21:46:05 ray Exp $ */
+/* $OpenBSD: diff.c,v 1.158 2010/07/28 21:19:30 nicm Exp $ */
/*
* Copyright (c) 2008 Tobias Stoeckmann <tobias@openbsd.org>
* Copyright (c) 2006 Joris Vink <joris@openbsd.org>
@@ -49,7 +49,7 @@ struct cvs_cmd cvs_cmd_diff = {
"Show differences between revisions",
"[-abcdilNnpRuw] [[-D date] [-r rev] [-D date2 | -r rev2]] "
"[-k mode] [file ...]",
- "abcfdD:ik:lNnpr:Ruw",
+ "abcfC:dD:ik:lNnpr:RuU:w",
NULL,
cvs_diff
};
@@ -70,6 +70,7 @@ cvs_diff(int argc, char **argv)
{
int ch, flags;
char *arg = ".";
+ const char *errstr;
struct cvs_recursion cr;
flags = CR_RECURSE_DIRS;
@@ -91,6 +92,14 @@ cvs_diff(int argc, char **argv)
strlcat(diffargs, " -c", sizeof(diffargs));
diff_format = D_CONTEXT;
break;
+ case 'C':
+ diff_context = strtonum(optarg, 0, INT_MAX, &errstr);
+ if (errstr != NULL)
+ fatal("context lines %s: %s", errstr, optarg);
+ strlcat(diffargs, " -C ", sizeof(diffargs));
+ strlcat(diffargs, optarg, sizeof(diffargs));
+ diff_format = D_CONTEXT;
+ break;
case 'd':
strlcat(diffargs, " -d", sizeof(diffargs));
dflags |= D_MINIMAL;
@@ -161,6 +170,14 @@ cvs_diff(int argc, char **argv)
strlcat(diffargs, " -u", sizeof(diffargs));
diff_format = D_UNIFIED;
break;
+ case 'U':
+ diff_context = strtonum(optarg, 0, INT_MAX, &errstr);
+ if (errstr != NULL)
+ fatal("context lines %s: %s", errstr, optarg);
+ strlcat(diffargs, " -U ", sizeof(diffargs));
+ strlcat(diffargs, optarg, sizeof(diffargs));
+ diff_format = D_UNIFIED;
+ break;
case 'V':
fatal("the -V option is obsolete "
"and should not be used");
@@ -209,13 +226,23 @@ cvs_diff(int argc, char **argv)
switch (diff_format) {
case D_CONTEXT:
- cvs_client_send_request("Argument -c");
+ if (cvs_cmdop == CVS_OP_RDIFF)
+ cvs_client_send_request("Argument -c");
+ else {
+ cvs_client_send_request("Argument -C %d",
+ diff_context);
+ }
break;
case D_RCSDIFF:
cvs_client_send_request("Argument -n");
break;
case D_UNIFIED:
- cvs_client_send_request("Argument -u");
+ if (cvs_cmdop == CVS_OP_RDIFF)
+ cvs_client_send_request("Argument -u");
+ else {
+ cvs_client_send_request("Argument -U %d",
+ diff_context);
+ }
break;
default:
break;
diff --git a/usr.bin/cvs/diff.h b/usr.bin/cvs/diff.h
index 16934ca551d..9c297d51967 100644
--- a/usr.bin/cvs/diff.h
+++ b/usr.bin/cvs/diff.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: diff.h,v 1.21 2010/07/23 21:46:05 ray Exp $ */
+/* $OpenBSD: diff.h,v 1.22 2010/07/28 21:19:30 nicm Exp $ */
/*
* Copyright (C) Caldera International Inc. 2001-2002.
* All rights reserved.
@@ -108,6 +108,7 @@ int diffreg(const char *, const char *, int, int, BUF *, int);
int ed_patch_lines(struct rcs_lines *, struct rcs_lines *);
extern int diff_format;
+extern int diff_context;
extern int diff3_conflicts;
extern int diff_aflag;
extern int diff_bflag;
diff --git a/usr.bin/cvs/diff_internals.c b/usr.bin/cvs/diff_internals.c
index 7c83f745865..e7b0e8c455f 100644
--- a/usr.bin/cvs/diff_internals.c
+++ b/usr.bin/cvs/diff_internals.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: diff_internals.c,v 1.32 2010/07/23 21:46:05 ray Exp $ */
+/* $OpenBSD: diff_internals.c,v 1.33 2010/07/28 21:19:30 nicm Exp $ */
/*
* Copyright (C) Caldera International Inc. 2001-2002.
* All rights reserved.
@@ -198,7 +198,7 @@ static char *match_function(const long *, int, FILE *);
static char *preadline(int, size_t, off_t);
static int Tflag;
-static int context = 3;
+int diff_context = 3;
int diff_format = D_NORMAL;
const char *diff_file1 = NULL;
const char *diff_file2 = NULL;
@@ -1011,8 +1011,8 @@ proceed:
diff_head();
anychange = 1;
- } else if (a > context_vec_ptr->b + (2 * context) + 1 &&
- c > context_vec_ptr->d + (2 * context) + 1) {
+ } else if (a > context_vec_ptr->b + (2 * diff_context) + 1 &&
+ c > context_vec_ptr->d + (2 * diff_context) + 1) {
/*
* If this change is more than 'context' lines from the
* previous change, dump the record and reset it.
@@ -1270,10 +1270,10 @@ dump_context_vec(FILE *f1, FILE *f2, int flags)
return;
b = d = 0; /* gcc */
- lowa = MAX(1, cvp->a - context);
- upb = MIN(len[0], context_vec_ptr->b + context);
- lowc = MAX(1, cvp->c - context);
- upd = MIN(len[1], context_vec_ptr->d + context);
+ lowa = MAX(1, cvp->a - diff_context);
+ upb = MIN(len[0], context_vec_ptr->b + diff_context);
+ lowc = MAX(1, cvp->c - diff_context);
+ upd = MIN(len[1], context_vec_ptr->d + diff_context);
diff_output("***************");
if ((flags & D_PROTOTYPE)) {
@@ -1373,10 +1373,10 @@ dump_unified_vec(FILE *f1, FILE *f2, int flags)
return;
b = d = 0; /* gcc */
- lowa = MAX(1, cvp->a - context);
- upb = MIN(len[0], context_vec_ptr->b + context);
- lowc = MAX(1, cvp->c - context);
- upd = MIN(len[1], context_vec_ptr->d + context);
+ lowa = MAX(1, cvp->a - diff_context);
+ upb = MIN(len[0], context_vec_ptr->b + diff_context);
+ lowc = MAX(1, cvp->c - diff_context);
+ upd = MIN(len[1], context_vec_ptr->d + diff_context);
diff_output("@@ -");
uni_range(lowa, upb);