summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Francois Brousseau <jfb@cvs.openbsd.org>2005-01-13 23:39:43 +0000
committerJean-Francois Brousseau <jfb@cvs.openbsd.org>2005-01-13 23:39:43 +0000
commit0788be35d30bba9fccc1f817923c6e7b88723fe5 (patch)
treed12e5fef028d0a7e206367644cf25686825aba47
parent29424443fa2fd8e5e3025e2c6c4dcffc046738ac (diff)
resurrect the -N and -p options to the diff command
requested and tested by brad@, thanks!
-rw-r--r--usr.bin/cvs/cvs.14
-rw-r--r--usr.bin/cvs/cvs.c6
-rw-r--r--usr.bin/cvs/diff.c70
3 files changed, 68 insertions, 12 deletions
diff --git a/usr.bin/cvs/cvs.1 b/usr.bin/cvs/cvs.1
index 099235325a4..bc088f51d36 100644
--- a/usr.bin/cvs/cvs.1
+++ b/usr.bin/cvs/cvs.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: cvs.1,v 1.23 2005/01/13 00:03:28 xsa Exp $
+.\" $OpenBSD: cvs.1,v 1.24 2005/01/13 23:39:42 jfb Exp $
.\"
.\" Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
.\" All rights reserved.
@@ -175,7 +175,7 @@ repository's information to reflect the changes.
Aliases:
.Ic ci ,
.Ic com .
-.It Xo Ic diff Op Fl cilu
+.It Xo Ic diff Op Fl cilNpu
.Op Fl D Ar date
.Op Fl r Ar rev
.Op Ar file ...
diff --git a/usr.bin/cvs/cvs.c b/usr.bin/cvs/cvs.c
index 5b28ea2d86b..853cfb6a340 100644
--- a/usr.bin/cvs/cvs.c
+++ b/usr.bin/cvs/cvs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cvs.c,v 1.33 2005/01/13 18:47:31 jfb Exp $ */
+/* $OpenBSD: cvs.c,v 1.34 2005/01/13 23:39:42 jfb Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -131,8 +131,8 @@ static struct cvs_cmd {
},
{
CVS_OP_DIFF, "diff", { "di", "dif" }, cvs_diff,
- "[-cilu] [-D date] [-r rev] ...",
- "cD:ilur:",
+ "[-cilNpu] [-D date] [-r rev] ...",
+ "cD:ilNpr:u",
"Show differences between revisions",
NULL,
},
diff --git a/usr.bin/cvs/diff.c b/usr.bin/cvs/diff.c
index 2b0c3c940da..d69c6d87d71 100644
--- a/usr.bin/cvs/diff.c
+++ b/usr.bin/cvs/diff.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: diff.c,v 1.16 2004/12/28 22:07:31 xsa Exp $ */
+/* $OpenBSD: diff.c,v 1.17 2005/01/13 23:39:42 jfb Exp $ */
/*
* Copyright (C) Caldera International Inc. 2001-2002.
* All rights reserved.
@@ -239,12 +239,13 @@ static int isqrt(int);
static int stone(int *, int, int *, int *);
static int readhash(FILE *);
static int files_differ(FILE *, FILE *);
+static char *match_function(const long *, int, FILE *);
static char *preadline(int, size_t, off_t);
extern int cvs_client;
-static int aflag, bflag, dflag, iflag, Nflag, tflag, Tflag, wflag;
+static int aflag, bflag, dflag, iflag, Nflag, pflag, tflag, Tflag, wflag;
static int context, status;
static int format = D_NORMAL;
static struct stat stb1, stb2;
@@ -273,8 +274,9 @@ static struct context_vec *context_vec_end;
static struct context_vec *context_vec_ptr;
#define FUNCTION_CONTEXT_SIZE 41
-static int lastline;
-static int lastmatchline;
+static char lastbuf[FUNCTION_CONTEXT_SIZE];
+static int lastline;
+static int lastmatchline;
/*
@@ -357,7 +359,7 @@ cvs_diff(int argc, char **argv)
memset(&darg, 0, sizeof(darg));
strlcpy(diffargs, argv[0], sizeof(diffargs));
- while ((ch = getopt(argc, argv, "cD:liN:r:u")) != -1) {
+ while ((ch = getopt(argc, argv, "cD:liNpr:u")) != -1) {
switch (ch) {
case 'c':
strlcat(diffargs, " -c", sizeof(diffargs));
@@ -387,6 +389,10 @@ cvs_diff(int argc, char **argv)
strlcat(diffargs, " -N", sizeof(diffargs));
Nflag = 1;
break;
+ case 'p':
+ strlcat(diffargs, " -p", sizeof(diffargs));
+ pflag = 1;
+ break;
case 'r':
if ((darg.rev1 == NULL) && (darg.date1 == NULL))
darg.rev1 = optarg;
@@ -438,6 +444,11 @@ int
cvs_diff_sendflags(struct cvsroot *root, struct diff_arg *dap)
{
/* send the flags */
+ if (Nflag && (cvs_sendarg(root, "-N", 0) < 0))
+ return (-1);
+ if (pflag && (cvs_sendarg(root, "-p", 0) < 0))
+ return (-1);
+
if (format == D_CONTEXT)
cvs_sendarg(root, "-c", 0);
else if (format == D_UNIFIED)
@@ -1424,6 +1435,37 @@ asciifile(FILE *f)
return (1);
}
+static char*
+match_function(const long *f, int pos, FILE *fp)
+{
+ unsigned char buf[FUNCTION_CONTEXT_SIZE];
+ size_t nc;
+ int last = lastline;
+ char *p;
+
+ lastline = pos;
+ while (pos > last) {
+ fseek(fp, f[pos - 1], SEEK_SET);
+ nc = f[pos] - f[pos - 1];
+ if (nc >= sizeof(buf))
+ nc = sizeof(buf) - 1;
+ nc = fread(buf, 1, nc, fp);
+ if (nc > 0) {
+ buf[nc] = '\0';
+ p = strchr(buf, '\n');
+ if (p != NULL)
+ *p = '\0';
+ if (isalpha(buf[0]) || buf[0] == '_' || buf[0] == '$') {
+ strlcpy(lastbuf, buf, sizeof lastbuf);
+ lastmatchline = pos;
+ return lastbuf;
+ }
+ }
+ pos--;
+ }
+ return (lastmatchline > 0) ? lastbuf : NULL;
+}
+
/* dump accumulated "context" diff changes */
static void
@@ -1432,7 +1474,7 @@ dump_context_vec(FILE *f1, FILE *f2)
struct context_vec *cvp = context_vec_start;
int lowa, upb, lowc, upd, do_output;
int a, b, c, d;
- char ch;
+ char ch, *f;
if (context_vec_start > context_vec_ptr)
return;
@@ -1444,6 +1486,13 @@ dump_context_vec(FILE *f1, FILE *f2)
upd = MIN(len[1], context_vec_ptr->d + context);
printf("***************");
+ if (pflag) {
+ f = match_function(ixold, lowa - 1, f1);
+ if (f != NULL) {
+ putchar(' ');
+ fputs(f, stdout);
+ }
+ }
printf("\n*** ");
range(lowa, upb, ",");
printf(" ****\n");
@@ -1530,7 +1579,7 @@ dump_unified_vec(FILE *f1, FILE *f2)
struct context_vec *cvp = context_vec_start;
int lowa, upb, lowc, upd;
int a, b, c, d;
- char ch;
+ char ch, *f;
if (context_vec_start > context_vec_ptr)
return;
@@ -1546,6 +1595,13 @@ dump_unified_vec(FILE *f1, FILE *f2)
fputs(" +", stdout);
uni_range(lowc, upd);
fputs(" @@", stdout);
+ if (pflag) {
+ f = match_function(ixold, lowa - 1, f1);
+ if (f != NULL) {
+ putchar(' ');
+ fputs(f, stdout);
+ }
+ }
putchar('\n');
/*