diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2006-11-09 21:47:53 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2006-11-09 21:47:53 +0000 |
commit | 00607485a32dc10751be769dd226f96c51d1c587 (patch) | |
tree | 9f120b18761aefd026c9be1ee0d6f40c6a8d57e9 | |
parent | 944dbc8ce0241ebc542b6a5cea01de250904fbf1 (diff) |
Simplify stripping of write bits from file mode.
Add support for reusing the checkin message for multiple files, ala GNU
Fix the message when you abort a checkout and the file was not writable.
OK joris@ niallo@
-rw-r--r-- | usr.bin/rcs/ci.c | 30 | ||||
-rw-r--r-- | usr.bin/rcs/co.c | 25 | ||||
-rw-r--r-- | usr.bin/rcs/rcsutil.c | 23 | ||||
-rw-r--r-- | usr.bin/rcs/rcsutil.h | 4 |
4 files changed, 40 insertions, 42 deletions
diff --git a/usr.bin/rcs/ci.c b/usr.bin/rcs/ci.c index 17106f3062b..143d6061476 100644 --- a/usr.bin/rcs/ci.c +++ b/usr.bin/rcs/ci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ci.c,v 1.188 2006/09/27 06:26:35 ray Exp $ */ +/* $OpenBSD: ci.c,v 1.189 2006/11/09 21:47:52 millert Exp $ */ /* * Copyright (c) 2005, 2006 Niall O'Higgins <niallo@openbsd.org> * All rights reserved. @@ -499,9 +499,19 @@ checkin_update(struct checkin_params *pb) } /* If no log message specified, get it interactively. */ - if (pb->flags & INTERACTIVE) - pb->rcs_msg = checkin_getlogmsg(pb->frev, pb->newrev, - pb->flags); + if (pb->flags & INTERACTIVE) { + if (pb->rcs_msg != NULL) { + fprintf(stderr, + "reuse log message of previous file? [yn](y): "); + if (rcs_yesno('y') != 'y') { + xfree(pb->rcs_msg); + pb->rcs_msg = NULL; + } + } + if (pb->rcs_msg == NULL) + pb->rcs_msg = checkin_getlogmsg(pb->frev, pb->newrev, + pb->flags); + } if (rcs_lock_remove(pb->file, pb->username, pb->frev) < 0) { if (rcs_errno != RCS_ERR_NOENT) @@ -551,8 +561,7 @@ checkin_update(struct checkin_params *pb) err(1, "%s", pb->filename); /* Strip all the write bits */ - pb->file->rf_mode = st.st_mode & - (S_IXUSR|S_IXGRP|S_IXOTH|S_IRUSR|S_IRGRP|S_IROTH); + pb->file->rf_mode = st.st_mode & ~(S_IWUSR|S_IWGRP|S_IWOTH); (void)close(workfile_fd); (void)unlink(pb->filename); @@ -565,12 +574,6 @@ checkin_update(struct checkin_params *pb) !(pb->flags & CI_DEFAULT)) checkout_rev(pb->file, pb->newrev, pb->filename, pb->flags, pb->username, pb->author, NULL, NULL); - - if (pb->flags & INTERACTIVE) { - xfree(pb->rcs_msg); - pb->rcs_msg = NULL; - } - out: return (0); @@ -676,8 +679,7 @@ skipdesc: err(1, "%s", pb->filename); /* Strip all the write bits */ - pb->file->rf_mode = st.st_mode & - (S_IXUSR|S_IXGRP|S_IXOTH|S_IRUSR|S_IRGRP|S_IROTH); + pb->file->rf_mode = st.st_mode & ~(S_IWUSR|S_IWGRP|S_IWOTH); (void)close(workfile_fd); (void)unlink(pb->filename); diff --git a/usr.bin/rcs/co.c b/usr.bin/rcs/co.c index ec44738c35f..9e9e07caf31 100644 --- a/usr.bin/rcs/co.c +++ b/usr.bin/rcs/co.c @@ -1,4 +1,4 @@ -/* $OpenBSD: co.c,v 1.98 2006/10/12 17:20:12 niallo Exp $ */ +/* $OpenBSD: co.c,v 1.99 2006/11/09 21:47:52 millert Exp $ */ /* * Copyright (c) 2005 Joris Vink <joris@openbsd.org> * All rights reserved. @@ -235,7 +235,7 @@ checkout_rev(RCSFILE *file, RCSNUM *frev, const char *dst, int flags, u_int i; int fd, lcount; char buf[16]; - mode_t mode = 0444; + mode_t mode = DEFFILEMODE; struct stat st; struct rcs_delta *rdp; struct rcs_lock *lkp; @@ -363,12 +363,8 @@ checkout_rev(RCSFILE *file, RCSNUM *frev, const char *dst, int flags, } } - /* Strip all write bits from mode */ - if (file->rf_fd != -1) { - mode = st.st_mode & - (S_IXUSR|S_IXGRP|S_IXOTH|S_IRUSR|S_IRGRP|S_IROTH); - } - + /* File should only be writable by owner. */ + mode &= ~(S_IWGRP|S_IWOTH); mode |= S_IWUSR; if (file->rf_ndelta != 0) { @@ -385,10 +381,7 @@ checkout_rev(RCSFILE *file, RCSNUM *frev, const char *dst, int flags, } /* Strip all write bits from mode */ - if (file->rf_fd != -1) { - mode = st.st_mode & - (S_IXUSR|S_IXGRP|S_IXOTH|S_IRUSR|S_IRGRP|S_IROTH); - } + mode &= ~(S_IWUSR|S_IWGRP|S_IWOTH); if (file->rf_ndelta != 0) { if (!(flags & QUIET) && !(flags & NEWFILE) && @@ -435,11 +428,11 @@ checkout_rev(RCSFILE *file, RCSNUM *frev, const char *dst, int flags, (getuid() == st.st_uid) ? "" : ", and you do not own it"); (void)fprintf(stderr, "remove it? [ny](n): "); - /* default is n */ - if (rcs_yesno() == -1) { + if (rcs_yesno('n') == 'n') { if (!(flags & QUIET) && isatty(STDIN_FILENO)) - warnx("writable %s exists; " - "checkout aborted", dst); + warnx("%s%s exists; checkout aborted", + (st.st_mode & (S_IWUSR|S_IWGRP|S_IWOTH)) ? + "writable " : "", dst); else warnx("checkout aborted"); return (-1); diff --git a/usr.bin/rcs/rcsutil.c b/usr.bin/rcs/rcsutil.c index 403b5abad55..98b7c8741f2 100644 --- a/usr.bin/rcs/rcsutil.c +++ b/usr.bin/rcs/rcsutil.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rcsutil.c,v 1.22 2006/10/12 17:20:12 niallo Exp $ */ +/* $OpenBSD: rcsutil.c,v 1.23 2006/11/09 21:47:52 millert Exp $ */ /* * Copyright (c) 2005, 2006 Joris Vink <joris@openbsd.org> * Copyright (c) 2006 Xavier Santolaria <xsa@openbsd.org> @@ -562,24 +562,27 @@ rcs_patchfile(BUF *data, BUF *patch, /* * rcs_yesno() * - * Read from standart input for `y' or `Y' character. - * Returns 0 on success, or -1 on failure. + * Read a char from standard input, returns defc if the + * user enters an equivalent to defc, else whatever char + * was entered. Converts input to lower case. */ int -rcs_yesno(void) +rcs_yesno(int defc) { int c, ret; - ret = 0; - fflush(stderr); fflush(stdout); - if ((c = getchar()) != 'y' && c != 'Y') - ret = -1; + if (isalpha(c = getchar())) + c = tolower(c); + if (c == defc || c == '\n' || (c == EOF && feof(stdin))) + ret = defc; else - while (c != EOF && c != '\n') - c = getchar(); + ret = c; + + while (c != EOF && c != '\n') + c = getchar(); return (ret); } diff --git a/usr.bin/rcs/rcsutil.h b/usr.bin/rcs/rcsutil.h index d65e8a4f319..647bafd9917 100644 --- a/usr.bin/rcs/rcsutil.h +++ b/usr.bin/rcs/rcsutil.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rcsutil.h,v 1.8 2006/08/16 07:39:15 ray Exp $ */ +/* $OpenBSD: rcsutil.h,v 1.9 2006/11/09 21:47:52 millert Exp $ */ /* * Copyright (c) 2006 Xavier Santolaria <xsa@openbsd.org> * All rights reserved. @@ -64,7 +64,7 @@ BUF *rcs_patchfile(BUF *, BUF *, int (*p)(struct rcs_lines *, struct rcs_lines *)); struct rcs_lines *rcs_splitlines(BUF *); void rcs_freelines(struct rcs_lines *); -int rcs_yesno(void); +int rcs_yesno(int); struct rcs_argvector *rcs_strsplit(const char *, const char *); void rcs_argv_destroy(struct rcs_argvector *); |