summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorXavier Santolaria <xsa@cvs.openbsd.org>2008-02-02 16:21:39 +0000
committerXavier Santolaria <xsa@cvs.openbsd.org>2008-02-02 16:21:39 +0000
commitfb6776c9b67f4633be57d7a146b0adf48ff875e4 (patch)
tree1f1b40b741f33557849075494ce8a70717025b1e /usr.bin
parentb14067cc8c2513fe9f608b36ddc3dde3665568d3 (diff)
From src/usr.bin/cvs:
> add changed lines support to log and rlog (the + and - stuff) > from Pierre Riteau;
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/rcs/rcs.c53
-rw-r--r--usr.bin/rcs/rcs.h3
-rw-r--r--usr.bin/rcs/rlog.c44
3 files changed, 95 insertions, 5 deletions
diff --git a/usr.bin/rcs/rcs.c b/usr.bin/rcs/rcs.c
index c7e2814262d..4c3fa730de6 100644
--- a/usr.bin/rcs/rcs.c
+++ b/usr.bin/rcs/rcs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcs.c,v 1.45 2008/01/31 16:36:11 tobias Exp $ */
+/* $OpenBSD: rcs.c,v 1.46 2008/02/02 16:21:38 xsa Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -1277,6 +1277,57 @@ rcs_getrev(RCSFILE *rfp, RCSNUM *frev)
return (rbuf);
}
+void
+rcs_delta_stats(struct rcs_delta *rdp, int *ladded, int *lremoved)
+{
+ struct rcs_lines *plines;
+ struct rcs_line *lp;
+ int added, i, lineno, nbln, removed;
+ char op, *ep;
+ u_char tmp;
+
+ added = removed = 0;
+
+ plines = rcs_splitlines(rdp->rd_text, rdp->rd_tlen);
+ lp = TAILQ_FIRST(&(plines->l_lines));
+
+ /* skip first bogus line */
+ for (lp = TAILQ_NEXT(lp, l_list); lp != NULL;
+ lp = TAILQ_NEXT(lp, l_list)) {
+ if (lp->l_len < 2)
+ errx(1,
+ "line too short, RCS patch seems broken");
+ op = *(lp->l_line);
+ /* NUL-terminate line buffer for strtol() safety. */
+ tmp = lp->l_line[lp->l_len - 1];
+ lp->l_line[lp->l_len - 1] = '\0';
+ lineno = (int)strtol((lp->l_line + 1), &ep, 10);
+ ep++;
+ nbln = (int)strtol(ep, &ep, 10);
+ /* Restore the last byte of the buffer */
+ lp->l_line[lp->l_len - 1] = tmp;
+ if (nbln < 0)
+ errx(1, "invalid line number specification "
+ "in RCS patch");
+
+ if (op == 'a') {
+ added += nbln;
+ for (i = 0; i < nbln; i++) {
+ lp = TAILQ_NEXT(lp, l_list);
+ if (lp == NULL)
+ errx(1, "truncated RCS patch");
+ }
+ } else if (op == 'd')
+ removed += nbln;
+ else
+ errx(1, "unknown RCS patch operation '%c'", op);
+ }
+
+ *ladded = added;
+ *lremoved = removed;
+}
+
+
/*
* rcs_rev_add()
*
diff --git a/usr.bin/rcs/rcs.h b/usr.bin/rcs/rcs.h
index 9f279ea8764..6e82ae5ed66 100644
--- a/usr.bin/rcs/rcs.h
+++ b/usr.bin/rcs/rcs.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcs.h,v 1.7 2008/01/31 16:36:11 tobias Exp $ */
+/* $OpenBSD: rcs.h,v 1.8 2008/02/02 16:21:38 xsa Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -253,6 +253,7 @@ int rcs_state_check(const char *);
RCSNUM *rcs_tag_resolve(RCSFILE *, const char *);
const char *rcs_errstr(int);
void rcs_write(RCSFILE *);
+void rcs_delta_stats(struct rcs_delta *, int *, int *);
int rcs_kflag_get(const char *);
void rcs_kflag_usage(void);
diff --git a/usr.bin/rcs/rlog.c b/usr.bin/rcs/rlog.c
index 4f3d0f35abc..6b904ef56d4 100644
--- a/usr.bin/rcs/rlog.c
+++ b/usr.bin/rcs/rlog.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rlog.c,v 1.59 2007/09/09 17:01:38 ray Exp $ */
+/* $OpenBSD: rlog.c,v 1.60 2008/02/02 16:21:38 xsa Exp $ */
/*
* Copyright (c) 2005 Joris Vink <joris@openbsd.org>
* Copyright (c) 2005, 2006 Xavier Santolaria <xsa@openbsd.org>
@@ -262,6 +262,8 @@ rlog_rev_print(struct rcs_delta *rdp)
struct tm t;
char *author, numb[RCS_REV_BUFSZ], *fmt, timeb[RCS_TIME_BUFSZ];
struct rcs_argvector *largv, *sargv, *wargv;
+ struct rcs_branch *rb;
+ struct rcs_delta *nrdp;
i = found = 0;
author = NULL;
@@ -347,10 +349,46 @@ rlog_rev_print(struct rcs_delta *rdp)
fmt = "%Y/%m/%d %H:%M:%S";
}
- strftime(timeb, sizeof(timeb), fmt, &t);
+ (void)strftime(timeb, sizeof(timeb), fmt, &t);
- printf("\ndate: %s; author: %s; state: %s;\n", timeb, rdp->rd_author,
+ printf("\ndate: %s; author: %s; state: %s;", timeb, rdp->rd_author,
rdp->rd_state);
+ /*
+ * If we are a branch revision, the diff of this revision is stored
+ * in place.
+ * Otherwise, it is stored in the previous revision as a reversed diff.
+ */
+ if (RCSNUM_ISBRANCHREV(rdp->rd_num))
+ nrdp = rdp;
+ else
+ nrdp = TAILQ_NEXT(rdp, rd_list);
+
+ /*
+ * We do not write diff stats for the first revision of the default
+ * branch, since it was not a diff but a full text.
+ */
+ if (nrdp != NULL && rdp->rd_num->rn_len == nrdp->rd_num->rn_len) {
+ int added, removed;
+ rcs_delta_stats(nrdp, &added, &removed);
+ if (RCSNUM_ISBRANCHREV(rdp->rd_num))
+ printf(" lines: +%d -%d", added, removed);
+ else
+ printf(" lines: +%d -%d", removed, added);
+ }
+ printf("\n");
+
+ if (!TAILQ_EMPTY(&(rdp->rd_branches))) {
+ printf("branches:");
+ TAILQ_FOREACH(rb, &(rdp->rd_branches), rb_list) {
+ RCSNUM *branch;
+ branch = rcsnum_revtobr(rb->rb_num);
+ (void)rcsnum_tostr(branch, numb, sizeof(numb));
+ printf(" %s;", numb);
+ rcsnum_free(branch);
+ }
+ printf("\n");
+ }
+
printf("%s", rdp->rd_log);
}