diff options
author | Joris Vink <joris@cvs.openbsd.org> | 2006-05-31 18:26:15 +0000 |
---|---|---|
committer | Joris Vink <joris@cvs.openbsd.org> | 2006-05-31 18:26:15 +0000 |
commit | d66b8ad730447fd867eb6e74ff8240d5366bc5d4 (patch) | |
tree | 8bd86fc8f6d02b0fe89c5c1610122c74f907b1e1 /usr.bin/cvs | |
parent | fb94c9d6329f2abaa8916326ec5f05caeedd42a6 (diff) |
have rcs_translate_tag translate branches too, which
allows us to completely use branches for diffing, logging,
updating, etc..
more branches support coming up!
Diffstat (limited to 'usr.bin/cvs')
-rw-r--r-- | usr.bin/cvs/rcs.c | 87 | ||||
-rw-r--r-- | usr.bin/cvs/rcs.h | 5 |
2 files changed, 61 insertions, 31 deletions
diff --git a/usr.bin/cvs/rcs.c b/usr.bin/cvs/rcs.c index 7b27255a8a1..ce6e76cbc4d 100644 --- a/usr.bin/cvs/rcs.c +++ b/usr.bin/cvs/rcs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rcs.c,v 1.177 2006/05/30 19:16:51 joris Exp $ */ +/* $OpenBSD: rcs.c,v 1.178 2006/05/31 18:26:14 joris Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -1459,17 +1459,16 @@ rcs_rev_remove(RCSFILE *rf, RCSNUM *rev) * Find a specific revision's delta entry in the tree of the RCS file <rfp>. * The revision number is given in <rev>. * - * If the given revision is a branch number, we translate it into the latest - * revision on the branch. - * * Returns a pointer to the delta on success, or NULL on failure. */ struct rcs_delta * rcs_findrev(RCSFILE *rfp, RCSNUM *rev) { + int isbrev; u_int cmplen; struct rcs_delta *rdp; - RCSNUM *brev, *frev; + + isbrev = RCSNUM_ISBRANCHREV(rev); /* * We need to do more parsing if the last revision in the linked list @@ -1477,35 +1476,18 @@ rcs_findrev(RCSFILE *rfp, RCSNUM *rev) */ rdp = TAILQ_LAST(&(rfp->rf_delta), rcs_dlist); if (rdp == NULL || - rcsnum_cmp(rdp->rd_num, rev, 0) == -1) { + (!isbrev && rcsnum_cmp(rdp->rd_num, rev, 0) == -1) || + ((isbrev && rdp->rd_num->rn_len < 4) || + (isbrev && rcsnum_differ(rev, rdp->rd_num)))) { rcs_parse_deltas(rfp, rev); } - /* - * Translate a branch into the latest revision on the branch itself. - */ - if (RCSNUM_ISBRANCH(rev)) { - brev = rcsnum_brtorev(rev); - frev = brev; - for (;;) { - rdp = rcs_findrev(rfp, frev); - if (rdp == NULL) - return (NULL); - - if (rdp->rd_next->rn_len == 0) - break; - - frev = rdp->rd_next; - } - - rcsnum_free(brev); - return (rdp); - } - cmplen = rev->rn_len; TAILQ_FOREACH(rdp, &(rfp->rf_delta), rd_list) { - if (rcsnum_cmp(rdp->rd_num, rev, cmplen) == 0) + if (rcsnum_differ(rdp->rd_num, rev)) + continue; + else return (rdp); } @@ -2968,7 +2950,11 @@ rcs_kwexp_buf(BUF *bp, RCSFILE *rf, RCSNUM *rev) RCSNUM * rcs_translate_tag(const char *revstr, RCSFILE *rfp) { - RCSNUM *rev; + size_t i; + RCSNUM *rev, *brev; + struct rcs_branch *brp; + struct rcs_delta *rdp, *brdp; + char foo[16]; rev = rcs_sym_getrev(rfp, revstr); if (rev == NULL) { @@ -2976,5 +2962,48 @@ rcs_translate_tag(const char *revstr, RCSFILE *rfp) fatal("%s is an invalid revision/symbol", revstr); } + if (RCSNUM_ISBRANCH(rev)) { + brev = rcsnum_alloc(); + rcsnum_cpy(rev, brev, 2); + + if ((rdp = rcs_findrev(rfp, brev)) == NULL) + fatal("rcs_translate_tag: cannot find branch root " + "for '%s'", revstr); + + TAILQ_FOREACH(brp, &(rdp->rd_branches), rb_list) { + if (brp->rb_num->rn_len < 4) + fatal("rcs_translate_tag: bad branch " + "revision on list"); + + for (i = 0; i < rev->rn_len; i++) { + if (rev->rn_id[i] != brp->rb_num->rn_id[i]) + continue; + } + + rcsnum_tostr(brp->rb_num, foo, sizeof(foo)); + break; + } + + if (brp == NULL) { + rcsnum_cpy(rdp->rd_num, rev, 0); + return (rev); + } + + if ((rdp = rcs_findrev(rfp, brp->rb_num)) == NULL) { + rcsnum_tostr(brp->rb_num, foo, sizeof(foo)); + fatal("rcs_translate_tag: cannot find branch rev %s", + foo); + } + + brdp = rdp; + while (brdp->rd_next->rn_len != 0) { + brdp = rcs_findrev(rfp, brdp->rd_next); + if (brdp == NULL) + fatal("rcs_translate_tag: next is NULL"); + } + + rcsnum_cpy(brdp->rd_num, rev, 0); + } + return (rev); } diff --git a/usr.bin/cvs/rcs.h b/usr.bin/cvs/rcs.h index 52b379f7b9d..a69a4877072 100644 --- a/usr.bin/cvs/rcs.h +++ b/usr.bin/cvs/rcs.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rcs.h,v 1.66 2006/05/30 19:16:51 joris Exp $ */ +/* $OpenBSD: rcs.h,v 1.67 2006/05/31 18:26:14 joris Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -272,7 +272,8 @@ void rcsnum_free(RCSNUM *); int rcsnum_aton(const char *, char **, RCSNUM *); char *rcsnum_tostr(const RCSNUM *, char *, size_t); void rcsnum_cpy(const RCSNUM *, RCSNUM *, u_int); -int rcsnum_cmp(const RCSNUM *, const RCSNUM *, u_int); +int rcsnum_cmp(RCSNUM *, RCSNUM *, u_int); +int rcsnum_differ(RCSNUM *, RCSNUM *); /* rcstime.c */ void rcs_set_tz(char *, struct rcs_delta *, struct tm *); |