Annotation of src/usr.bin/rcs/ci.c, Revision 1.62
1.62 ! niallo 1: /* $OpenBSD: ci.c,v 1.61 2005/11/17 00:16:35 niallo Exp $ */
1.1 niallo 2: /*
3: * Copyright (c) 2005 Niall O'Higgins <niallo@openbsd.org>
4: * All rights reserved.
5: *
6: * Redistribution and use in source and binary forms, with or without
7: * modification, are permitted provided that the following cinditions
8: * are met:
9: *
10: * 1. Redistributions of source cide must retain the above cipyright
11: * notice, this list of cinditions and the following disclaimer.
12: * 2. The name of the author may not be used to endorse or promote products
13: * derived from this software without specific prior written permission.
14: *
15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16: * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17: * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18: * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25: */
26:
27: #include <sys/param.h>
28: #include <sys/types.h>
29: #include <sys/stat.h>
30: #include <sys/wait.h>
31:
32: #include <err.h>
33: #include <pwd.h>
34: #include <errno.h>
35: #include <stdio.h>
36: #include <ctype.h>
37: #include <stdlib.h>
38: #include <unistd.h>
39: #include <string.h>
1.20 niallo 40: #include <time.h>
1.1 niallo 41:
42: #include "log.h"
43: #include "rcs.h"
1.4 niallo 44: #include "diff.h"
1.1 niallo 45: #include "rcsprog.h"
1.9 niallo 46:
1.58 niallo 47: #define CI_OPTSTRING "d::f::i::j::k:l::m:M::N:n:qr::s:u::Vw:"
1.25 niallo 48: #define DATE_NOW -1
49: #define DATE_MTIME -2
50:
1.58 niallo 51: #define LOG_INIT "Initial revision"
52: #define LOG_PROMPT "enter log message, terminated with a single '.' " \
53: "or end of file:\n>> "
54: #define DESC_PROMPT "enter description, terminated with single '.' " \
55: "or end of file:\nNOTE: This is NOT the log message!\n"
56:
57: struct checkin_params {
58: int flags, openflags;
59: mode_t fmode;
60: time_t date;
61: RCSFILE *file;
62: RCSNUM *frev, *newrev;
63: char fpath[MAXPATHLEN], *rcs_msg, *username, *deltatext, *filename;
64: const char *symbol, *state;
65: };
66:
67: static int checkin_attach_symbol(struct checkin_params *pb);
68: static int checkin_checklock(struct checkin_params *pb);
69: static char * checkin_diff_file(struct checkin_params *);
70: static char * checkin_getdesc(void);
71: static char * checkin_getinput(const char *);
1.34 niallo 72: static char * checkin_getlogmsg(RCSNUM *, RCSNUM *);
1.58 niallo 73: static void checkin_init(struct checkin_params *);
74: static void checkin_revert(struct checkin_params *pb);
1.62 ! niallo 75: static int checkin_mtimedate(struct checkin_params *pb);
1.4 niallo 76:
1.1 niallo 77: void
78: checkin_usage(void)
79: {
80: fprintf(stderr,
1.58 niallo 81: "usage: ci [-MNqV] [-d[date]] [-f[rev]] [-i[rev]] [-j[rev]]\n"
82: " [-kmode] [-l[rev]] [-M[rev]] [-mmsg] [-Nsymbol]\n"
83: " [-nsymbol] [-r[rev]] [-sstate] [-u[rev]] [-wusername]\n"
84: " file ...\n");
85: }
86:
1.55 niallo 87:
1.1 niallo 88:
89: /*
90: * checkin_main()
91: *
92: * Handler for the `ci' program.
93: * Returns 0 on success, or >0 on error.
94: */
95: int
96: checkin_main(int argc, char **argv)
97: {
1.58 niallo 98: int i, ch, status;
99: char *filec;
100: struct stat sb;
101: struct checkin_params pb;
1.4 niallo 102: BUF *bp;
1.1 niallo 103:
1.58 niallo 104: pb.date = DATE_NOW;
105: pb.file = NULL;
106: pb.rcs_msg = pb.username = NULL;
107: pb.state = pb.symbol = NULL;
108: pb.newrev = NULL;
109: pb.fmode = pb.flags = status = 0;
1.1 niallo 110:
1.58 niallo 111: pb.flags = INTERACTIVE;
112: pb.openflags = RCS_RDWR|RCS_CREATE;
1.9 niallo 113:
1.58 niallo 114: while ((ch = rcs_getopt(argc, argv, CI_OPTSTRING)) != -1) {
1.1 niallo 115: switch (ch) {
1.20 niallo 116: case 'd':
1.25 niallo 117: if (rcs_optarg == NULL)
1.58 niallo 118: pb.date = DATE_MTIME;
119: else if ((pb.date = cvs_date_parse(rcs_optarg)) <= 0) {
1.20 niallo 120: cvs_log(LP_ERR, "invalide date");
121: exit(1);
122: }
123: break;
1.29 niallo 124: case 'f':
1.58 niallo 125: rcs_set_rev(rcs_optarg, &pb.newrev);
126: pb.flags |= FORCE;
1.29 niallo 127: break;
1.1 niallo 128: case 'h':
129: (usage)();
130: exit(0);
1.58 niallo 131: case 'i':
132: rcs_set_rev(rcs_optarg, &pb.newrev);
133: pb.openflags |= RCS_CREATE;
134: break;
135: case 'j':
136: rcs_set_rev(rcs_optarg, &pb.newrev);
137: pb.openflags &= ~RCS_CREATE;
138: break;
1.30 niallo 139: case 'l':
1.58 niallo 140: rcs_set_rev(rcs_optarg, &pb.newrev);
141: pb.flags |= CO_LOCK;
1.54 niallo 142: break;
143: case 'M':
1.58 niallo 144: rcs_set_rev(rcs_optarg, &pb.newrev);
145: pb.flags |= CO_REVDATE;
1.30 niallo 146: break;
1.1 niallo 147: case 'm':
1.58 niallo 148: pb.rcs_msg = rcs_optarg;
149: if (pb.rcs_msg == NULL) {
150: cvs_log(LP_ERR,
151: "missing message for -m option");
152: exit(1);
153: }
154: pb.flags &= ~INTERACTIVE;
1.3 joris 155: break;
1.42 niallo 156: case 'N':
1.58 niallo 157: if ((pb.symbol = strdup(rcs_optarg)) == NULL) {
1.42 niallo 158: cvs_log(LP_ERRNO, "out of memory");
159: exit(1);
160: }
1.58 niallo 161: if (rcs_sym_check(pb.symbol) != 1) {
162: cvs_log(LP_ERR, "invalid symbol `%s'",
163: pb.symbol);
1.42 niallo 164: exit(1);
165: }
1.58 niallo 166: pb.flags |= CI_SYMFORCE;
1.42 niallo 167: break;
1.38 niallo 168: case 'n':
1.58 niallo 169: if ((pb.symbol = strdup(rcs_optarg)) == NULL) {
1.38 niallo 170: cvs_log(LP_ERRNO, "out of memory");
171: exit(1);
172: }
1.58 niallo 173: if (rcs_sym_check(pb.symbol) != 1) {
174: cvs_log(LP_ERR, "invalid symbol `%s'",
175: pb.symbol);
1.38 niallo 176: exit(1);
177: }
178: break;
1.3 joris 179: case 'q':
180: verbose = 0;
1.1 niallo 181: break;
1.30 niallo 182: case 'r':
1.58 niallo 183: rcs_set_rev(rcs_optarg, &pb.newrev);
184: pb.flags |= CI_DEFAULT;
1.9 niallo 185: break;
1.51 niallo 186: case 's':
1.58 niallo 187: pb.state = rcs_optarg;
188: if (rcs_state_check(pb.state) < 0) {
189: cvs_log(LP_ERR, "invalid state `%s'",
190: pb.state);
1.51 niallo 191: exit(1);
192: }
193: break;
1.9 niallo 194: case 'u':
1.58 niallo 195: rcs_set_rev(rcs_optarg, &pb.newrev);
196: pb.flags |= CO_UNLOCK;
1.9 niallo 197: break;
1.30 niallo 198: case 'V':
199: printf("%s\n", rcs_version);
200: exit(0);
1.31 niallo 201: case 'w':
1.58 niallo 202: pb.username = rcs_optarg;
1.31 niallo 203: break;
1.1 niallo 204: default:
205: (usage)();
206: exit(1);
207: }
208: }
209:
1.24 joris 210: argc -= rcs_optind;
211: argv += rcs_optind;
212:
1.1 niallo 213: if (argc == 0) {
214: cvs_log(LP_ERR, "no input file");
215: (usage)();
216: exit(1);
217: }
218:
1.58 niallo 219: if ((pb.username == NULL) && (pb.username = getlogin()) == NULL) {
1.31 niallo 220: cvs_log(LP_ERRNO, "failed to get username");
221: exit(1);
222: }
223:
224:
1.1 niallo 225: for (i = 0; i < argc; i++) {
1.58 niallo 226: pb.filename = argv[i];
227: if (rcs_statfile(pb.filename, pb.fpath, sizeof(pb.fpath)) < 0)
1.1 niallo 228: continue;
229:
1.58 niallo 230: /*
231: * Test for existence of ,v file. If we are expected to
232: * create one, set NEWFILE flag.
233: */
234: if ((pb.openflags & RCS_CREATE) && (stat(pb.fpath, &sb) < 0))
235: pb.flags |= NEWFILE;
236: else
237: pb.openflags &= ~RCS_CREATE;
238:
239: pb.file = rcs_open(pb.fpath, pb.openflags, pb.fmode);
240:
241: if (pb.file == NULL) {
1.60 niallo 242: cvs_log(LP_ERR, "failed to open rcsfile '%s'",
243: pb.fpath);
1.1 niallo 244: exit(1);
245: }
1.29 niallo 246:
1.58 niallo 247: if (verbose == 1)
248: printf("%s <-- %s\n", pb.fpath, pb.filename);
1.36 niallo 249:
1.58 niallo 250: pb.frev = pb.file->rf_head;
1.29 niallo 251:
1.17 niallo 252: /*
253: * If revision passed on command line is less than HEAD, bail.
254: */
1.58 niallo 255: if ((pb.newrev != NULL)
256: && (rcsnum_cmp(pb.newrev, pb.frev, 0) > 0)) {
1.17 niallo 257: cvs_log(LP_ERR, "revision is too low!");
258: status = 1;
1.58 niallo 259: rcs_close(pb.file);
1.17 niallo 260: continue;
261: }
1.4 niallo 262:
263: /*
264: * Load file contents
265: */
266: if ((bp = cvs_buf_load(argv[i], BUF_AUTOEXT)) == NULL) {
1.58 niallo 267: cvs_log(LP_ERR, "failed to load '%s'", pb.filename);
1.4 niallo 268: exit(1);
269: }
270:
1.12 niallo 271: if (cvs_buf_putc(bp, '\0') < 0)
272: exit(1);
273:
1.23 niallo 274: filec = (char *)cvs_buf_release(bp);
1.13 joris 275:
1.6 niallo 276: /*
1.29 niallo 277: * Get RCS patch
278: */
1.58 niallo 279: if ((pb.deltatext = checkin_diff_file(&pb)) == NULL) {
1.29 niallo 280: cvs_log(LP_ERR, "failed to get diff");
281: exit(1);
282: }
283:
284: /*
1.58 niallo 285: * If -f is not specified and there are no differences, tell
286: * the user and revert to latest version.
1.29 niallo 287: */
1.58 niallo 288: if (!(pb.flags & FORCE) && (strlen(pb.deltatext) < 1)) {
289: checkin_revert(&pb);
1.29 niallo 290: continue;
291: }
292:
293: /*
1.16 niallo 294: * Check for a lock belonging to this user. If none,
295: * abort check-in.
296: */
1.58 niallo 297: if (checkin_checklock(&pb) < 0) {
1.16 niallo 298: status = 1;
299: continue;
300: }
301:
302: /*
1.6 niallo 303: * If no log message specified, get it interactively.
304: */
1.58 niallo 305: if (pb.flags & INTERACTIVE)
306: pb.rcs_msg = checkin_getlogmsg(pb.frev, pb.newrev);
1.4 niallo 307:
308: /*
309: * Remove the lock
310: */
1.58 niallo 311: if (rcs_lock_remove(pb.file, pb.frev) < 0) {
1.4 niallo 312: if (rcs_errno != RCS_ERR_NOENT)
313: cvs_log(LP_WARN, "failed to remove lock");
314: }
315:
316: /*
317: * Current head revision gets the RCS patch as rd_text
318: */
1.58 niallo 319: if (rcs_deltatext_set(pb.file, pb.frev, pb.deltatext) == -1) {
1.7 niallo 320: cvs_log(LP_ERR,
321: "failed to set new rd_text for head rev");
1.4 niallo 322: exit (1);
1.25 niallo 323: }
1.32 joris 324:
1.25 niallo 325: /*
1.58 niallo 326: * Set the date of the revision to be the last modification
327: * time of the working file if -d has no argument.
1.25 niallo 328: */
1.61 niallo 329: if (pb.date == DATE_MTIME
1.62 ! niallo 330: && (checkin_mtimedate(&pb) < 0))
1.61 niallo 331: continue;
332:
1.32 joris 333:
1.4 niallo 334: /*
335: * Now add our new revision
336: */
1.58 niallo 337: if (rcs_rev_add(pb.file,
338: (pb.newrev == NULL ? RCS_HEAD_REV : pb.newrev),
339: pb.rcs_msg, pb.date, pb.username) != 0) {
1.4 niallo 340: cvs_log(LP_ERR, "failed to add new revision");
341: exit(1);
342: }
343:
344: /*
1.12 niallo 345: * If we are checking in to a non-default (ie user-specified)
346: * revision, set head to this revision.
347: */
1.58 niallo 348: if (pb.newrev != NULL)
349: rcs_head_set(pb.file, pb.newrev);
1.15 niallo 350: else
1.58 niallo 351: pb.newrev = pb.file->rf_head;
1.32 joris 352:
1.12 niallo 353: /*
1.4 niallo 354: * New head revision has to contain entire file;
355: */
1.58 niallo 356: if (rcs_deltatext_set(pb.file, pb.frev, filec) == -1) {
1.4 niallo 357: cvs_log(LP_ERR, "failed to set new head revision");
358: exit(1);
1.38 niallo 359: }
360:
361: /*
362: * Attach a symbolic name to this revision if specified.
363: */
1.58 niallo 364: if (pb.symbol != NULL
365: && (checkin_attach_symbol(&pb) < 0)) {
366: status = 1;
367: continue;
1.4 niallo 368: }
1.51 niallo 369:
370: /*
371: * Set the state of this revision if specified.
372: */
1.58 niallo 373: if (pb.state != NULL)
374: (void)rcs_state_set(pb.file, pb.newrev, pb.state);
1.4 niallo 375:
1.58 niallo 376: free(pb.deltatext);
1.4 niallo 377: free(filec);
1.58 niallo 378: (void)unlink(pb.filename);
1.4 niallo 379:
1.9 niallo 380: /*
381: * Do checkout if -u or -l are specified.
382: */
1.58 niallo 383: if (((pb.flags & CO_LOCK) || (pb.flags & CO_UNLOCK))
384: && !(pb.flags & CI_DEFAULT))
385: checkout_rev(pb.file, pb.newrev, pb.filename, pb.flags,
386: pb.username);
1.28 niallo 387:
1.4 niallo 388: /* File will NOW be synced */
1.58 niallo 389: rcs_close(pb.file);
1.4 niallo 390:
1.58 niallo 391: if (pb.flags & INTERACTIVE) {
392: free(pb.rcs_msg);
393: pb.rcs_msg = NULL;
1.6 niallo 394: }
1.4 niallo 395: }
396:
1.16 niallo 397: return (status);
1.4 niallo 398: }
399:
1.59 niallo 400: /*
401: * checkin_diff_file()
402: *
403: * Generate the diff between the working file and a revision.
404: * Returns pointer to a char array on success, NULL on failure.
405: */
1.4 niallo 406: static char *
1.58 niallo 407: checkin_diff_file(struct checkin_params *pb)
1.4 niallo 408: {
409: char path1[MAXPATHLEN], path2[MAXPATHLEN];
410: BUF *b1, *b2, *b3;
411: char rbuf[64], *deltatext;
412:
1.58 niallo 413: rcsnum_tostr(pb->frev, rbuf, sizeof(rbuf));
1.4 niallo 414:
1.58 niallo 415: if ((b1 = cvs_buf_load(pb->filename, BUF_AUTOEXT)) == NULL) {
416: cvs_log(LP_ERR, "failed to load file: '%s'", pb->filename);
1.4 niallo 417: return (NULL);
1.1 niallo 418: }
419:
1.58 niallo 420: if ((b2 = rcs_getrev(pb->file, pb->frev)) == NULL) {
1.4 niallo 421: cvs_log(LP_ERR, "failed to load revision");
422: cvs_buf_free(b1);
423: return (NULL);
424: }
425:
1.57 xsa 426: if ((b3 = cvs_buf_alloc((size_t)128, BUF_AUTOEXT)) == NULL) {
1.4 niallo 427: cvs_log(LP_ERR, "failed to allocated buffer for diff");
428: cvs_buf_free(b1);
429: cvs_buf_free(b2);
430: return (NULL);
431: }
432:
1.50 xsa 433: strlcpy(path1, rcs_tmpdir, sizeof(path1));
434: strlcat(path1, "/diff1.XXXXXXXXXX", sizeof(path1));
1.4 niallo 435: if (cvs_buf_write_stmp(b1, path1, 0600) == -1) {
436: cvs_log(LP_ERRNO, "could not write temporary file");
437: cvs_buf_free(b1);
438: cvs_buf_free(b2);
439: return (NULL);
440: }
441: cvs_buf_free(b1);
442:
1.50 xsa 443: strlcpy(path2, rcs_tmpdir, sizeof(path2));
444: strlcat(path2, "/diff2.XXXXXXXXXX", sizeof(path2));
1.4 niallo 445: if (cvs_buf_write_stmp(b2, path2, 0600) == -1) {
446: cvs_buf_free(b2);
447: (void)unlink(path1);
448: return (NULL);
449: }
450: cvs_buf_free(b2);
451:
1.5 niallo 452: diff_format = D_RCSDIFF;
1.4 niallo 453: cvs_diffreg(path1, path2, b3);
454: (void)unlink(path1);
455: (void)unlink(path2);
456:
457: cvs_buf_putc(b3, '\0');
458: deltatext = (char *)cvs_buf_release(b3);
459:
460: return (deltatext);
1.6 niallo 461: }
462:
463: /*
1.59 niallo 464: * checkin_getlogmsg()
465: *
1.6 niallo 466: * Get log message from user interactively.
1.59 niallo 467: * Returns pointer to a char array on success, NULL on failure.
1.6 niallo 468: */
469: static char *
1.34 niallo 470: checkin_getlogmsg(RCSNUM *rev, RCSNUM *rev2)
1.6 niallo 471: {
1.58 niallo 472: char *rcs_msg, nrev[16], prev[16];
1.6 niallo 473: RCSNUM *tmprev;
474:
1.7 niallo 475: rcs_msg = NULL;
1.6 niallo 476: tmprev = rcsnum_alloc();
477: rcsnum_cpy(rev, tmprev, 16);
1.9 niallo 478: rcsnum_tostr(tmprev, prev, sizeof(prev));
1.12 niallo 479: if (rev2 == NULL)
480: rcsnum_tostr(rcsnum_inc(tmprev), nrev, sizeof(nrev));
481: else
482: rcsnum_tostr(rev2, nrev, sizeof(nrev));
1.6 niallo 483: rcsnum_free(tmprev);
484:
1.47 niallo 485: if (verbose == 1)
486: printf("new revision: %s; previous revision: %s\n", nrev,
487: prev);
1.32 joris 488:
1.58 niallo 489: rcs_msg = checkin_getinput(LOG_PROMPT);
490: return (rcs_msg);
491: }
492:
493:
494: /*
495: * checkin_getdesc()
496: *
497: * Get file description interactively.
1.59 niallo 498: * Returns pointer to a char array on success, NULL on failure.
1.58 niallo 499: */
500: static char *
501: checkin_getdesc()
502: {
503: char *description;
504:
505: description = checkin_getinput(DESC_PROMPT);
506: return (description);
507: }
508:
509: /*
510: * checkin_getinput()
511: *
1.59 niallo 512: * Get some input from the user, in RCS style, prompting with message <prompt>.
513: * Returns pointer to a char array on success, NULL on failure.
1.58 niallo 514: */
515: static char *
516: checkin_getinput(const char *prompt)
517: {
518: BUF *inputbuf;
519: char *input, buf[128];
520:
521: if ((inputbuf = cvs_buf_alloc((size_t)64, BUF_AUTOEXT)) == NULL) {
522: cvs_log(LP_ERR, "failed to allocate input buffer");
523: return (NULL);
524: }
525:
526: printf(prompt);
1.6 niallo 527: for (;;) {
528: fgets(buf, (int)sizeof(buf), stdin);
1.9 niallo 529: if (feof(stdin) || ferror(stdin) || buf[0] == '.')
1.6 niallo 530: break;
1.58 niallo 531: cvs_buf_append(inputbuf, buf, strlen(buf));
1.46 joris 532: printf(">> ");
1.6 niallo 533: }
1.32 joris 534:
1.58 niallo 535: cvs_buf_putc(inputbuf, '\0');
536: input = (char *)cvs_buf_release(inputbuf);
537:
538: return (input);
539: }
540:
541: /*
542: * checkin_init()
543: *
544: * Does an initial check in, just enough to create the new ,v file
1.60 niallo 545: * XXX not fully implemented yet.
1.58 niallo 546: */
547: static void
548: checkin_init(struct checkin_params *pb)
549: {
550: BUF *bp;
551: char *rcs_desc, *filec;
552:
553: /*
554: * Load file contents
555: */
556: if ((bp = cvs_buf_load(pb->filename, BUF_AUTOEXT)) == NULL) {
557: cvs_log(LP_ERR, "failed to load '%s'", pb->filename);
558: exit(1);
559: }
560:
561: if (cvs_buf_putc(bp, '\0') < 0)
562: exit(1);
563:
564: filec = (char *)cvs_buf_release(bp);
565:
566: /*
567: * Get description from user
568: */
569: rcs_desc = checkin_getdesc();
570: rcs_desc_set(pb->file, rcs_desc);
571:
572: /*
573: * Now add our new revision
574: */
575: if (rcs_rev_add(pb->file, RCS_HEAD_REV, LOG_INIT,
576: -1, pb->username) != 0) {
577: cvs_log(LP_ERR, "failed to add new revision");
578: exit(1);
579: }
580: }
581:
1.59 niallo 582: /*
583: * checkin_attach_symbol()
584: *
585: * Attempt to attach the specified symbol to the revision.
586: * On success, return 0. On error return -1.
587: */
1.58 niallo 588: static int
589: checkin_attach_symbol(struct checkin_params *pb)
590: {
591: char rbuf[16];
592: int ret;
593: if (verbose == 1)
594: printf("symbol: %s\n", pb->symbol);
595: if (pb->flags & CI_SYMFORCE)
596: rcs_sym_remove(pb->file, pb->symbol);
597: if ((ret = rcs_sym_add(pb->file, pb->symbol, pb->newrev) == -1)
598: && (rcs_errno == RCS_ERR_DUPENT)) {
599: rcsnum_tostr(rcs_sym_getrev(pb->file, pb->symbol),
600: rbuf, sizeof(rbuf));
601: cvs_log(LP_ERR,
602: "symbolic name %s already bound to %s",
603: pb->symbol, rbuf);
604: rcs_close(pb->file);
605: return (-1);
606: } else if (ret == -1) {
607: cvs_log(LP_ERR, "problem adding symbol: %s",
608: pb->symbol);
609: rcs_close(pb->file);
610: return (-1);
611: }
612: return (0);
613: }
614:
1.59 niallo 615: /*
616: * checkin_revert()
617: *
618: * If there are no differences between the working file and the latest revision
619: * and the -f flag is not specified, simply revert to the latest version and
620: * warn the user.
621: *
622: */
1.58 niallo 623: static void
624: checkin_revert(struct checkin_params *pb)
625: {
626: char rbuf[16];
627:
628: rcsnum_tostr(pb->frev, rbuf, sizeof(rbuf));
629: cvs_log(LP_WARN,
630: "file is unchanged; reverting to previous revision %s",
631: rbuf);
632: (void)unlink(pb->filename);
633: if ((pb->flags & CO_LOCK) || (pb->flags & CO_UNLOCK))
634: checkout_rev(pb->file, pb->frev, pb->filename,
635: pb->flags, pb->username);
636: rcs_lock_remove(pb->file, pb->frev);
637: rcs_close(pb->file);
638: if (verbose == 1)
639: printf("done\n");
640: }
641:
1.59 niallo 642: /*
643: * checkin_checklock()
644: *
645: * Check for the existence of a lock on the file. If there are no locks, or it
646: * is not locked by the correct user, return -1. Otherwise, return 0.
647: */
1.58 niallo 648: static int
649: checkin_checklock(struct checkin_params *pb)
650: {
651: int found = 0, notlocked = 1;
652: struct rcs_lock *lkp;
653:
654: if (!TAILQ_EMPTY(&(pb->file->rf_locks))) {
655: TAILQ_FOREACH(lkp, &(pb->file->rf_locks), rl_list) {
656: if (!strcmp(lkp->rl_name, pb->username))
657: notlocked = 0;
658:
659: if (!strcmp(lkp->rl_name, pb->username) &&
660: !rcsnum_cmp(lkp->rl_num, pb->frev, 0)) {
661: found = 1;
662: return (0);
663: }
664: }
665: }
1.32 joris 666:
1.58 niallo 667: if ((found == 0) && (notlocked == 0)) {
668: cvs_log(LP_ERR, "no locks set for '%s'", pb->username);
669: rcs_close(pb->file);
670: return (-1);
671: }
1.61 niallo 672: return (0);
673: }
674:
675: /*
1.62 ! niallo 676: * checkin_mtimedate()
1.61 niallo 677: *
678: * Set the date of the revision to be the last modification
1.62 ! niallo 679: * time of the working file.
1.61 niallo 680: *
681: * On success, return 0. On error return -1.
682: */
683: static int
1.62 ! niallo 684: checkin_mtimedate(struct checkin_params *pb)
1.61 niallo 685: {
686: struct stat sb;
687: if (stat(pb->filename, &sb) != 0) {
688: cvs_log(LP_ERRNO, "failed to stat: `%s'",
689: pb->filename);
690: rcs_close(pb->file);
691: return (-1);
692: }
693: pb->date = (time_t)sb.st_mtimespec.tv_sec;
1.58 niallo 694: return (0);
1.1 niallo 695: }