summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorJoris Vink <joris@cvs.openbsd.org>2005-10-17 15:33:13 +0000
committerJoris Vink <joris@cvs.openbsd.org>2005-10-17 15:33:13 +0000
commit9839ef3092d5236c710b1b5730a6bb5778aacbd1 (patch)
tree3672884d83fc901876bc145f9bf36514d4efc280 /usr.bin
parent51a7d60f5b621aa7770b479716d6e61db32a8c62 (diff)
support -f flag for co;
'fine' niallo@
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/rcs/ci.c6
-rw-r--r--usr.bin/rcs/co.c68
-rw-r--r--usr.bin/rcs/rcsprog.h4
3 files changed, 57 insertions, 21 deletions
diff --git a/usr.bin/rcs/ci.c b/usr.bin/rcs/ci.c
index a9f48a64c0c..860a457047d 100644
--- a/usr.bin/rcs/ci.c
+++ b/usr.bin/rcs/ci.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ci.c,v 1.40 2005/10/16 23:30:45 niallo Exp $ */
+/* $OpenBSD: ci.c,v 1.41 2005/10/17 15:33:12 joris Exp $ */
/*
* Copyright (c) 2005 Niall O'Higgins <niallo@openbsd.org>
* All rights reserved.
@@ -242,7 +242,7 @@ checkin_main(int argc, char **argv)
(void)unlink(argv[i]);
if (lkmode != 0)
checkout_rev(file, frev, argv[i], lkmode,
- username);
+ username, 0);
rcs_lock_remove(file, frev);
rcs_close(file);
cvs_printf("done\n");
@@ -368,7 +368,7 @@ checkin_main(int argc, char **argv)
* Do checkout if -u or -l are specified.
*/
if (lkmode != 0 && !rflag)
- checkout_rev(file, newrev, argv[i], lkmode, username);
+ checkout_rev(file, newrev, argv[i], lkmode, username, 0);
/* File will NOW be synced */
rcs_close(file);
diff --git a/usr.bin/rcs/co.c b/usr.bin/rcs/co.c
index 70091fab807..0bf353dfe72 100644
--- a/usr.bin/rcs/co.c
+++ b/usr.bin/rcs/co.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: co.c,v 1.17 2005/10/16 15:46:07 joris Exp $ */
+/* $OpenBSD: co.c,v 1.18 2005/10/17 15:33:12 joris Exp $ */
/*
* Copyright (c) 2005 Joris Vink <joris@openbsd.org>
* All rights reserved.
@@ -43,13 +43,13 @@ int
checkout_main(int argc, char **argv)
{
int i, ch;
- int lock;
+ int fflag, lock;
RCSNUM *frev, *rev;
RCSFILE *file;
char fpath[MAXPATHLEN], buf[16];
char *username;
- lock = 0;
+ fflag = lock = 0;
rev = RCS_HEAD_REV;
frev = NULL;
@@ -58,8 +58,20 @@ checkout_main(int argc, char **argv)
exit (1);
}
- while ((ch = rcs_getopt(argc, argv, "l::qr::u::V")) != -1) {
+ while ((ch = rcs_getopt(argc, argv, "f::l::qr::u::V")) != -1) {
switch (ch) {
+ case 'f':
+ if (rev != RCS_HEAD_REV)
+ cvs_log(LP_WARN,
+ "redefinition of revision number");
+ if (rcs_optarg != NULL) {
+ if ((rev = rcsnum_parse(rcs_optarg)) == NULL) {
+ cvs_log(LP_ERR, "bad revision number");
+ exit (1);
+ }
+ }
+ fflag = 1;
+ break;
case 'l':
if (rev != RCS_HEAD_REV)
cvs_log(LP_WARN,
@@ -130,7 +142,7 @@ checkout_main(int argc, char **argv)
rcsnum_tostr(frev, buf, sizeof(buf));
- if (checkout_rev(file, frev, argv[i], lock, username) < 0) {
+ if (checkout_rev(file, frev, argv[i], lock, username, fflag) < 0) {
rcs_close(file);
continue;
}
@@ -162,11 +174,12 @@ checkout_usage(void)
*/
int
checkout_rev(RCSFILE *file, RCSNUM *frev, const char *dst, int lkmode,
- const char *username)
+ const char *username, int force)
{
- char buf[16];
+ char buf[16], yn;
mode_t mode = 0444;
BUF *bp;
+ struct stat st;
/*
* Check out the latest revision if <frev> is greater than HEAD
@@ -176,6 +189,9 @@ checkout_rev(RCSFILE *file, RCSNUM *frev, const char *dst, int lkmode,
rcsnum_tostr(frev, buf, sizeof(buf));
+ if (verbose == 1)
+ printf("revision %s", buf);
+
if ((bp = rcs_getrev(file, frev)) == NULL) {
cvs_log(LP_ERR, "cannot find revision `%s'", buf);
return (-1);
@@ -189,14 +205,41 @@ checkout_rev(RCSFILE *file, RCSNUM *frev, const char *dst, int lkmode,
else
cvs_log(LP_WARN, "you already have a lock");
}
+
mode = 0644;
+ if (verbose == 1)
+ printf(" (locked)");
} 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 (verbose == 1)
+ printf(" (unlocked)");
+ }
+
+ if (verbose == 1)
+ printf("\n");
+
+ if ((stat(dst, &st) != -1) && force == 0) {
+ if (st.st_mode & S_IWUSR) {
+ yn = 0;
+ while (yn != 'y' && yn != 'n') {
+ printf("writeable '%s' exists; ", dst);
+ printf("remove it? [ny] (n):");
+ fflush(stdout);
+ yn = getchar();
+ }
+
+ if (yn == 'n') {
+ if (verbose == 1)
+ cvs_log(LP_ERR, "checkout aborted");
+ return (-1);
+ }
+ }
}
if (cvs_buf_write(bp, dst, mode) < 0) {
@@ -207,15 +250,8 @@ checkout_rev(RCSFILE *file, RCSNUM *frev, const char *dst, int lkmode,
cvs_buf_free(bp);
- if (verbose == 1) {
- cvs_printf("revision %s ", buf);
- if (lkmode == LOCK_LOCK)
- cvs_printf("(locked)");
- else if (lkmode == LOCK_UNLOCK)
- cvs_printf("(unlocked)");
- cvs_printf("\n");
- cvs_printf("done\n");
- }
+ if (verbose == 1)
+ printf("done\n");
return (0);
}
diff --git a/usr.bin/rcs/rcsprog.h b/usr.bin/rcs/rcsprog.h
index 663f0d948ec..fce375dde20 100644
--- a/usr.bin/rcs/rcsprog.h
+++ b/usr.bin/rcs/rcsprog.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcsprog.h,v 1.12 2005/10/15 23:39:36 joris Exp $ */
+/* $OpenBSD: rcsprog.h,v 1.13 2005/10/17 15:33:12 joris Exp $ */
/*
* Copyright (c) 2005 Joris Vink <joris@openbsd.org>
* All rights reserved.
@@ -49,7 +49,7 @@ void (*usage)(void);
int rcs_init(char *, char **, int);
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_rev(RCSFILE *, RCSNUM *, const char *, int, const char *, int);
int checkout_main(int, char **);
int checkin_main(int, char **);
int rcs_main(int, char **);