[BACK]Return to co.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / rcs

Annotation of src/usr.bin/rcs/co.c, Revision 1.100

1.100   ! millert     1: /*     $OpenBSD: co.c,v 1.99 2006/11/09 21:47:52 millert Exp $ */
1.1       joris       2: /*
                      3:  * Copyright (c) 2005 Joris Vink <joris@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 conditions
                      8:  * are met:
                      9:  *
                     10:  * 1. Redistributions of source code must retain the above copyright
                     11:  *    notice, this list of conditions 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:
1.51      xsa        27: #include "includes.h"
1.1       joris      28:
                     29: #include "rcsprog.h"
1.100   ! millert    30: #include "diff.h"
1.1       joris      31:
1.70      xsa        32: #define CO_OPTSTRING   "d:f::I::k:l::M::p::q::r::s:Tu::Vw::x::z::"
1.38      xsa        33:
1.43      xsa        34: static void    checkout_err_nobranch(RCSFILE *, const char *, const char *,
                     35:     const char *, int);
1.100   ! millert    36: static int     checkout_file_has_diffs(RCSFILE *, RCSNUM *, const char *);
1.4       joris      37:
1.1       joris      38: int
                     39: checkout_main(int argc, char **argv)
                     40: {
1.94      ray        41:        int fd, i, ch, flags, kflag, status;
1.78      pat        42:        RCSNUM *rev;
1.1       joris      43:        RCSFILE *file;
1.94      ray        44:        const char *author, *date, *state;
1.45      joris      45:        char fpath[MAXPATHLEN];
1.94      ray        46:        char *rev_str, *username;
1.37      xsa        47:        time_t rcs_mtime = -1;
1.1       joris      48:
1.94      ray        49:        flags = status = 0;
1.33      xsa        50:        kflag = RCS_KWEXP_ERR;
1.1       joris      51:        rev = RCS_HEAD_REV;
1.73      ray        52:        rev_str = NULL;
1.94      ray        53:        author = date = state = NULL;
1.4       joris      54:
1.38      xsa        55:        while ((ch = rcs_getopt(argc, argv, CO_OPTSTRING)) != -1) {
1.1       joris      56:                switch (ch) {
1.49      joris      57:                case 'd':
1.94      ray        58:                        date = rcs_optarg;
1.49      joris      59:                        break;
1.18      joris      60:                case 'f':
1.73      ray        61:                        rcs_setrevstr(&rev_str, rcs_optarg);
1.24      niallo     62:                        flags |= FORCE;
1.18      joris      63:                        break;
1.65      niallo     64:                case 'I':
1.73      ray        65:                        rcs_setrevstr(&rev_str, rcs_optarg);
1.65      niallo     66:                        flags |= INTERACTIVE;
                     67:                        break;
                     68:
1.33      xsa        69:                case 'k':
                     70:                        kflag = rcs_kflag_get(rcs_optarg);
                     71:                        if (RCS_KWEXP_INVAL(kflag)) {
1.83      xsa        72:                                warnx("invalid RCS keyword substitution mode");
1.33      xsa        73:                                (usage)();
                     74:                                exit(1);
                     75:                        }
                     76:                        break;
1.4       joris      77:                case 'l':
1.53      xsa        78:                        if (flags & CO_UNLOCK) {
1.81      xsa        79:                                warnx("warning: -u overridden by -l");
1.53      xsa        80:                                flags &= ~CO_UNLOCK;
                     81:                        }
1.73      ray        82:                        rcs_setrevstr(&rev_str, rcs_optarg);
1.24      niallo     83:                        flags |= CO_LOCK;
1.26      niallo     84:                        break;
                     85:                case 'M':
1.73      ray        86:                        rcs_setrevstr(&rev_str, rcs_optarg);
1.26      niallo     87:                        flags |= CO_REVDATE;
1.4       joris      88:                        break;
1.20      joris      89:                case 'p':
1.73      ray        90:                        rcs_setrevstr(&rev_str, rcs_optarg);
1.80      xsa        91:                        flags |= PIPEOUT;
1.20      joris      92:                        break;
1.3       joris      93:                case 'q':
1.73      ray        94:                        rcs_setrevstr(&rev_str, rcs_optarg);
1.79      xsa        95:                        flags |= QUIET;
1.3       joris      96:                        break;
1.1       joris      97:                case 'r':
1.73      ray        98:                        rcs_setrevstr(&rev_str, rcs_optarg);
1.4       joris      99:                        break;
1.24      niallo    100:                case 's':
1.94      ray       101:                        state = rcs_optarg;
1.24      niallo    102:                        flags |= CO_STATE;
1.34      xsa       103:                        break;
                    104:                case 'T':
                    105:                        flags |= PRESERVETIME;
1.24      niallo    106:                        break;
1.4       joris     107:                case 'u':
1.73      ray       108:                        rcs_setrevstr(&rev_str, rcs_optarg);
1.53      xsa       109:                        if (flags & CO_LOCK) {
1.81      xsa       110:                                warnx("warning: -l overridden by -u");
1.53      xsa       111:                                flags &= ~CO_LOCK;
                    112:                        }
1.24      niallo    113:                        flags |= CO_UNLOCK;
1.1       joris     114:                        break;
1.7       joris     115:                case 'V':
                    116:                        printf("%s\n", rcs_version);
                    117:                        exit(0);
1.38      xsa       118:                case 'w':
1.44      joris     119:                        /* if no argument, assume current user */
                    120:                        if (rcs_optarg == NULL) {
1.48      xsa       121:                                if ((author = getlogin()) == NULL)
1.84      xsa       122:                                        err(1, "getlogin");
1.94      ray       123:                        } else
                    124:                                author = rcs_optarg;
1.43      xsa       125:                        flags |= CO_AUTHOR;
1.38      xsa       126:                        break;
1.30      xsa       127:                case 'x':
1.66      ray       128:                        /* Use blank extension if none given. */
                    129:                        rcs_suffixes = rcs_optarg ? rcs_optarg : "";
1.59      joris     130:                        break;
                    131:                case 'z':
                    132:                        timezone_flag = rcs_optarg;
1.30      xsa       133:                        break;
1.1       joris     134:                default:
                    135:                        (usage)();
                    136:                        exit(1);
                    137:                }
                    138:        }
                    139:
1.13      joris     140:        argc -= rcs_optind;
                    141:        argv += rcs_optind;
1.1       joris     142:
                    143:        if (argc == 0) {
1.81      xsa       144:                warnx("no input file");
1.1       joris     145:                (usage)();
                    146:                exit (1);
                    147:        }
1.11      deraadt   148:
1.81      xsa       149:        if ((username = getlogin()) == NULL)
1.84      xsa       150:                err(1, "getlogin");
1.38      xsa       151:
1.1       joris     152:        for (i = 0; i < argc; i++) {
1.92      ray       153:                fd = rcs_choosefile(argv[i], fpath, sizeof(fpath));
                    154:                if (fd < 0) {
1.98      niallo    155:                        warn("%s", fpath);
1.1       joris     156:                        continue;
1.92      ray       157:                }
1.1       joris     158:
1.79      xsa       159:                if (!(flags & QUIET))
1.90      xsa       160:                        (void)fprintf(stderr, "%s  -->  %s\n", fpath,
1.80      xsa       161:                            (flags & PIPEOUT) ? "standard output" : argv[i]);
1.35      xsa       162:
                    163:                if ((flags & CO_LOCK) && (kflag & RCS_KWEXP_VAL)) {
1.81      xsa       164:                        warnx("%s: cannot combine -kv and -l", fpath);
1.86      joris     165:                        (void)close(fd);
1.35      xsa       166:                        continue;
                    167:                }
1.21      niallo    168:
1.86      joris     169:                if ((file = rcs_open(fpath, fd,
                    170:                    RCS_RDWR|RCS_PARSE_FULLY)) == NULL)
1.1       joris     171:                        continue;
                    172:
1.37      xsa       173:                if (flags & PRESERVETIME)
1.86      joris     174:                        rcs_mtime = rcs_get_mtime(file);
1.37      xsa       175:
1.72      xsa       176:                rcs_kwexp_set(file, kflag);
1.37      xsa       177:
1.75      ray       178:                if (rev_str != NULL) {
                    179:                        if ((rev = rcs_getrevnum(rev_str, file)) == NULL)
1.84      xsa       180:                                errx(1, "invalid revision: %s", rev_str);
1.75      ray       181:                } else {
1.76      joris     182:                        /* no revisions in RCS file, generate empty 0.0 */
                    183:                        if (file->rf_ndelta == 0) {
                    184:                                rev = rcsnum_parse("0.0");
                    185:                                if (rev == NULL)
1.84      xsa       186:                                        errx(1, "failed to generate rev 0.0");
1.76      joris     187:                        } else {
                    188:                                rev = rcsnum_alloc();
                    189:                                rcsnum_cpy(file->rf_head, rev, 0);
                    190:                        }
1.73      ray       191:                }
1.17      joris     192:
1.73      ray       193:                if ((status = checkout_rev(file, rev, argv[i], flags,
1.64      niallo    194:                    username, author, state, date)) < 0) {
1.73      ray       195:                        rcs_close(file);
                    196:                        rcsnum_free(rev);
                    197:                        continue;
1.8       niallo    198:                }
1.58      xsa       199:
1.79      xsa       200:                if (!(flags & QUIET))
1.90      xsa       201:                        (void)fprintf(stderr, "done\n");
1.17      joris     202:
1.73      ray       203:                rcsnum_free(rev);
1.37      xsa       204:
1.86      joris     205:                rcs_write(file);
1.37      xsa       206:                if (flags & PRESERVETIME)
1.86      joris     207:                        rcs_set_mtime(file, rcs_mtime);
                    208:                rcs_close(file);
1.1       joris     209:        }
                    210:
1.64      niallo    211:        return (status);
1.1       joris     212: }
                    213:
                    214: void
                    215: checkout_usage(void)
                    216: {
1.11      deraadt   217:        fprintf(stderr,
1.42      xsa       218:            "usage: co [-TV] [-ddate] [-f[rev]] [-I[rev]] [-kmode] [-l[rev]]\n"
                    219:            "          [-M[rev]] [-p[rev]] [-q[rev]] [-r[rev]] [-sstate]\n"
                    220:            "          [-u[rev]] [-w[user]] [-xsuffixes] [-ztz] file ...\n");
1.1       joris     221: }
1.14      niallo    222:
                    223: /*
                    224:  * Checkout revision <rev> from RCSFILE <file>, writing it to the path <dst>
1.88      ray       225:  * Currently recognised <flags> are CO_LOCK, CO_UNLOCK and CO_REVDATE.
1.14      niallo    226:  *
1.49      joris     227:  * Looks up revision based upon <lockname>, <author>, <state> and <date>
1.44      joris     228:  *
1.14      niallo    229:  * Returns 0 on success, -1 on failure.
                    230:  */
                    231: int
1.24      niallo    232: checkout_rev(RCSFILE *file, RCSNUM *frev, const char *dst, int flags,
1.49      joris     233:     const char *lockname, const char *author, const char *state,
                    234:     const char *date)
1.14      niallo    235: {
1.44      joris     236:        BUF *bp;
1.69      joris     237:        u_int i;
1.86      joris     238:        int fd, lcount;
1.60      niallo    239:        char buf[16];
1.99      millert   240:        mode_t mode = DEFFILEMODE;
1.18      joris     241:        struct stat st;
1.44      joris     242:        struct rcs_delta *rdp;
                    243:        struct rcs_lock *lkp;
1.97      ray       244:        char *fdate;
1.100   ! millert   245:        const char *fstatus;
1.49      joris     246:        time_t rcsdate, givendate;
1.69      joris     247:        RCSNUM *rev;
1.49      joris     248:
                    249:        rcsdate = givendate = -1;
                    250:        if (date != NULL)
1.85      joris     251:                givendate = rcs_date_parse(date);
1.14      niallo    252:
1.90      xsa       253:        if (file->rf_ndelta == 0 && !(flags & QUIET))
                    254:                (void)fprintf(stderr,
                    255:                    "no revisions present; generating empty revision 0.0\n");
1.76      joris     256:
1.69      joris     257:        /* XXX rcsnum_cmp()
                    258:         * Check out the latest revision if <frev> is greater than HEAD
                    259:         */
1.76      joris     260:        if (file->rf_ndelta != 0) {
                    261:                for (i = 0; i < file->rf_head->rn_len; i++) {
                    262:                        if (file->rf_head->rn_id[i] < frev->rn_id[i]) {
                    263:                                frev = file->rf_head;
                    264:                                break;
                    265:                        }
1.69      joris     266:                }
                    267:        }
1.15      niallo    268:
1.44      joris     269:        lcount = 0;
                    270:        TAILQ_FOREACH(lkp, &(file->rf_locks), rl_list) {
                    271:                if (!strcmp(lkp->rl_name, lockname))
                    272:                        lcount++;
                    273:        }
                    274:
                    275:        /*
                    276:         * If the user didn't specify any revision, we cycle through
                    277:         * revisions to lookup the first one that matches what he specified.
                    278:         *
                    279:         * If we cannot find one, we return an error.
                    280:         */
                    281:        rdp = NULL;
1.77      deraadt   282:        if (file->rf_ndelta != 0 && frev == file->rf_head) {
1.44      joris     283:                if (lcount > 1) {
1.81      xsa       284:                        warnx("multiple revisions locked by %s; "
1.44      joris     285:                            "please specify one", lockname);
                    286:                        return (-1);
                    287:                }
                    288:
                    289:                TAILQ_FOREACH(rdp, &file->rf_delta, rd_list) {
1.49      joris     290:                        if (date != NULL) {
                    291:                                fdate = asctime(&rdp->rd_date);
1.85      joris     292:                                rcsdate = rcs_date_parse(fdate);
1.49      joris     293:                                if (givendate <= rcsdate)
                    294:                                        continue;
                    295:                        }
                    296:
1.77      deraadt   297:                        if (author != NULL &&
                    298:                            strcmp(rdp->rd_author, author))
1.44      joris     299:                                continue;
1.49      joris     300:
1.77      deraadt   301:                        if (state != NULL &&
                    302:                            strcmp(rdp->rd_state, state))
1.44      joris     303:                                continue;
                    304:
                    305:                        frev = rdp->rd_num;
                    306:                        break;
                    307:                }
1.76      joris     308:        } else if (file->rf_ndelta != 0) {
1.44      joris     309:                rdp = rcs_findrev(file, frev);
                    310:        }
                    311:
1.77      deraadt   312:        if (file->rf_ndelta != 0 && rdp == NULL) {
1.49      joris     313:                checkout_err_nobranch(file, author, date, state, flags);
1.44      joris     314:                return (-1);
                    315:        }
                    316:
1.76      joris     317:        if (file->rf_ndelta == 0)
                    318:                rev = frev;
                    319:        else
                    320:                rev = rdp->rd_num;
                    321:
1.69      joris     322:        rcsnum_tostr(rev, buf, sizeof(buf));
1.15      niallo    323:
1.77      deraadt   324:        if (file->rf_ndelta != 0 && rdp->rd_locker != NULL) {
1.44      joris     325:                if (strcmp(lockname, rdp->rd_locker)) {
1.97      ray       326:                        warnx("Revision %s is already locked by %s; %s",
                    327:                            buf, rdp->rd_locker,
                    328:                            (flags & CO_UNLOCK) ? "use co -r or rcs -u" : "");
1.44      joris     329:                        return (-1);
                    330:                }
                    331:        }
                    332:
1.79      xsa       333:        if (!(flags & QUIET) && !(flags & NEWFILE) &&
1.77      deraadt   334:            !(flags & CO_REVERT) && file->rf_ndelta != 0)
1.91      xsa       335:                (void)fprintf(stderr, "revision %s", buf);
1.74      deraadt   336:
1.76      joris     337:        if (file->rf_ndelta != 0) {
                    338:                if ((bp = rcs_getrev(file, rev)) == NULL) {
1.81      xsa       339:                        warnx("cannot find revision `%s'", buf);
1.76      joris     340:                        return (-1);
                    341:                }
                    342:        } else {
1.85      joris     343:                bp = rcs_buf_alloc(1, 0);
1.14      niallo    344:        }
1.69      joris     345:
1.55      niallo    346:        /*
                    347:         * Do keyword expansion if required.
                    348:         */
1.76      joris     349:        if (file->rf_ndelta != 0)
                    350:                bp = rcs_kwexp_buf(bp, file, rev);
1.67      niallo    351:        /*
                    352:         * File inherits permissions from its ,v file
                    353:         */
1.93      ray       354:        if (file->rf_fd != -1) {
                    355:                if (fstat(file->rf_fd, &st) == -1)
1.86      joris     356:                        err(1, "%s", file->rf_path);
                    357:                mode = st.st_mode;
                    358:        }
1.67      niallo    359:
1.24      niallo    360:        if (flags & CO_LOCK) {
1.76      joris     361:                if (file->rf_ndelta != 0) {
1.77      deraadt   362:                        if (lockname != NULL &&
                    363:                            rcs_lock_add(file, lockname, rev) < 0) {
1.76      joris     364:                                if (rcs_errno != RCS_ERR_DUPENT)
                    365:                                        return (-1);
                    366:                        }
1.14      niallo    367:                }
1.18      joris     368:
1.99      millert   369:                /* File should only be writable by owner. */
                    370:                mode &= ~(S_IWGRP|S_IWOTH);
1.67      niallo    371:                mode |= S_IWUSR;
1.76      joris     372:
                    373:                if (file->rf_ndelta != 0) {
1.79      xsa       374:                        if (!(flags & QUIET) && !(flags & NEWFILE) &&
1.77      deraadt   375:                            !(flags & CO_REVERT))
1.91      xsa       376:                                (void)fprintf(stderr, " (locked)");
1.76      joris     377:                }
1.24      niallo    378:        } else if (flags & CO_UNLOCK) {
1.76      joris     379:                if (file->rf_ndelta != 0) {
                    380:                        if (rcs_lock_remove(file, lockname, rev) < 0) {
                    381:                                if (rcs_errno != RCS_ERR_NOENT)
                    382:                                        return (-1);
                    383:                        }
1.46      joris     384:                }
1.18      joris     385:
1.67      niallo    386:                /* Strip all write bits from mode */
1.99      millert   387:                mode &= ~(S_IWUSR|S_IWGRP|S_IWOTH);
1.76      joris     388:
                    389:                if (file->rf_ndelta != 0) {
1.79      xsa       390:                        if (!(flags & QUIET) && !(flags & NEWFILE) &&
1.77      deraadt   391:                            !(flags & CO_REVERT))
1.91      xsa       392:                                (void)fprintf(stderr, " (unlocked)");
1.76      joris     393:                }
1.18      joris     394:        }
1.56      xsa       395:
1.90      xsa       396:        if (file->rf_ndelta == 0 && !(flags & QUIET) &&
1.76      joris     397:            ((flags & CO_LOCK) || (flags & CO_UNLOCK))) {
1.91      xsa       398:                (void)fprintf(stderr, "no revisions, so nothing can be %s\n",
1.76      joris     399:                    (flags & CO_LOCK) ? "locked" : "unlocked");
                    400:        } else if (file->rf_ndelta != 0) {
1.88      ray       401:                /* XXX - Not a good way to detect if a newline is needed. */
                    402:                if (!(flags & QUIET) && !(flags & NEWFILE) &&
                    403:                    !(flags & CO_REVERT))
1.90      xsa       404:                        (void)fprintf(stderr, "\n");
1.76      joris     405:        }
1.18      joris     406:
1.44      joris     407:        if (flags & CO_LOCK) {
1.71      niallo    408:                if (rcs_errno != RCS_ERR_DUPENT)
                    409:                        lcount++;
1.79      xsa       410:                if (!(flags & QUIET) && lcount > 1 && !(flags & CO_REVERT))
1.81      xsa       411:                        warnx("%s: warning: You now have %d locks.",
1.63      xsa       412:                            file->rf_path, lcount);
1.44      joris     413:        }
                    414:
1.100   ! millert   415:        if ((flags & (PIPEOUT|FORCE)) == 0 && stat(dst, &st) != -1) {
1.68      ray       416:                /*
1.100   ! millert   417:                 * Prompt the user if the file is writable or the file is
        !           418:                 * not writable but is different from the RCS head version.
        !           419:                 * This is different from GNU which will silently overwrite
        !           420:                 * the file regardless of its contents so long as it is
        !           421:                 * read-only.
1.68      ray       422:                 */
                    423:                if (st.st_mode & (S_IWUSR|S_IWGRP|S_IWOTH))
1.100   ! millert   424:                        fstatus = "writable";
        !           425:                else if (checkout_file_has_diffs(file, frev, dst) != D_SAME)
        !           426:                        fstatus = "modified";
        !           427:                else
        !           428:                        fstatus = NULL;
        !           429:                if (fstatus) {
        !           430:                        (void)fprintf(stderr, "%s %s exists%s; ", fstatus, dst,
        !           431:                            (getuid() == st.st_uid) ? "" :
        !           432:                            ", and you do not own it");
        !           433:                        (void)fprintf(stderr, "remove it? [ny](n): ");
        !           434:                        if (rcs_yesno('n') == 'n') {
        !           435:                                if (!(flags & QUIET) && isatty(STDIN_FILENO))
        !           436:                                        warnx("%s %s exists; checkout aborted",
        !           437:                                            fstatus, dst);
        !           438:                                else
        !           439:                                        warnx("checkout aborted");
        !           440:                                return (-1);
        !           441:                        }
1.18      joris     442:                }
1.14      niallo    443:        }
1.17      joris     444:
1.96      ray       445:        if (flags & PIPEOUT)
                    446:                rcs_buf_write_fd(bp, STDOUT_FILENO);
                    447:        else {
1.86      joris     448:                (void)unlink(dst);
                    449:
                    450:                if ((fd = open(dst, O_WRONLY|O_CREAT|O_TRUNC, mode)) < 0)
                    451:                        err(1, "%s", dst);
                    452:
                    453:                if (rcs_buf_write_fd(bp, fd) < 0) {
1.81      xsa       454:                        warnx("failed to write revision to file");
1.85      joris     455:                        rcs_buf_free(bp);
1.86      joris     456:                        (void)close(fd);
1.20      joris     457:                        return (-1);
                    458:                }
1.86      joris     459:
                    460:                if (fchmod(fd, mode) == -1)
                    461:                        warn("%s", dst);
                    462:
1.24      niallo    463:                if (flags & CO_REVDATE) {
                    464:                        struct timeval tv[2];
1.36      xsa       465:                        memset(&tv, 0, sizeof(tv));
1.69      joris     466:                        tv[0].tv_sec = (long)rcs_rev_getdate(file, rev);
1.24      niallo    467:                        tv[1].tv_sec = tv[0].tv_sec;
1.86      joris     468:                        if (futimes(fd, (const struct timeval *)&tv) < 0)
1.81      xsa       469:                                warn("utimes");
1.24      niallo    470:                }
1.86      joris     471:
                    472:                (void)close(fd);
1.14      niallo    473:        }
1.96      ray       474:
                    475:        rcs_buf_free(bp);
1.17      joris     476:
1.14      niallo    477:        return (0);
1.43      xsa       478: }
                    479:
                    480: /*
                    481:  * checkout_err_nobranch()
                    482:  *
                    483:  * XXX - should handle the dates too.
                    484:  */
                    485: static void
                    486: checkout_err_nobranch(RCSFILE *file, const char *author, const char *date,
                    487:     const char *state, int flags)
                    488: {
                    489:        if (!(flags & CO_AUTHOR))
                    490:                author = NULL;
                    491:        if (!(flags & CO_STATE))
                    492:                state = NULL;
                    493:
1.81      xsa       494:        warnx("%s: No revision on branch has%s%s%s%s%s%s.",
1.43      xsa       495:            file->rf_path,
                    496:            date ? " a date before " : "",
                    497:            date ? date : "",
                    498:            author ? " and author " + (date ? 0:4 ) : "",
                    499:            author ? author : "",
                    500:            state  ? " and state " + (date || author ? 0:4) : "",
                    501:            state  ? state : "");
1.100   ! millert   502: }
        !           503:
        !           504: /*
        !           505:  * checkout_file_has_diffs()
        !           506:  *
        !           507:  * Check for diffs between the working file and its current revision.
        !           508:  * Same return values as rcs_diffreg()
        !           509:  */
        !           510: static int
        !           511: checkout_file_has_diffs(RCSFILE *rfp, RCSNUM *frev, const char *dst)
        !           512: {
        !           513:        char *tempfile;
        !           514:        BUF *bp;
        !           515:        int ret;
        !           516:
        !           517:        tempfile = NULL;
        !           518:
        !           519:        if ((bp = rcs_getrev(rfp, frev)) == NULL) {
        !           520:                warnx("failed to load revision");
        !           521:                return (D_ERROR);
        !           522:        }
        !           523:
        !           524:        (void)xasprintf(&tempfile, "%s/diff.XXXXXXXXXX", rcs_tmpdir);
        !           525:        rcs_buf_write_stmp(bp, tempfile);
        !           526:        rcs_buf_empty(bp);
        !           527:
        !           528:        diff_format = D_RCSDIFF;
        !           529:        ret = rcs_diffreg(dst, tempfile, bp, 0);
        !           530:
        !           531:        rcs_buf_free(bp);
        !           532:        unlink(tempfile);
        !           533:        xfree(tempfile);
        !           534:
        !           535:        return (ret);
1.24      niallo    536: }