diff options
author | Joris Vink <joris@cvs.openbsd.org> | 2008-01-31 20:29:17 +0000 |
---|---|---|
committer | Joris Vink <joris@cvs.openbsd.org> | 2008-01-31 20:29:17 +0000 |
commit | 438536a52d177ddcb19c2f9823550828d15c4ce0 (patch) | |
tree | cd29dc699b85de1c451cfab5953581edfb18fe47 /usr.bin/cvs | |
parent | 272552091816096cdc9c3bf627f1b5fa4adf6159 (diff) |
add changed lines support to log and rlog (the + and - stuff)
from Pierre Riteau;
Diffstat (limited to 'usr.bin/cvs')
-rw-r--r-- | usr.bin/cvs/getlog.c | 43 | ||||
-rw-r--r-- | usr.bin/cvs/rcs.c | 51 | ||||
-rw-r--r-- | usr.bin/cvs/rcs.h | 3 |
3 files changed, 93 insertions, 4 deletions
diff --git a/usr.bin/cvs/getlog.c b/usr.bin/cvs/getlog.c index 77ab794e172..9653e7d4ecd 100644 --- a/usr.bin/cvs/getlog.c +++ b/usr.bin/cvs/getlog.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getlog.c,v 1.81 2008/01/31 10:15:05 tobias Exp $ */ +/* $OpenBSD: getlog.c,v 1.82 2008/01/31 20:29:16 joris Exp $ */ /* * Copyright (c) 2005, 2006 Xavier Santolaria <xsa@openbsd.org> * Copyright (c) 2006 Joris Vink <joris@openbsd.org> @@ -288,6 +288,8 @@ log_rev_print(struct rcs_delta *rdp) int i, found; char numb[CVS_REV_BUFSZ], timeb[CVS_TIME_BUFSZ]; struct cvs_argvector *sargv, *wargv; + struct rcs_branch *rb; + struct rcs_delta *nrdp; i = found = 0; @@ -326,7 +328,44 @@ log_rev_print(struct rcs_delta *rdp) cvs_printf("revision %s", numb); strftime(timeb, sizeof(timeb), "%Y/%m/%d %H:%M:%S", &rdp->rd_date); - cvs_printf("\ndate: %s; author: %s; state: %s;\n", + cvs_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)) + cvs_printf(" lines: +%d -%d", added, removed); + else + cvs_printf(" lines: +%d -%d", removed, added); + } + cvs_printf("\n"); + + if (!TAILQ_EMPTY(&(rdp->rd_branches))) { + cvs_printf("branches:"); + TAILQ_FOREACH(rb, &(rdp->rd_branches), rb_list) { + RCSNUM *branch; + branch = rcsnum_revtobr(rb->rb_num); + rcsnum_tostr(branch, numb, sizeof(numb)); + cvs_printf(" %s;", numb); + rcsnum_free(branch); + } + cvs_printf("\n"); + } + cvs_printf("%s", rdp->rd_log); } diff --git a/usr.bin/cvs/rcs.c b/usr.bin/cvs/rcs.c index ef988ba22ae..cb40f5f365b 100644 --- a/usr.bin/cvs/rcs.c +++ b/usr.bin/cvs/rcs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rcs.c,v 1.240 2008/01/28 21:33:20 tobias Exp $ */ +/* $OpenBSD: rcs.c,v 1.241 2008/01/31 20:29:16 joris Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -1134,6 +1134,55 @@ rcs_patch_lines(struct cvs_lines *dlines, struct cvs_lines *plines, return (0); } +void +rcs_delta_stats(struct rcs_delta *rdp, int *ladded, int *lremoved) +{ + struct cvs_lines *plines; + struct cvs_line *lp; + int added, i, lineno, nbln, removed; + char op, *ep; + u_char tmp; + + added = removed = 0; + + plines = cvs_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) + fatal("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) + fatal("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) + fatal("truncated RCS patch"); + } + } + else if (op == 'd') + removed += nbln; + else + fatal("unknown RCS patch operation '%c'", op); + } + + *ladded = added; + *lremoved = removed; +} + /* * rcs_rev_add() * diff --git a/usr.bin/cvs/rcs.h b/usr.bin/cvs/rcs.h index c71cf78db32..6b69d817e00 100644 --- a/usr.bin/cvs/rcs.h +++ b/usr.bin/cvs/rcs.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rcs.h,v 1.84 2008/01/10 10:06:59 tobias Exp $ */ +/* $OpenBSD: rcs.h,v 1.85 2008/01/31 20:29:16 joris Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -266,6 +266,7 @@ struct cvs_lines *rcs_rev_getlines(RCSFILE *, RCSNUM *, void rcs_annotate_getlines(RCSFILE *, RCSNUM *, struct cvs_line ***); BUF *rcs_rev_getbuf(RCSFILE *, RCSNUM *, int); +void rcs_delta_stats(struct rcs_delta *, int *, int *); int rcs_kflag_get(const char *); void rcs_kflag_usage(void); |