diff options
author | Ray Lai <ray@cvs.openbsd.org> | 2006-04-12 08:23:31 +0000 |
---|---|---|
committer | Ray Lai <ray@cvs.openbsd.org> | 2006-04-12 08:23:31 +0000 |
commit | d168187781096ebce8875465a1ac0d8ef42bdef8 (patch) | |
tree | 16ed20858dec9d8349da6c6d839bb2bb8526fc6e /usr.bin/rcs/co.c | |
parent | d9349acd8c7813ac3bc17ef771803b40fdf1bcbc (diff) |
Clean up <rev> handling. Whenever a revision is specified after a
flag, it calls one of two new functions: rcs_setrevstr() or
rcs_setrevstr2(). rcs_setrevstr() sets a string to another string,
and complains if it was set more than once. rcs_setrevstr2() takes
two strings, sets one after the other, and fatal()s if more than
two strings were given.
All <rev> handling is now done in the loop that goes through each
argv. This is necessary for parsing symbols, which will be much
easier after this.
Along the way a lot of memory leaks were cleaned up. There is one
area where rcs_set_rev() is called, which allocates a RCSNUM and
stores it in pb.newrev, but it segfaults whenever I try to rcsnum_free()
it. I put an /* XXX */ comment there for now.
Passes regression tests and the code is less complicated in some
ways (to me).
Suggestions and OK xsa@
Diffstat (limited to 'usr.bin/rcs/co.c')
-rw-r--r-- | usr.bin/rcs/co.c | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/usr.bin/rcs/co.c b/usr.bin/rcs/co.c index 0a335b1f2bf..35fa43990a9 100644 --- a/usr.bin/rcs/co.c +++ b/usr.bin/rcs/co.c @@ -1,4 +1,4 @@ -/* $OpenBSD: co.c,v 1.72 2006/04/10 08:08:00 xsa Exp $ */ +/* $OpenBSD: co.c,v 1.73 2006/04/12 08:23:30 ray Exp $ */ /* * Copyright (c) 2005 Joris Vink <joris@openbsd.org> * All rights reserved. @@ -40,7 +40,7 @@ checkout_main(int argc, char **argv) RCSNUM *frev, *rev; RCSFILE *file; char fpath[MAXPATHLEN]; - char *author, *username, *date; + char *author, *date, *rev_str, *username; const char *state; time_t rcs_mtime = -1; @@ -48,6 +48,7 @@ checkout_main(int argc, char **argv) kflag = RCS_KWEXP_ERR; rev = RCS_HEAD_REV; frev = NULL; + rev_str = NULL; state = NULL; author = NULL; date = NULL; @@ -58,11 +59,11 @@ checkout_main(int argc, char **argv) date = xstrdup(rcs_optarg); break; case 'f': - rcs_set_rev(rcs_optarg, &rev); + rcs_setrevstr(&rev_str, rcs_optarg); flags |= FORCE; break; case 'I': - rcs_set_rev(rcs_optarg, &rev); + rcs_setrevstr(&rev_str, rcs_optarg); flags |= INTERACTIVE; break; @@ -76,27 +77,27 @@ checkout_main(int argc, char **argv) } break; case 'l': - rcs_set_rev(rcs_optarg, &rev); if (flags & CO_UNLOCK) { cvs_log(LP_ERR, "warning: -u overridden by -l"); flags &= ~CO_UNLOCK; } + rcs_setrevstr(&rev_str, rcs_optarg); flags |= CO_LOCK; break; case 'M': - rcs_set_rev(rcs_optarg, &rev); + rcs_setrevstr(&rev_str, rcs_optarg); flags |= CO_REVDATE; break; case 'p': - rcs_set_rev(rcs_optarg, &rev); + rcs_setrevstr(&rev_str, rcs_optarg); pipeout = 1; break; case 'q': - rcs_set_rev(rcs_optarg, &rev); + rcs_setrevstr(&rev_str, rcs_optarg); verbose = 0; break; case 'r': - rcs_set_rev(rcs_optarg, &rev); + rcs_setrevstr(&rev_str, rcs_optarg); break; case 's': state = xstrdup(rcs_optarg); @@ -106,7 +107,7 @@ checkout_main(int argc, char **argv) flags |= PRESERVETIME; break; case 'u': - rcs_set_rev(rcs_optarg, &rev); + rcs_setrevstr(&rev_str, rcs_optarg); if (flags & CO_LOCK) { cvs_log(LP_ERR, "warning: -l overridden by -u"); flags &= ~CO_LOCK; @@ -175,21 +176,25 @@ checkout_main(int argc, char **argv) rcs_kwexp_set(file, kflag); - if (rev == RCS_HEAD_REV) - frev = file->rf_head; - else - frev = rev; + if (rev_str != NULL) + rcs_set_rev(rev_str, &rev); + else { + rev = rcsnum_alloc(); + rcsnum_cpy(file->rf_head, rev, 0); + } - if ((status = checkout_rev(file, frev, argv[i], flags, + if ((status = checkout_rev(file, rev, argv[i], flags, username, author, state, date)) < 0) { - rcs_close(file); - continue; + rcs_close(file); + rcsnum_free(rev); + continue; } if (verbose == 1) printf("done\n"); rcs_close(file); + rcsnum_free(rev); if (flags & PRESERVETIME) rcs_set_mtime(fpath, rcs_mtime); |