=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/rcs/ci.c,v retrieving revision 1.28 retrieving revision 1.29 diff -c -r1.28 -r1.29 *** src/usr.bin/rcs/ci.c 2005/10/15 18:26:24 1.28 --- src/usr.bin/rcs/ci.c 2005/10/15 19:45:23 1.29 *************** *** 1,4 **** ! /* $OpenBSD: ci.c,v 1.28 2005/10/15 18:26:24 niallo Exp $ */ /* * Copyright (c) 2005 Niall O'Higgins * All rights reserved. --- 1,4 ---- ! /* $OpenBSD: ci.c,v 1.29 2005/10/15 19:45:23 niallo Exp $ */ /* * Copyright (c) 2005 Niall O'Higgins * All rights reserved. *************** *** 51,64 **** #define DATE_MTIME -2 static char * checkin_diff_file(RCSFILE *, RCSNUM *, const char *); ! static char * checkin_getlogmsg(char *, char *, RCSNUM *, RCSNUM *); void checkin_usage(void) { fprintf(stderr, ! "usage: ci [-jMNqV] [-d [date]] [-k mode] [-l [rev]] [-m msg]\n" ! " [-r [rev]] [-u [rev]] file ...\n"); } /* --- 51,64 ---- #define DATE_MTIME -2 static char * checkin_diff_file(RCSFILE *, RCSNUM *, const char *); ! static char * checkin_getlogmsg(char *, RCSNUM *, RCSNUM *); void checkin_usage(void) { fprintf(stderr, ! "usage: ci [-jMNqV] [-d[date]] [-f[rev]] [-kmode] [-l[rev]]\n" ! " [-mmsg] [-r[rev]] [-u[rev]] file ...\n"); } /* *************** *** 70,76 **** int checkin_main(int argc, char **argv) { ! int i, ch, flags, lkmode, interactive, rflag, status; mode_t fmode; time_t date; RCSFILE *file; --- 70,76 ---- int checkin_main(int argc, char **argv) { ! int i, ch, flags, force, lkmode, interactive, rflag, status; mode_t fmode; time_t date; RCSFILE *file; *************** *** 85,91 **** file = NULL; rcs_msg = NULL; newrev = NULL; ! fmode = lkmode = verbose = rflag = status = 0; interactive = 1; if ((username = getlogin()) == NULL) { --- 85,91 ---- file = NULL; rcs_msg = NULL; newrev = NULL; ! fmode = force = lkmode = verbose = rflag = status = 0; interactive = 1; if ((username = getlogin()) == NULL) { *************** *** 93,99 **** exit(1); } ! while ((ch = rcs_getopt(argc, argv, "j:l::M:N:qu::d::r::m:k:V")) != -1) { switch (ch) { case 'd': if (rcs_optarg == NULL) --- 93,99 ---- exit(1); } ! while ((ch = rcs_getopt(argc, argv, "f::j:l::M:N:qu::d::r::m:k:V")) != -1) { switch (ch) { case 'd': if (rcs_optarg == NULL) *************** *** 103,108 **** --- 103,117 ---- exit(1); } break; + case 'f': + if (rcs_optarg != NULL) { + if ((newrev = rcsnum_parse(rcs_optarg)) == NULL) { + cvs_log(LP_ERR, "bad revision number"); + exit(1); + } + } + force = 1; + break; case 'h': (usage)(); exit(0); *************** *** 167,177 **** --- 176,189 ---- cvs_log(LP_ERR, "failed to open rcsfile '%s'", fpath); exit(1); } + /* * If rev is not specified on the command line, * assume HEAD. */ frev = file->rf_head; + cvs_printf("%s <-- %s\n", fpath, argv[i]); + /* * If revision passed on command line is less than HEAD, bail. */ *************** *** 196,201 **** --- 208,239 ---- filec = (char *)cvs_buf_release(bp); /* + * Get RCS patch + */ + if ((deltatext = checkin_diff_file(file, frev, argv[i])) == NULL) { + cvs_log(LP_ERR, "failed to get diff"); + exit(1); + } + + /* + * If -f is not specified and there are no differences, tell the + * user and revert to latest version. + */ + if ((!force) && (strlen(deltatext) < 1)) { + char buf[16]; + rcsnum_tostr(frev, buf, sizeof(buf)); + cvs_log(LP_WARN, + "file is unchanged; reverting to previous revision %s", + buf); + (void)unlink(argv[i]); + if (lkmode != 0) + checkout_rev(file, frev, argv[i], lkmode, username); + rcs_close(file); + cvs_printf("done\n"); + continue; + } + + /* * Check for a lock belonging to this user. If none, * abort check-in. */ *************** *** 203,208 **** --- 241,247 ---- cvs_log(LP_ERR, "%s: no lock set by %s", fpath, username); status = 1; + rcs_close(file); continue; } else { TAILQ_FOREACH(lkp, &(file->rf_locks), rl_list) { *************** *** 212,217 **** --- 251,257 ---- "%s: no lock set by %s", fpath, username); status = 1; + rcs_close(file); continue; } } *************** *** 221,227 **** * If no log message specified, get it interactively. */ if (rcs_msg == NULL) ! rcs_msg = checkin_getlogmsg(fpath, argv[i], frev, newrev); /* * Remove the lock --- 261,267 ---- * If no log message specified, get it interactively. */ if (rcs_msg == NULL) ! rcs_msg = checkin_getlogmsg(fpath, frev, newrev); /* * Remove the lock *************** *** 232,245 **** } /* - * Get RCS patch - */ - if ((deltatext = checkin_diff_file(file, frev, argv[i])) == NULL) { - cvs_log(LP_ERR, "failed to get diff"); - exit(1); - } - - /* * Current head revision gets the RCS patch as rd_text */ if (rcs_deltatext_set(file, frev, deltatext) == -1) { --- 272,277 ---- *************** *** 253,259 **** */ if (date == DATE_MTIME) { struct stat sb; - tzset(); if (stat(argv[i], &sb) != 0) { cvs_log(LP_ERRNO, "failed to stat: `%s'", argv[i]); rcs_close(file); --- 285,290 ---- *************** *** 367,373 **** * Get log message from user interactively. */ static char * ! checkin_getlogmsg(char *rcsfile, char *workingfile, RCSNUM *rev, RCSNUM *rev2) { char *rcs_msg, buf[128], nrev[16], prev[16]; BUF *logbuf; --- 398,404 ---- * Get log message from user interactively. */ static char * ! checkin_getlogmsg(char *rcsfile, RCSNUM *rev, RCSNUM *rev2) { char *rcs_msg, buf[128], nrev[16], prev[16]; BUF *logbuf; *************** *** 387,393 **** cvs_log(LP_ERR, "failed to allocate log buffer"); return (NULL); } - cvs_printf("%s <-- %s\n", rcsfile, workingfile); cvs_printf("new revision: %s; previous revision: %s\n", nrev, prev); cvs_printf("enter log message, terminated with single " "'.' or end of file:\n"); --- 418,423 ----