diff options
author | Joris Vink <joris@cvs.openbsd.org> | 2006-05-28 21:34:38 +0000 |
---|---|---|
committer | Joris Vink <joris@cvs.openbsd.org> | 2006-05-28 21:34:38 +0000 |
commit | 296716bcd389c354c305434ffad4526c937f984f (patch) | |
tree | 96f74754c1bfae390d8e65dd29483f72143d0529 /usr.bin | |
parent | 5fcbece4c3844d1a7eaa956a07fead6391d9c0c5 (diff) |
add code which allows us to select revisions based upon
a string given by the user on the command line, much like
rcs_revision_select in OpenRCS.
this will be usefull for some commands.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/cvs/util.c | 72 | ||||
-rw-r--r-- | usr.bin/cvs/util.h | 4 |
2 files changed, 74 insertions, 2 deletions
diff --git a/usr.bin/cvs/util.c b/usr.bin/cvs/util.c index 8eacf9ac418..eea8798ad9b 100644 --- a/usr.bin/cvs/util.c +++ b/usr.bin/cvs/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.81 2006/05/28 17:25:18 joris Exp $ */ +/* $OpenBSD: util.c,v 1.82 2006/05/28 21:34:37 joris Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * Copyright (c) 2005, 2006 Joris Vink <joris@openbsd.org> @@ -842,3 +842,73 @@ cvs_argv_destroy(struct cvs_argvector *av) xfree(av->argv); xfree(av); } + +u_int +cvs_revision_select(RCSFILE *file, char *range) +{ + int i; + u_int nrev; + char *lstr, *rstr; + struct rcs_delta *rdp; + struct cvs_argvector *revargv, *revrange; + RCSNUM *lnum, *rnum; + + nrev = 0; + lnum = rnum = NULL; + + revargv = cvs_strsplit(range, ","); + for (i = 0; revargv->argv[i] != NULL; i++) { + revrange = cvs_strsplit(revargv->argv[i], ":"); + if (revrange->argv[0] == NULL) + fatal("invalid revision range: %s", revargv->argv[i]); + else if (revrange->argv[1] == NULL) + lstr = rstr = revrange->argv[0]; + else { + if (revrange->argv[2] != NULL) + fatal("invalid revision range: %s", + revargv->argv[i]); + + lstr = revrange->argv[0]; + rstr = revrange->argv[1]; + + if (strcmp(lstr, "") == 0) + lstr = NULL; + if (strcmp(rstr, "") == 0) + rstr = NULL; + } + + if (lstr == NULL) + lstr = RCS_HEAD_INIT; + + if ((lnum = rcsnum_parse(lstr)) == NULL) + fatal("invalid revision %s", lstr); + + if (rstr != NULL) { + if ((rnum = rcsnum_parse(rstr)) == NULL) + fatal("invalid revision %s", rstr); + } else { + rnum = rcsnum_alloc(); + rcsnum_cpy(file->rf_head, rnum, 0); + } + + cvs_argv_destroy(revrange); + + TAILQ_FOREACH(rdp, &(file->rf_delta), rd_list) { + if (rcsnum_cmp(rdp->rd_num, lnum, 0) <= 0 && + rcsnum_cmp(rdp->rd_num, rnum, 0) >= 0 && + !(rdp->rd_flags & RCS_RD_SELECT)) { + rdp->rd_flags |= RCS_RD_SELECT; + nrev++; + } + } + } + + cvs_argv_destroy(revargv); + + if (lnum != NULL) + rcsnum_free(lnum); + if (rnum != NULL) + rcsnum_free(rnum); + + return (nrev); +} diff --git a/usr.bin/cvs/util.h b/usr.bin/cvs/util.h index 352c610e5a2..596078ac7e4 100644 --- a/usr.bin/cvs/util.h +++ b/usr.bin/cvs/util.h @@ -1,4 +1,4 @@ -/* $OpenBSD: util.h,v 1.7 2006/05/28 17:25:18 joris Exp $ */ +/* $OpenBSD: util.h,v 1.8 2006/05/28 21:34:37 joris Exp $ */ /* * Copyright (c) 2006 Niall O'Higgins <niallo@openbsd.org> * All rights reserved. @@ -48,6 +48,8 @@ void cvs_parse_tagfile(char **, char **, int *); size_t cvs_path_cat(const char *, const char *, char *, size_t); time_t cvs_hack_time(time_t, int); +u_int cvs_revision_select(RCSFILE *, char *); + struct cvs_line { char *l_line; int l_lineno; |