diff options
-rw-r--r-- | usr.bin/cvs/rcs.c | 26 | ||||
-rw-r--r-- | usr.bin/cvs/rcsnum.c | 20 | ||||
-rw-r--r-- | usr.bin/rcs/ci.c | 25 |
3 files changed, 48 insertions, 23 deletions
diff --git a/usr.bin/cvs/rcs.c b/usr.bin/cvs/rcs.c index 0c61aad358e..c67c3fb2c5a 100644 --- a/usr.bin/cvs/rcs.c +++ b/usr.bin/cvs/rcs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rcs.c,v 1.142 2006/03/11 18:40:14 niallo Exp $ */ +/* $OpenBSD: rcs.c,v 1.143 2006/03/11 22:44:11 niallo Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -1264,9 +1264,7 @@ rcs_rev_add(RCSFILE *rf, RCSNUM *rev, const char *msg, time_t date, time_t now; struct passwd *pw; struct rcs_delta *ordp, *rdp; - RCSNUM *old; - old = rcsnum_alloc(); if (rev == RCS_HEAD_REV) { if (rf->rf_flags & RCS_CREATE) { if ((rev = rcsnum_parse(RCS_HEAD_INIT)) == NULL) @@ -1274,24 +1272,13 @@ rcs_rev_add(RCSFILE *rf, RCSNUM *rev, const char *msg, time_t date, rf->rf_head = rcsnum_alloc(); rcsnum_cpy(rev, rf->rf_head, 0); } else { - rcsnum_cpy(rf->rf_head, old, 0); rev = rcsnum_inc(rf->rf_head); } } else { if ((rdp = rcs_findrev(rf, rev)) != NULL) { rcs_errno = RCS_ERR_DUPENT; - rcsnum_free(old); return (-1); } - - if (!(rf->rf_flags & RCS_CREATE)) { - ordp = NULL; - rcsnum_cpy(rev, old, 0); - while (ordp == NULL) { - old = rcsnum_dec(old); - ordp = rcs_findrev(rf, old); - } - } } if ((pw = getpwuid(getuid())) == NULL) @@ -1308,10 +1295,12 @@ rcs_rev_add(RCSFILE *rf, RCSNUM *rev, const char *msg, time_t date, rdp->rd_next = rcsnum_alloc(); - if (!(rf->rf_flags & RCS_CREATE)) - rcsnum_cpy(old, rdp->rd_next, 0); + if (!(rf->rf_flags & RCS_CREATE)) { + /* next should point to the previous HEAD */ + ordp = TAILQ_FIRST(&(rf->rf_delta)); + rcsnum_cpy(ordp->rd_num, rdp->rd_next, 0); + } - rcsnum_free(old); if (username == NULL) username = pw->pw_name; @@ -2970,8 +2959,9 @@ cvs_checkout_rev(RCSFILE *rf, RCSNUM *rev, CVSFILE *cf, char *fpath, oldrev = rcsnum_alloc(); rcsnum_cpy(rev, oldrev, 0); - if (rcsnum_dec(oldrev) == NULL) + if (oldrev->rn_id[oldrev->rn_len - 1] <= 0) goto out; + oldrev = rcsnum_dec(oldrev); l = snprintf(copyfile, sizeof(copyfile), ".#%s.%s", cf->cf_name, rcsnum_tostr(oldrev, buf, sizeof(buf))); diff --git a/usr.bin/cvs/rcsnum.c b/usr.bin/cvs/rcsnum.c index 85ae275ba6a..72cd3cf1d99 100644 --- a/usr.bin/cvs/rcsnum.c +++ b/usr.bin/cvs/rcsnum.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rcsnum.c,v 1.25 2006/03/11 06:28:49 ray Exp $ */ +/* $OpenBSD: rcsnum.c,v 1.26 2006/03/11 22:44:11 niallo Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -124,6 +124,9 @@ rcsnum_itoa(u_int16_t num, char *buf, size_t len) u_int16_t i; char *p; + if (num == 0) + return "0"; + p = buf + len - 1; i = num; bzero(buf, len); @@ -295,6 +298,14 @@ rcsnum_aton(const char *str, char **ep, RCSNUM *nump) } } + /* We can't have a single-digit rcs number. */ + if (nump->rn_len == 0) { + tmp = xrealloc(nump->rn_id, + (nump->rn_len + 1) * sizeof(u_int16_t)); + nump->rn_id = (u_int16_t *)tmp; + nump->rn_id[nump->rn_len + 1] = 0; + nump->rn_len++; + } nump->rn_len++; return (nump->rn_len); @@ -323,14 +334,15 @@ rcsnum_inc(RCSNUM *num) /* * rcsnum_dec() * - * Decreases the revision number specified in <num> - * Returns pointer to the <num> on success, or NULL on failure. + * Decreases the revision number specified in <num>, if doing so will not + * result in an ending value below 1. E.g. 4.2 will go to 4.1 but 4.1 will + * be returned as 4.1. */ RCSNUM * rcsnum_dec(RCSNUM *num) { if (num->rn_id[num->rn_len - 1] <= 0) - return (NULL); + return (num); num->rn_id[num->rn_len - 1]--; return (num); } diff --git a/usr.bin/rcs/ci.c b/usr.bin/rcs/ci.c index 9002f17f081..d3028ba23fa 100644 --- a/usr.bin/rcs/ci.c +++ b/usr.bin/rcs/ci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ci.c,v 1.114 2006/03/11 18:38:54 niallo Exp $ */ +/* $OpenBSD: ci.c,v 1.115 2006/03/11 22:44:11 niallo Exp $ */ /* * Copyright (c) 2005, 2006 Niall O'Higgins <niallo@openbsd.org> * All rights reserved. @@ -51,6 +51,8 @@ #define KW_NUMTOKS_STATE 3 #define KW_NUMTOKS_REVISION 3 +#define RCSNUM_ZERO_ENDING(x) (x->rn_id[x->rn_len - 1] == 0) + extern struct rcs_kw rcs_expkw[]; struct checkin_params { @@ -453,6 +455,10 @@ checkin_update(struct checkin_params *pb) */ pb->frev = pb->file->rf_head; + /* If this is a zero-ending RCSNUM eg 4.0, increment it (eg to 4.1) */ + if ((pb->newrev != NULL) && (RCSNUM_ZERO_ENDING(pb->newrev))) + pb->newrev = rcsnum_inc(pb->newrev); + if (checkin_checklock(pb) < 0) return (-1); @@ -606,8 +612,17 @@ checkin_init(struct checkin_params *pb) { BUF *bp, *dp; char *filec, numb[64]; + int fetchlog = 0; const char *rcs_desc; + /* If this is a zero-ending RCSNUM eg 4.0, increment it (eg to 4.1) */ + if ((pb->newrev != NULL) && (RCSNUM_ZERO_ENDING(pb->newrev))) { + pb->frev = rcsnum_alloc(); + rcsnum_cpy(pb->newrev, pb->frev, 0); + pb->newrev = rcsnum_inc(pb->newrev); + fetchlog = 1; + } + /* Load file contents */ if ((bp = cvs_buf_load(pb->filename, BUF_AUTOEXT)) == NULL) { rcs_close(pb->file); @@ -654,6 +669,14 @@ checkin_init(struct checkin_params *pb) rcs_desc_set(pb->file, rcs_desc); /* + * If the user had specified a zero-ending revision number e.g. 4 + * emulate odd GNU behaviour and fetch log message. + */ + if (fetchlog == 1) { + pb->rcs_msg = checkin_getlogmsg(pb->frev, pb->newrev); + rcsnum_free(pb->frev); + } + /* * Set the date of the revision to be the last modification * time of the working file if -d has no argument. */ |