summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorNiall O'Higgins <niallo@cvs.openbsd.org>2005-10-15 18:26:25 +0000
committerNiall O'Higgins <niallo@cvs.openbsd.org>2005-10-15 18:26:25 +0000
commitea9a8b68b4d0303dbe4709462ab6801b42082163 (patch)
tree945fcbbefcf44ead2619def456599aca57fd855c /usr.bin
parent18cfee2de0d3e90d67fe415d031e6f810cb27f0d (diff)
modularise checkout code into checkout_rev(). this shaves off a number
of lines in ci.c due to code re-use, and will simplify features which are in the pipeline. no functional changes. ok joris@
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/rcs/ci.c31
-rw-r--r--usr.bin/rcs/co.c92
-rw-r--r--usr.bin/rcs/rcsprog.h3
3 files changed, 63 insertions, 63 deletions
diff --git a/usr.bin/rcs/ci.c b/usr.bin/rcs/ci.c
index 1c7cd67d58b..854daec1bd9 100644
--- a/usr.bin/rcs/ci.c
+++ b/usr.bin/rcs/ci.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ci.c,v 1.27 2005/10/15 14:23:06 niallo Exp $ */
+/* $OpenBSD: ci.c,v 1.28 2005/10/15 18:26:24 niallo Exp $ */
/*
* Copyright (c) 2005 Niall O'Higgins <niallo@openbsd.org>
* All rights reserved.
@@ -293,32 +293,9 @@ checkin_main(int argc, char **argv)
/*
* Do checkout if -u or -l are specified.
*/
- if (lkmode != 0 && !rflag) {
- mode_t mode = 0;
- if ((bp = rcs_getrev(file, newrev)) == NULL) {
- cvs_log(LP_ERR, "cannot get revision");
- goto err;
- }
- if (lkmode == LOCK_LOCK) {
- mode = 0644;
- if (rcs_lock_add(file, username, newrev) < 0) {
- if (rcs_errno != RCS_ERR_DUPENT)
- cvs_log(LP_ERR,
- "failed to lock revision");
- else
- cvs_log(LP_ERR,
- "you already have a lock");
- }
- } else if (lkmode == LOCK_UNLOCK) {
- mode = 0444;
- }
- if (cvs_buf_write(bp, argv[i], mode) < 0) {
- cvs_log(LP_ERR,
- "failed to write revision to file");
- }
- cvs_buf_free(bp);
- }
-err:
+ if (lkmode != 0 && !rflag)
+ checkout_rev(file, newrev, argv[i], lkmode, username);
+
/* File will NOW be synced */
rcs_close(file);
diff --git a/usr.bin/rcs/co.c b/usr.bin/rcs/co.c
index a2cb90d9024..ff654df3228 100644
--- a/usr.bin/rcs/co.c
+++ b/usr.bin/rcs/co.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: co.c,v 1.13 2005/10/13 12:35:30 joris Exp $ */
+/* $OpenBSD: co.c,v 1.14 2005/10/15 18:26:24 niallo Exp $ */
/*
* Copyright (c) 2005 Joris Vink <joris@openbsd.org>
* All rights reserved.
@@ -46,11 +46,8 @@ checkout_main(int argc, char **argv)
int lock;
RCSNUM *frev, *rev;
RCSFILE *file;
- BUF *bp;
- char buf[16];
- char fpath[MAXPATHLEN];
+ char fpath[MAXPATHLEN], buf[16];
char *username;
- mode_t mode = 0444;
lock = 0;
rev = RCS_HEAD_REV;
@@ -130,40 +127,11 @@ checkout_main(int argc, char **argv)
frev = file->rf_head;
else
frev = rev;
-
rcsnum_tostr(frev, buf, sizeof(buf));
-
- if ((bp = rcs_getrev(file, frev)) == NULL) {
- cvs_log(LP_ERR, "cannot find '%s' in %s", buf, fpath);
+ if (checkout_rev(file, frev, argv[i], lock, username) < 0) {
rcs_close(file);
continue;
}
-
- if (lock == LOCK_LOCK) {
- if (rcs_lock_add(file, username, frev) < 0) {
- if (rcs_errno != RCS_ERR_DUPENT)
- cvs_log(LP_ERR, "failed to lock '%s'", buf);
- else
- cvs_log(LP_WARN, "you already have a lock");
- }
- mode = 0644;
- } else if (lock == LOCK_UNLOCK) {
- if (rcs_lock_remove(file, frev) < 0) {
- if (rcs_errno != RCS_ERR_NOENT)
- cvs_log(LP_ERR,
- "failed to remove lock '%s'", buf);
- }
- mode = 0444;
- }
- if (cvs_buf_write(bp, argv[i], mode) < 0) {
- cvs_log(LP_ERR, "failed to write revision to file");
- cvs_buf_free(bp);
- rcs_close(file);
- continue;
- }
-
- cvs_buf_free(bp);
-
rcs_close(file);
if (verbose == 1) {
printf("revision %s ", buf);
@@ -188,3 +156,57 @@ checkout_usage(void)
fprintf(stderr,
"usage: co [-qV] [-l [rev]] [-r [rev]] [-u [rev]] file ...\n");
}
+
+/*
+ * Checkout revision <rev> from RCSFILE <file>, writing it to the path <dst>
+ * <lkmode> is either LOCK_LOCK or LOCK_UNLOCK or something else
+ * (which has no effect).
+ * In the case of LOCK_LOCK, a lock is set for <username> if it is not NULL.
+ * In the case of LOCK_UNLOCK, all locks are removed for that revision.
+ *
+ * Returns 0 on success, -1 on failure.
+ */
+int
+checkout_rev(RCSFILE *file, RCSNUM *frev, const char *dst, int lkmode,
+ const char *username)
+{
+ char buf[16];
+ mode_t mode = 0444;
+ BUF *bp;
+ rcsnum_tostr(frev, buf, sizeof(buf));
+
+ /*
+ * XXX: GNU RCS will check out the latest revision if <frev> is
+ * greater than HEAD
+ */
+ if ((bp = rcs_getrev(file, frev)) == NULL) {
+ cvs_log(LP_ERR, "cannot find revision `%s'", buf);
+ return (-1);
+ }
+
+ if (lkmode == LOCK_LOCK) {
+ if ((username != NULL)
+ && (rcs_lock_add(file, username, frev) < 0)) {
+ if (rcs_errno != RCS_ERR_DUPENT)
+ cvs_log(LP_ERR, "failed to lock '%s'", buf);
+ else
+ cvs_log(LP_WARN, "you already have a lock");
+ }
+ mode = 0644;
+ } else if (lkmode == LOCK_UNLOCK) {
+ if (rcs_lock_remove(file, frev) < 0) {
+ if (rcs_errno != RCS_ERR_NOENT)
+ cvs_log(LP_ERR,
+ "failed to remove lock '%s'", buf);
+ }
+ mode = 0444;
+ }
+ if (cvs_buf_write(bp, dst, mode) < 0) {
+ cvs_log(LP_ERR, "failed to write revision to file");
+ cvs_buf_free(bp);
+ return (-1);
+ }
+ cvs_buf_free(bp);
+ return (0);
+}
+
diff --git a/usr.bin/rcs/rcsprog.h b/usr.bin/rcs/rcsprog.h
index 8eacd0d9290..27e8ece22f4 100644
--- a/usr.bin/rcs/rcsprog.h
+++ b/usr.bin/rcs/rcsprog.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcsprog.h,v 1.10 2005/10/13 12:35:30 joris Exp $ */
+/* $OpenBSD: rcsprog.h,v 1.11 2005/10/15 18:26:24 niallo Exp $ */
/*
* Copyright (c) 2005 Joris Vink <joris@openbsd.org>
* All rights reserved.
@@ -48,6 +48,7 @@ void (*usage)(void);
int rcs_getopt(int, char **, const char *);
int rcs_statfile(char *, char *, size_t);
+int checkout_rev(RCSFILE *, RCSNUM *, const char *, int, const char *);
int checkout_main(int, char **);
int checkin_main(int, char **);
int rcs_main(int, char **);