=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/rcs/co.c,v retrieving revision 1.17 retrieving revision 1.18 diff -c -r1.17 -r1.18 *** src/usr.bin/rcs/co.c 2005/10/16 15:46:07 1.17 --- src/usr.bin/rcs/co.c 2005/10/17 15:33:12 1.18 *************** *** 1,4 **** ! /* $OpenBSD: co.c,v 1.17 2005/10/16 15:46:07 joris Exp $ */ /* * Copyright (c) 2005 Joris Vink * All rights reserved. --- 1,4 ---- ! /* $OpenBSD: co.c,v 1.18 2005/10/17 15:33:12 joris Exp $ */ /* * Copyright (c) 2005 Joris Vink * All rights reserved. *************** *** 43,55 **** checkout_main(int argc, char **argv) { int i, ch; ! int lock; RCSNUM *frev, *rev; RCSFILE *file; char fpath[MAXPATHLEN], buf[16]; char *username; ! lock = 0; rev = RCS_HEAD_REV; frev = NULL; --- 43,55 ---- checkout_main(int argc, char **argv) { int i, ch; ! int fflag, lock; RCSNUM *frev, *rev; RCSFILE *file; char fpath[MAXPATHLEN], buf[16]; char *username; ! fflag = lock = 0; rev = RCS_HEAD_REV; frev = NULL; *************** *** 58,65 **** exit (1); } ! while ((ch = rcs_getopt(argc, argv, "l::qr::u::V")) != -1) { switch (ch) { case 'l': if (rev != RCS_HEAD_REV) cvs_log(LP_WARN, --- 58,77 ---- exit (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,136 **** rcsnum_tostr(frev, buf, sizeof(buf)); ! if (checkout_rev(file, frev, argv[i], lock, username) < 0) { rcs_close(file); continue; } --- 142,148 ---- rcsnum_tostr(frev, buf, sizeof(buf)); ! if (checkout_rev(file, frev, argv[i], lock, username, fflag) < 0) { rcs_close(file); continue; } *************** *** 162,172 **** */ int checkout_rev(RCSFILE *file, RCSNUM *frev, const char *dst, int lkmode, ! const char *username) { ! char buf[16]; mode_t mode = 0444; BUF *bp; /* * Check out the latest revision if is greater than HEAD --- 174,185 ---- */ int checkout_rev(RCSFILE *file, RCSNUM *frev, const char *dst, int lkmode, ! const char *username, int force) { ! char buf[16], yn; mode_t mode = 0444; BUF *bp; + struct stat st; /* * Check out the latest revision if is greater than HEAD *************** *** 176,181 **** --- 189,197 ---- 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,204 **** --- 205,247 ---- 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) { cvs_log(LP_ERR, "failed to write revision to file"); cvs_buf_free(bp); *************** *** 207,221 **** 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"); ! } return (0); } --- 250,257 ---- cvs_buf_free(bp); ! if (verbose == 1) ! printf("done\n"); return (0); }