/* * rcsnum_parse() * * Parse a string specifying an RCS number and return the corresponding RCSNUM. */ RCSNUM * rcsnum_parse(const char *str) { char *ep; RCSNUM *num; num = rcsnum_alloc(); if (rcsnum_aton(str, &ep, num) < 0 || *ep != '\0') { rcsnum_free(num); num = NULL; } return (num); }
/* * rcs_main() * * Handler for the `rcs' program. * Returns 0 on success, or >0 on error. */ int rcs_main(int argc, char **argv) { int fd; int i, j, ch, flags, kflag, lkmode; const char *nflag, *oldfilename, *orange; char fpath[PATH_MAX]; char *logstr, *logmsg, *descfile; char *alist, *comment, *elist, *lrev, *urev; mode_t fmode; RCSFILE *file; RCSNUM *logrev; struct rcs_access *acp; time_t rcs_mtime = -1; kflag = RCS_KWEXP_ERR; lkmode = RCS_LOCK_INVAL; fmode = S_IRUSR|S_IRGRP|S_IROTH; flags = RCS_RDWR|RCS_PARSE_FULLY; lrev = urev = descfile = NULL; logstr = alist = comment = elist = NULL; nflag = oldfilename = orange = NULL; /* match GNU */ if (1 < argc && argv[1][0] != '-') warnx("warning: No options were given; " "this usage is obsolescent."); while ((ch = rcs_getopt(argc, argv, RCSPROG_OPTSTRING)) != -1) { switch (ch) { case 'A': oldfilename = rcs_optarg; rcsflags |= CO_ACLAPPEND; break; case 'a': alist = rcs_optarg; break; case 'c': comment = rcs_optarg; break; case 'e': elist = rcs_optarg; rcsflags |= RCSPROG_EFLAG; break; case 'I': rcsflags |= INTERACTIVE; break; case 'i': flags |= RCS_CREATE; break; case 'k': kflag = rcs_kflag_get(rcs_optarg); if (RCS_KWEXP_INVAL(kflag)) { warnx("invalid RCS keyword substitution mode"); (usage)(); } break; case 'L': if (lkmode == RCS_LOCK_LOOSE) warnx("-U overridden by -L"); lkmode = RCS_LOCK_STRICT; break; case 'l': if (rcsflags & RCSPROG_UFLAG) warnx("-u overridden by -l"); lrev = rcs_optarg; rcsflags &= ~RCSPROG_UFLAG; rcsflags |= RCSPROG_LFLAG; break; case 'm': free(logstr); logstr = xstrdup(rcs_optarg); break; case 'M': /* ignore for the moment */ break; case 'n': nflag = rcs_optarg; break; case 'N': nflag = rcs_optarg; rcsflags |= RCSPROG_NFLAG; break; case 'o': orange = rcs_optarg; break; case 'q': rcsflags |= QUIET; break; case 't': descfile = rcs_optarg; rcsflags |= DESCRIPTION; break; case 'T': rcsflags |= PRESERVETIME; break; case 'U': if (lkmode == RCS_LOCK_STRICT) warnx("-L overridden by -U"); lkmode = RCS_LOCK_LOOSE; break; case 'u': if (rcsflags & RCSPROG_LFLAG) warnx("-l overridden by -u"); urev = rcs_optarg; rcsflags &= ~RCSPROG_LFLAG; rcsflags |= RCSPROG_UFLAG; break; case 'V': printf("%s\n", rcs_version); exit(0); case 'x': /* Use blank extension if none given. */ rcs_suffixes = rcs_optarg ? rcs_optarg : ""; break; case 'z': /* * kept for compatibility */ break; default: (usage)(); } } argc -= rcs_optind; argv += rcs_optind; if (argc == 0) { warnx("no input file"); (usage)(); } for (i = 0; i < argc; i++) { fd = rcs_choosefile(argv[i], fpath, sizeof(fpath)); if (fd < 0 && !(flags & RCS_CREATE)) { warn("%s", fpath); continue; } if (!(rcsflags & QUIET)) (void)fprintf(stderr, "RCS file: %s\n", fpath); if ((file = rcs_open(fpath, fd, flags, fmode)) == NULL) { close(fd); continue; } if (rcsflags & DESCRIPTION) { if (rcs_set_description(file, descfile, rcsflags) == -1) { warn("%s", descfile); rcs_close(file); continue; } } else if (flags & RCS_CREATE) { if (rcs_set_description(file, NULL, rcsflags) == -1) { warn("stdin"); rcs_close(file); continue; } } if (rcsflags & PRESERVETIME) rcs_mtime = rcs_get_mtime(file); if (nflag != NULL) rcs_attach_symbol(file, nflag); if (logstr != NULL) { if ((logmsg = strchr(logstr, ':')) == NULL) { warnx("missing log message"); rcs_close(file); continue; } *logmsg++ = '\0'; if ((logrev = rcsnum_parse(logstr)) == NULL) { warnx("`%s' bad revision number", logstr); rcs_close(file); continue; } if (rcs_rev_setlog(file, logrev, logmsg) < 0) { warnx("failed to set logmsg for `%s' to `%s'", logstr, logmsg); rcs_close(file); rcsnum_free(logrev); continue; } rcsnum_free(logrev); } /* entries to add from <oldfile> */ if (rcsflags & CO_ACLAPPEND) { RCSFILE *oldfile; int ofd; char ofpath[PATH_MAX]; ofd = rcs_choosefile(oldfilename, ofpath, sizeof(ofpath)); if (ofd < 0) { if (!(flags & RCS_CREATE)) warn("%s", ofpath); exit(1); } if ((oldfile = rcs_open(ofpath, ofd, RCS_READ)) == NULL) exit(1); TAILQ_FOREACH(acp, &(oldfile->rf_access), ra_list) rcs_access_add(file, acp->ra_name); rcs_close(oldfile); (void)close(ofd); } /* entries to add to the access list */ if (alist != NULL) { struct rcs_argvector *aargv; aargv = rcs_strsplit(alist, ","); for (j = 0; aargv->argv[j] != NULL; j++) rcs_access_add(file, aargv->argv[j]); rcs_argv_destroy(aargv); } if (comment != NULL) rcs_comment_set(file, comment); if (elist != NULL) { struct rcs_argvector *eargv; eargv = rcs_strsplit(elist, ","); for (j = 0; eargv->argv[j] != NULL; j++) rcs_access_remove(file, eargv->argv[j]); rcs_argv_destroy(eargv); } else if (rcsflags & RCSPROG_EFLAG) { struct rcs_access *rap; /* XXX rcs_access_remove(file, NULL); ?? */ while (!TAILQ_EMPTY(&(file->rf_access))) { rap = TAILQ_FIRST(&(file->rf_access)); TAILQ_REMOVE(&(file->rf_access), rap, ra_list); free(rap->ra_name); free(rap); } /* not synced anymore */ file->rf_flags &= ~RCS_SYNCED; } rcs_kwexp_set(file, kflag); if (lkmode != RCS_LOCK_INVAL) (void)rcs_lock_setmode(file, lkmode); if (rcsflags & RCSPROG_LFLAG) { RCSNUM *rev; const char *username; char rev_str[RCS_REV_BUFSZ]; if (file->rf_head == NULL) { warnx("%s contains no revisions", fpath); rcs_close(file); continue; } if ((username = getlogin()) == NULL) err(1, "getlogin"); if (lrev == NULL) { rev = rcsnum_alloc(); rcsnum_cpy(file->rf_head, rev, 0); } else if ((rev = rcsnum_parse(lrev)) == NULL) { warnx("unable to unlock file"); rcs_close(file); continue; } rcsnum_tostr(rev, rev_str, sizeof(rev_str)); /* Make sure revision exists. */ if (rcs_findrev(file, rev) == NULL) errx(1, "%s: cannot lock nonexisting " "revision %s", fpath, rev_str); if (rcs_lock_add(file, username, rev) != -1 && !(rcsflags & QUIET)) (void)fprintf(stderr, "%s locked\n", rev_str); rcsnum_free(rev); } if (rcsflags & RCSPROG_UFLAG) { RCSNUM *rev; const char *username; char rev_str[RCS_REV_BUFSZ]; if (file->rf_head == NULL) { warnx("%s contains no revisions", fpath); rcs_close(file); continue; } if ((username = getlogin()) == NULL) err(1, "getlogin"); if (urev == NULL) { rev = rcsnum_alloc(); rcsnum_cpy(file->rf_head, rev, 0); } else if ((rev = rcsnum_parse(urev)) == NULL) { warnx("unable to unlock file"); rcs_close(file); continue; } rcsnum_tostr(rev, rev_str, sizeof(rev_str)); /* Make sure revision exists. */ if (rcs_findrev(file, rev) == NULL) errx(1, "%s: cannot unlock nonexisting " "revision %s", fpath, rev_str); if (rcs_lock_remove(file, username, rev) == -1 && !(rcsflags & QUIET)) warnx("%s: warning: No locks are set.", fpath); else { if (!(rcsflags & QUIET)) (void)fprintf(stderr, "%s unlocked\n", rev_str); } rcsnum_free(rev); } if (orange != NULL) { struct rcs_delta *rdp, *nrdp; char b[RCS_REV_BUFSZ]; rcs_rev_select(file, orange); for (rdp = TAILQ_FIRST(&(file->rf_delta)); rdp != NULL; rdp = nrdp) { nrdp = TAILQ_NEXT(rdp, rd_list); /* * Delete selected revisions. */ if (rdp->rd_flags & RCS_RD_SELECT) { rcsnum_tostr(rdp->rd_num, b, sizeof(b)); if (!(rcsflags & QUIET)) { (void)fprintf(stderr, "deleting" " revision %s\n", b); } (void)rcs_rev_remove(file, rdp->rd_num); } } } rcs_write(file); if (rcsflags & PRESERVETIME) rcs_set_mtime(file, rcs_mtime); rcs_close(file); if (!(rcsflags & QUIET)) (void)fprintf(stderr, "done\n"); } return (0); }
void cvs_admin_local(struct cvs_file *cf) { int i; RCSNUM *rev; cvs_log(LP_TRACE, "cvs_admin_local(%s)", cf->file_path); cvs_file_classify(cf, cvs_directory_tag); if (cf->file_type == CVS_DIR) { if (verbosity > 1) cvs_log(LP_NOTICE, "Administrating %s", cf->file_name); return; } if (cf->file_ent == NULL) return; else if (cf->file_status == FILE_ADDED) { cvs_log(LP_ERR, "cannot admin newly added file `%s'", cf->file_name); return; } if (cf->file_rcs == NULL) { cvs_log(LP_ERR, "lost RCS file for `%s'", cf->file_path); return; } if (verbosity > 0) cvs_printf("RCS file: %s\n", cf->file_rcs->rf_path); if (oldfilename != NULL) { struct cvs_file *ocf; struct rcs_access *acp; int ofd; char *d, *f, fpath[MAXPATHLEN], repo[MAXPATHLEN]; if ((f = basename(oldfilename)) == NULL) fatal("cvs_admin_local: basename failed"); if ((d = dirname(oldfilename)) == NULL) fatal("cvs_admin_local: dirname failed"); cvs_get_repository_path(d, repo, MAXPATHLEN); (void)xsnprintf(fpath, MAXPATHLEN, "%s/%s", repo, f); if (strlcat(fpath, RCS_FILE_EXT, MAXPATHLEN) >= MAXPATHLEN) fatal("cvs_admin_local: truncation"); if ((ofd = open(fpath, O_RDONLY)) == -1) fatal("cvs_admin_local: open: `%s': %s", fpath, strerror(errno)); /* XXX: S_ISREG() check instead of blindly using CVS_FILE? */ ocf = cvs_file_get_cf(d, f, oldfilename, ofd, CVS_FILE, 0); ocf->file_rcs = rcs_open(fpath, ofd, RCS_READ, 0444); if (ocf->file_rcs == NULL) fatal("cvs_admin_local: rcs_open failed"); TAILQ_FOREACH(acp, &(ocf->file_rcs->rf_access), ra_list) rcs_access_add(cf->file_rcs, acp->ra_name); cvs_file_free(ocf); } if (alist != NULL) { struct cvs_argvector *aargv; aargv = cvs_strsplit(alist, ","); for (i = 0; aargv->argv[i] != NULL; i++) rcs_access_add(cf->file_rcs, aargv->argv[i]); cvs_argv_destroy(aargv); } if (comment != NULL) rcs_comment_set(cf->file_rcs, comment); if (elist != NULL) { struct cvs_argvector *eargv; eargv = cvs_strsplit(elist, ","); for (i = 0; eargv->argv[i] != NULL; i++) rcs_access_remove(cf->file_rcs, eargv->argv[i]); cvs_argv_destroy(eargv); } else if (runflags & ADM_EFLAG) { struct rcs_access *rap; while (!TAILQ_EMPTY(&(cf->file_rcs->rf_access))) { rap = TAILQ_FIRST(&(cf->file_rcs->rf_access)); TAILQ_REMOVE(&(cf->file_rcs->rf_access), rap, ra_list); xfree(rap->ra_name); xfree(rap); } /* no synced anymore */ cf->file_rcs->rf_flags &= ~RCS_SYNCED; } /* Default `-kv' is accepted here. */ if (kflag) { if (cf->file_rcs->rf_expand == NULL || strcmp(cf->file_rcs->rf_expand, koptstr) != 0) rcs_kwexp_set(cf->file_rcs, kflag); } if (logstr != NULL) { if ((logmsg = strchr(logstr, ':')) == NULL) { cvs_log(LP_ERR, "missing log message"); return; } *logmsg++ = '\0'; if ((rev = rcsnum_parse(logstr)) == NULL) { cvs_log(LP_ERR, "`%s' bad revision number", logstr); return; } if (rcs_rev_setlog(cf->file_rcs, rev, logmsg) < 0) { cvs_log(LP_ERR, "failed to set logmsg for `%s' to `%s'", logstr, logmsg); rcsnum_free(rev); return; } rcsnum_free(rev); } if (orange != NULL) { struct rcs_delta *rdp, *nrdp; char b[CVS_REV_BUFSZ]; cvs_revision_select(cf->file_rcs, orange); for (rdp = TAILQ_FIRST(&(cf->file_rcs->rf_delta)); rdp != NULL; rdp = nrdp) { nrdp = TAILQ_NEXT(rdp, rd_list); /* * Delete selected revisions. */ if (rdp->rd_flags & RCS_RD_SELECT) { rcsnum_tostr(rdp->rd_num, b, sizeof(b)); if (verbosity > 0) cvs_printf("deleting revision %s\n", b); (void)rcs_rev_remove(cf->file_rcs, rdp->rd_num); } } } if (state != NULL) { if (staterevstr != NULL) { if ((rev = rcsnum_parse(staterevstr)) == NULL) { cvs_log(LP_ERR, "`%s' bad revision number", staterevstr); return; } } else if (cf->file_rcs->rf_head != NULL) { rev = rcsnum_alloc(); rcsnum_cpy(cf->file_rcs->rf_head, rev, 0); } else { cvs_log(LP_ERR, "head revision missing"); return; } (void)rcs_state_set(cf->file_rcs, rev, state); rcsnum_free(rev); } if (lkmode != RCS_LOCK_INVAL) (void)rcs_lock_setmode(cf->file_rcs, lkmode); rcs_write(cf->file_rcs); if (verbosity > 0) cvs_printf("done\n"); }
int rcsdiff_main(int argc, char **argv) { int fd, i, ch, dflags, status; RCSNUM *rev1, *rev2; RCSFILE *file; char fpath[MAXPATHLEN], *rev_str1, *rev_str2; const char *errstr; rev1 = rev2 = NULL; rev_str1 = rev_str2 = NULL; status = D_SAME; dflags = 0; if (strlcpy(diffargs, "diff", sizeof(diffargs)) >= sizeof(diffargs)) errx(D_ERROR, "diffargs too long"); while ((ch = rcs_getopt(argc, argv, "abC:cdI:ik:npqr:TtU:uVwx::z::")) != -1) { switch (ch) { case 'a': if (strlcat(diffargs, " -a", sizeof(diffargs)) >= sizeof(diffargs)) errx(D_ERROR, "diffargs too long"); dflags |= D_FORCEASCII; break; case 'b': if (strlcat(diffargs, " -b", sizeof(diffargs)) >= sizeof(diffargs)) errx(D_ERROR, "diffargs too long"); dflags |= D_FOLDBLANKS; break; case 'C': (void)strlcat(diffargs, " -C", sizeof(diffargs)); if (strlcat(diffargs, rcs_optarg, sizeof(diffargs)) >= sizeof(diffargs)) errx(D_ERROR, "diffargs too long"); diff_context = strtonum(rcs_optarg, 0, INT_MAX, &errstr); if (errstr) errx(D_ERROR, "context is %s: %s", errstr, rcs_optarg); diff_format = D_CONTEXT; break; case 'c': if (strlcat(diffargs, " -c", sizeof(diffargs)) >= sizeof(diffargs)) errx(D_ERROR, "diffargs too long"); diff_format = D_CONTEXT; break; case 'd': if (strlcat(diffargs, " -d", sizeof(diffargs)) >= sizeof(diffargs)) errx(D_ERROR, "diffargs too long"); dflags |= D_MINIMAL; break; case 'i': if (strlcat(diffargs, " -i", sizeof(diffargs)) >= sizeof(diffargs)) errx(D_ERROR, "diffargs too long"); dflags |= D_IGNORECASE; break; case 'I': (void)strlcat(diffargs, " -I", sizeof(diffargs)); if (strlcat(diffargs, rcs_optarg, sizeof(diffargs)) >= sizeof(diffargs)) errx(D_ERROR, "diffargs too long"); push_ignore_pats(rcs_optarg); break; case 'k': kflag = rcs_kflag_get(rcs_optarg); if (RCS_KWEXP_INVAL(kflag)) { warnx("invalid RCS keyword substitution mode"); (usage)(); exit(D_ERROR); } break; case 'n': if (strlcat(diffargs, " -n", sizeof(diffargs)) >= sizeof(diffargs)) errx(D_ERROR, "diffargs too long"); diff_format = D_RCSDIFF; break; case 'p': if (strlcat(diffargs, " -p", sizeof(diffargs)) >= sizeof(diffargs)) errx(D_ERROR, "diffargs too long"); dflags |= D_PROTOTYPE; break; case 'q': quiet = 1; break; case 'r': rcs_setrevstr2(&rev_str1, &rev_str2, rcs_optarg); break; case 'T': /* * kept for compatibility */ break; case 't': if (strlcat(diffargs, " -t", sizeof(diffargs)) >= sizeof(diffargs)) errx(D_ERROR, "diffargs too long"); dflags |= D_EXPANDTABS; break; case 'U': (void)strlcat(diffargs, " -U", sizeof(diffargs)); if (strlcat(diffargs, rcs_optarg, sizeof(diffargs)) >= sizeof(diffargs)) errx(D_ERROR, "diffargs too long"); diff_context = strtonum(rcs_optarg, 0, INT_MAX, &errstr); if (errstr) errx(D_ERROR, "context is %s: %s", errstr, rcs_optarg); diff_format = D_UNIFIED; break; case 'u': if (strlcat(diffargs, " -u", sizeof(diffargs)) >= sizeof(diffargs)) errx(D_ERROR, "diffargs too long"); diff_format = D_UNIFIED; break; case 'V': printf("%s\n", rcs_version); exit(0); case 'w': if (strlcat(diffargs, " -w", sizeof(diffargs)) >= sizeof(diffargs)) errx(D_ERROR, "diffargs too long"); dflags |= D_IGNOREBLANKS; break; case 'x': /* Use blank extension if none given. */ rcs_suffixes = rcs_optarg ? rcs_optarg : ""; break; case 'z': timezone_flag = rcs_optarg; break; default: (usage)(); exit(D_ERROR); } } argc -= rcs_optind; argv += rcs_optind; if (argc == 0) { warnx("no input file"); (usage)(); exit(D_ERROR); } if (diff_ignore_pats != NULL) { char buf[BUFSIZ]; int error; diff_ignore_re = xmalloc(sizeof(*diff_ignore_re)); if ((error = regcomp(diff_ignore_re, diff_ignore_pats, REG_NEWLINE | REG_EXTENDED)) != 0) { regerror(error, diff_ignore_re, buf, sizeof(buf)); if (*diff_ignore_pats != '\0') errx(D_ERROR, "%s: %s", diff_ignore_pats, buf); else errx(D_ERROR, "%s", buf); } } for (i = 0; i < argc; i++) { fd = rcs_choosefile(argv[i], fpath, sizeof(fpath)); if (fd < 0) { warn("%s", fpath); continue; } if ((file = rcs_open(fpath, fd, RCS_READ|RCS_PARSE_FULLY)) == NULL) continue; rcs_kwexp_set(file, kflag); if (rev_str1 != NULL) { if ((rev1 = rcs_getrevnum(rev_str1, file)) == NULL) errx(D_ERROR, "bad revision number"); } if (rev_str2 != NULL) { if ((rev2 = rcs_getrevnum(rev_str2, file)) == NULL) errx(D_ERROR, "bad revision number"); } if (!quiet) { fprintf(stderr, "%s\n", RCS_DIFF_DIV); fprintf(stderr, "RCS file: %s\n", fpath); } diff_file = argv[i]; /* No revisions given. */ if (rev_str1 == NULL) status = rcsdiff_file(file, file->rf_head, argv[i], dflags); /* One revision given. */ else if (rev_str2 == NULL) status = rcsdiff_file(file, rev1, argv[i], dflags); /* Two revisions given. */ else status = rcsdiff_rev(file, rev1, rev2, dflags); rcs_close(file); if (rev1 != NULL) { rcsnum_free(rev1); rev1 = NULL; } if (rev2 != NULL) { rcsnum_free(rev2); rev2 = NULL; } } return (status); }
static void import_new(struct cvs_file *cf) { int i; BUF *bp; mode_t mode; time_t tstamp; struct stat st; struct rcs_branch *brp; struct rcs_delta *rdp; RCSNUM *branch, *brev; tstamp = -1; cvs_log(LP_TRACE, "import_new(%s)", cf->file_name); if (cvs_noexec == 1) { import_printf("N %s/%s\n", import_repository, cf->file_path); return; } if (fstat(cf->fd, &st) == -1) fatal("import_new: %s", strerror(errno)); mode = st.st_mode; if (dflag == 1) tstamp = st.st_mtime; if ((branch = rcsnum_parse(import_branch)) == NULL) fatal("import_new: failed to parse branch"); bp = buf_load_fd(cf->fd); if ((brev = rcsnum_brtorev(branch)) == NULL) fatal("import_new: failed to get first branch revision"); cf->repo_fd = open(cf->file_rpath, O_CREAT | O_RDONLY); if (cf->repo_fd < 0) fatal("import_new: %s: %s", cf->file_rpath, strerror(errno)); cf->file_rcs = rcs_open(cf->file_rpath, cf->repo_fd, RCS_CREATE, (mode & ~(S_IWUSR | S_IWGRP | S_IWOTH))); if (cf->file_rcs == NULL) fatal("import_new: failed to create RCS file for %s", cf->file_path); rcs_branch_set(cf->file_rcs, branch); if (rcs_sym_add(cf->file_rcs, vendor_tag, branch) == -1) fatal("import_new: failed to add vendor tag"); for (i = 0; i < tagcount; i++) { if (rcs_sym_add(cf->file_rcs, release_tags[i], brev) == -1) fatal("import_new: failed to add release tag"); } if (rcs_rev_add(cf->file_rcs, brev, logmsg, tstamp, NULL) == -1) fatal("import_new: failed to create first branch revision"); if (rcs_rev_add(cf->file_rcs, RCS_HEAD_REV, "Initial revision", tstamp, NULL) == -1) fatal("import_new: failed to create first revision"); if ((rdp = rcs_findrev(cf->file_rcs, cf->file_rcs->rf_head)) == NULL) fatal("import_new: cannot find newly added revision"); brp = xmalloc(sizeof(*brp)); brp->rb_num = rcsnum_alloc(); rcsnum_cpy(brev, brp->rb_num, 0); TAILQ_INSERT_TAIL(&(rdp->rd_branches), brp, rb_list); if (rcs_deltatext_set(cf->file_rcs, cf->file_rcs->rf_head, bp) == -1) fatal("import_new: failed to set deltatext"); if (kflag) rcs_kwexp_set(cf->file_rcs, kflag); rcs_write(cf->file_rcs); import_printf("N %s/%s\n", import_repository, cf->file_path); rcsnum_free(branch); rcsnum_free(brev); }
static void import_update(struct cvs_file *cf) { int ret; BUF *b1, *b2, *d; char branch[CVS_REV_BUFSZ]; RCSNUM *newrev, *rev, *brev; cvs_log(LP_TRACE, "import_update(%s)", cf->file_path); if (cf->file_rcs->rf_head == NULL) fatal("no head revision in RCS file for `%s'", cf->file_path); if ((rev = rcs_translate_tag(import_branch, cf->file_rcs)) == NULL) fatal("import_update: could not translate tag `%s'", import_branch); if ((brev = rcsnum_parse(import_branch)) == NULL) fatal("import_update: rcsnum_parse failed"); b1 = rcs_rev_getbuf(cf->file_rcs, rev, RCS_KWEXP_NONE); b2 = buf_load_fd(cf->fd); ret = buf_differ(b1, b2); buf_free(b1); buf_free(b2); if (ret == 0) { import_tag(cf, brev, rev); rcsnum_free(brev); if (cvs_noexec != 1) rcs_write(cf->file_rcs); import_printf("U %s/%s\n", import_repository, cf->file_path); return; } if (cf->file_rcs->rf_branch != NULL) rcsnum_tostr(cf->file_rcs->rf_branch, branch, sizeof(branch)); if (cf->file_rcs->rf_branch == NULL || cf->in_attic == 1 || strcmp(branch, import_branch)) { import_conflicts++; import_printf("C %s/%s\n", import_repository, cf->file_path); } else { import_printf("U %s/%s\n", import_repository, cf->file_path); } if (cvs_noexec == 1) return; d = import_get_rcsdiff(cf, rev); newrev = rcsnum_inc(rev); if (rcs_rev_add(cf->file_rcs, newrev, logmsg, -1, NULL) == -1) fatal("import_update: failed to add new revision"); if (rcs_deltatext_set(cf->file_rcs, newrev, d) == -1) fatal("import_update: failed to set deltatext"); import_tag(cf, brev, newrev); if (kflag) rcs_kwexp_set(cf->file_rcs, kflag); rcsnum_free(brev); rcs_write(cf->file_rcs); }
void cvs_annotate_local(struct cvs_file *cf) { int i; char date[10], rnum[13], *p; RCSNUM *bnum, *rev; struct rcs_line *line; struct rcs_line **alines; cvs_log(LP_TRACE, "cvs_annotate_local(%s)", cf->file_path); cvs_file_classify(cf, cvs_directory_tag); if (cf->file_rcs == NULL || cf->file_rcs->rf_head == NULL) return; if (cvs_specified_tag != NULL) { if ((rev = rcs_translate_tag(cvs_specified_tag, cf->file_rcs)) == NULL) { if (!force_head) /* Stick at weird GNU cvs, ignore error. */ return; /* -f is not allowed for unknown symbols */ rev = rcsnum_parse(cvs_specified_tag); if (rev == NULL) fatal("no such tag %s", cvs_specified_tag); rcsnum_free(rev); rev = rcsnum_alloc(); rcsnum_cpy(cf->file_rcs->rf_head, rev, 0); } /* * If this is a revision in a branch, we have to go first * from HEAD to branch, then down to 1.1. After that, take * annotated branch and go up to branch revision. This must * be done this way due to different handling of "a" and * "d" in rcs file for annotation. */ if (!RCSNUM_ISBRANCHREV(rev)) { bnum = rev; } else { bnum = rcsnum_alloc(); rcsnum_cpy(rev, bnum, 2); } rcs_rev_getlines(cf->file_rcs, bnum, &alines); /* * Go into branch and receive annotations for branch revision, * with inverted "a" and "d" meaning. */ if (bnum != rev) { rcs_annotate_getlines(cf->file_rcs, rev, &alines); rcsnum_free(bnum); } rcsnum_free(rev); } else { rcs_rev_getlines(cf->file_rcs, (cvs_specified_date != -1 || cvs_directory_date != -1) ? cf->file_rcsrev : cf->file_rcs->rf_head, &alines); } /* Stick at weird GNU cvs, ignore error. */ if (alines == NULL) return; cvs_log(LP_RCS, "Annotations for %s", cf->file_path); cvs_log(LP_RCS, "***************"); for (i = 0; alines[i] != NULL; i++) { line = alines[i]; rcsnum_tostr(line->l_delta->rd_num, rnum, sizeof(rnum)); strftime(date, sizeof(date), "%d-%b-%y", &(line->l_delta->rd_date)); if (line->l_len && line->l_line[line->l_len - 1] == '\n') line->l_line[line->l_len - 1] = '\0'; else { p = xmalloc(line->l_len + 1); memcpy(p, line->l_line, line->l_len); p[line->l_len] = '\0'; if (line->l_needsfree) xfree(line->l_line); line->l_line = p; line->l_len++; line->l_needsfree = 1; } cvs_printf("%-12.12s (%-8.8s %s): %s\n", rnum, line->l_delta->rd_author, date, line->l_line); if (line->l_needsfree) xfree(line->l_line); xfree(line); } xfree(alines); }
int rcsmerge_main(int argc, char **argv) { int fd, ch, flags, kflag, status; char fpath[PATH_MAX], r1[RCS_REV_BUFSZ], r2[RCS_REV_BUFSZ]; char *rev_str1, *rev_str2; RCSFILE *file; RCSNUM *rev1, *rev2; BUF *bp; flags = 0; status = D_ERROR; rev1 = rev2 = NULL; rev_str1 = rev_str2 = NULL; while ((ch = rcs_getopt(argc, argv, "AEek:p::q::r::TVx::z:")) != -1) { switch (ch) { case 'A': /* * kept for compatibility */ break; case 'E': flags |= MERGE_EFLAG; flags |= MERGE_OFLAG; break; case 'e': flags |= MERGE_EFLAG; break; case 'k': kflag = rcs_kflag_get(rcs_optarg); if (RCS_KWEXP_INVAL(kflag)) { warnx("invalid RCS keyword substitution mode"); (usage)(); } break; case 'p': rcs_setrevstr2(&rev_str1, &rev_str2, rcs_optarg); flags |= PIPEOUT; break; case 'q': rcs_setrevstr2(&rev_str1, &rev_str2, rcs_optarg); flags |= QUIET; break; case 'r': rcs_setrevstr2(&rev_str1, &rev_str2, rcs_optarg ? rcs_optarg : ""); break; case 'T': /* * kept for compatibility */ break; case 'V': printf("%s\n", rcs_version); exit(0); case 'x': /* Use blank extension if none given. */ rcs_suffixes = rcs_optarg ? rcs_optarg : ""; break; case 'z': timezone_flag = rcs_optarg; break; default: (usage)(); } } argc -= rcs_optind; argv += rcs_optind; if (rev_str1 == NULL) { warnx("no base revision number given"); (usage)(); } if (argc < 1) { warnx("no input file"); (usage)(); } if (argc > 2 || (argc == 2 && argv[1] != NULL)) warnx("warning: excess arguments ignored"); if ((fd = rcs_choosefile(argv[0], fpath, sizeof(fpath))) < 0) err(status, "%s", fpath); if (!(flags & QUIET)) (void)fprintf(stderr, "RCS file: %s\n", fpath); if ((file = rcs_open(fpath, fd, RCS_READ)) == NULL) return (status); if (strcmp(rev_str1, "") == 0) { rev1 = rcsnum_alloc(); rcsnum_cpy(file->rf_head, rev1, 0); } else if ((rev1 = rcs_getrevnum(rev_str1, file)) == NULL) errx(D_ERROR, "invalid revision: %s", rev_str1); if (rev_str2 != NULL && strcmp(rev_str2, "") != 0) { if ((rev2 = rcs_getrevnum(rev_str2, file)) == NULL) errx(D_ERROR, "invalid revision: %s", rev_str2); } else { rev2 = rcsnum_alloc(); rcsnum_cpy(file->rf_head, rev2, 0); } if (rcsnum_cmp(rev1, rev2, 0) == 0) goto out; if ((bp = rcs_diff3(file, argv[0], rev1, rev2, flags)) == NULL) errx(D_ERROR, "failed to merge"); if (!(flags & QUIET)) { (void)rcsnum_tostr(rev1, r1, sizeof(r1)); (void)rcsnum_tostr(rev2, r2, sizeof(r2)); (void)fprintf(stderr, "Merging differences between %s and " "%s into %s%s\n", r1, r2, argv[0], (flags & PIPEOUT) ? "; result to stdout":""); } if (diff3_conflicts != 0) status = D_OVERLAPS; else status = 0; if (flags & PIPEOUT) buf_write_fd(bp, STDOUT_FILENO); else { /* XXX mode */ if (buf_write(bp, argv[0], 0644) < 0) warnx("buf_write failed"); } buf_free(bp); out: rcs_close(file); rcsnum_free(rev1); rcsnum_free(rev2); return (status); }
static void add_file(struct cvs_file *cf) { int nb, stop; char revbuf[CVS_REV_BUFSZ]; RCSNUM *head = NULL; char *tag; cvs_parse_tagfile(cf->file_wd, &tag, NULL, &nb); if (nb) { cvs_log(LP_ERR, "cannot add file on non-branch tag %s", tag); return; } if (cf->file_rcs != NULL) { head = rcs_head_get(cf->file_rcs); if (head == NULL) { cvs_log(LP_NOTICE, "no head revision in RCS file for " "%s", cf->file_path); } rcsnum_tostr(head, revbuf, sizeof(revbuf)); } stop = 0; switch (cf->file_status) { case FILE_ADDED: case FILE_CHECKOUT: if (verbosity > 1) cvs_log(LP_NOTICE, "%s has already been entered", cf->file_path); stop = 1; break; case FILE_REMOVED: if (cf->file_rcs == NULL) { cvs_log(LP_NOTICE, "cannot resurrect %s; " "RCS file removed by second party", cf->file_name); } else if (!(cf->file_flags & FILE_ON_DISK)) { add_entry(cf); /* Restore the file. */ cvs_checkout_file(cf, head, NULL, 0); cvs_printf("U %s\n", cf->file_path); cvs_log(LP_NOTICE, "%s, version %s, resurrected", cf->file_name, revbuf); cf->file_status = FILE_UPTODATE; } stop = 1; break; case FILE_CONFLICT: case FILE_LOST: case FILE_MODIFIED: case FILE_UPTODATE: if (cf->file_rcs != NULL && cf->file_rcs->rf_dead == 0) { cvs_log(LP_NOTICE, "%s already exists, with version " "number %s", cf->file_path, revbuf); stop = 1; } break; case FILE_UNKNOWN: if (cf->file_rcs != NULL && cf->file_rcs->rf_dead == 1) { cvs_log(LP_NOTICE, "re-adding file %s " "(instead of dead revision %s)", cf->file_path, revbuf); added_files++; } else if (cf->file_flags & FILE_ON_DISK) { cvs_log(LP_NOTICE, "scheduling file '%s' for addition", cf->file_path); added_files++; } else { stop = 1; } break; default: break; } if (head != NULL) rcsnum_free(head); if (stop == 1) return; add_entry(cf); }
void cvs_history_add(int type, struct cvs_file *cf, const char *argument) { BUF *buf; FILE *fp; RCSNUM *hrev; size_t len; int fd; char *cwd, *p, *rev; char revbuf[CVS_REV_BUFSZ], repo[MAXPATHLEN], fpath[MAXPATHLEN]; char timebuf[CVS_TIME_BUFSZ]; struct tm datetm; if (cvs_nolog == 1) return; if (cvs_cmdop == CVS_OP_CHECKOUT || cvs_cmdop == CVS_OP_EXPORT) { if (type != CVS_HISTORY_CHECKOUT && type != CVS_HISTORY_EXPORT) return; } cvs_log(LP_TRACE, "cvs_history_add(`%c', `%s', `%s')", historytab[type], (cf != NULL) ? cf->file_name : "", argument); /* construct repository field */ if (cvs_cmdop != CVS_OP_CHECKOUT && cvs_cmdop != CVS_OP_EXPORT) { cvs_get_repository_name((cf != NULL) ? cf->file_wd : ".", repo, sizeof(repo)); } else { cvs_get_repository_name(argument, repo, sizeof(repo)); } if (cvs_server_active == 1) { cwd = "<remote>"; } else { if (getcwd(fpath, sizeof(fpath)) == NULL) fatal("cvs_history_add: getcwd: %s", strerror(errno)); p = fpath; if (cvs_cmdop == CVS_OP_CHECKOUT || cvs_cmdop == CVS_OP_EXPORT) { if (strlcat(fpath, "/", sizeof(fpath)) >= sizeof(fpath) || strlcat(fpath, argument, sizeof(fpath)) >= sizeof(fpath)) fatal("cvs_history_add: string truncation"); } if (cvs_homedir != NULL && cvs_homedir[0] != '\0') { len = strlen(cvs_homedir); if (strncmp(cvs_homedir, fpath, len) == 0 && fpath[len] == '/') { p += len - 1; *p = '~'; } } history_compress(p, repo); cwd = xstrdup(p); } /* construct revision field */ revbuf[0] = '\0'; rev = revbuf; switch (type) { case CVS_HISTORY_TAG: strlcpy(revbuf, argument, sizeof(revbuf)); break; case CVS_HISTORY_CHECKOUT: case CVS_HISTORY_EXPORT: /* * cvs_buf_alloc uses xcalloc(), so we are safe even * if neither cvs_specified_tag nor cvs_specified_date * have been supplied. */ buf = cvs_buf_alloc(128); if (cvs_specified_tag != NULL) { cvs_buf_puts(buf, cvs_specified_tag); if (cvs_specified_date != -1) cvs_buf_putc(buf, ':'); } if (cvs_specified_date != -1) { gmtime_r(&cvs_specified_date, &datetm); strftime(timebuf, sizeof(timebuf), "%Y.%m.%d.%H.%M.%S", &datetm); cvs_buf_puts(buf, timebuf); } rev = cvs_buf_release(buf); break; case CVS_HISTORY_UPDATE_MERGED: case CVS_HISTORY_UPDATE_MERGED_ERR: case CVS_HISTORY_COMMIT_MODIFIED: case CVS_HISTORY_COMMIT_ADDED: case CVS_HISTORY_COMMIT_REMOVED: case CVS_HISTORY_UPDATE_CO: if ((hrev = rcs_head_get(cf->file_rcs)) == NULL) fatal("cvs_history_add: rcs_head_get failed"); rcsnum_tostr(hrev, revbuf, sizeof(revbuf)); rcsnum_free(hrev); break; } (void)xsnprintf(fpath, sizeof(fpath), "%s/%s", current_cvsroot->cr_dir, CVS_PATH_HISTORY); if ((fd = open(fpath, O_WRONLY|O_APPEND)) == -1) { if (errno != ENOENT) cvs_log(LP_ERR, "failed to open history file"); } else { if ((fp = fdopen(fd, "a")) != NULL) { fprintf(fp, "%c%x|%s|%s|%s|%s|%s\n", historytab[type], time(NULL), getlogin(), cwd, repo, rev, (cf != NULL) ? cf->file_name : argument); (void)fclose(fp); } else { cvs_log(LP_ERR, "failed to add entry to history file"); (void)close(fd); } } if (rev != revbuf) xfree(rev); if (cvs_server_active != 1) xfree(cwd); }
void cvs_diff_local(struct cvs_file *cf) { BUF *b1; int fd1, fd2; struct stat st; struct timespec tv[2], tv2[2]; struct tm datetm; char rbuf[CVS_REV_BUFSZ], tbuf[CVS_TIME_BUFSZ], *p1, *p2; b1 = NULL; fd1 = fd2 = -1; p1 = p2 = NULL; cvs_log(LP_TRACE, "cvs_diff_local(%s)", cf->file_path); if (cf->file_type == CVS_DIR) { if (verbosity > 1) cvs_log(LP_ERR, "Diffing inside %s", cf->file_path); return; } cvs_file_classify(cf, cvs_directory_tag); if (cvs_cmdop == CVS_OP_DIFF) { if (cf->file_ent == NULL) { cvs_log(LP_ERR, "I know nothing about %s", cf->file_path); return; } switch (cf->file_ent->ce_status) { case CVS_ENT_ADDED: if (Nflag == 0) { cvs_log(LP_ERR, "%s is a new entry, no " "comparison available", cf->file_path); return; } if (!(cf->file_flags & FILE_ON_DISK)) { cvs_log(LP_ERR, "cannot find %s", cf->file_path); return; } break; case CVS_ENT_REMOVED: if (Nflag == 0) { cvs_log(LP_ERR, "%s was removed, no " "comparison available", cf->file_path); return; } if (cf->file_rcs == NULL) { cvs_log(LP_ERR, "cannot find RCS file for %s", cf->file_path); return; } break; default: if (!(cf->file_flags & FILE_ON_DISK)) { cvs_printf("? %s\n", cf->file_path); return; } if (cf->file_rcs == NULL) { cvs_log(LP_ERR, "cannot find RCS file for %s", cf->file_path); return; } break; } } if (cf->file_status == FILE_UPTODATE && rev1 == NULL && rev2 == NULL && date1 == -1 && date2 == -1) return; if (cf->file_rcs != NULL && cf->file_rcs->rf_head == NULL) { cvs_log(LP_ERR, "no head revision in RCS file for %s\n", cf->file_path); return; } if (kflag && cf->file_rcs != NULL) rcs_kwexp_set(cf->file_rcs, kflag); if (cf->file_rcs == NULL) diff_rev1 = NULL; else if (rev1 != NULL || date1 != -1) { cvs_specified_date = date1; diff_rev1 = rcs_translate_tag(rev1, cf->file_rcs); if (diff_rev1 == NULL && cvs_cmdop == CVS_OP_DIFF) { if (rev1 != NULL) { cvs_log(LP_ERR, "tag %s not in file %s", rev1, cf->file_path); goto cleanup; } else if (Nflag) { diff_rev1 = NULL; } else { gmtime_r(&cvs_specified_date, &datetm); strftime(tbuf, sizeof(tbuf), "%Y.%m.%d.%H.%M.%S", &datetm); cvs_log(LP_ERR, "no revision for date %s in " "file %s", tbuf, cf->file_path); goto cleanup; } } else if (diff_rev1 == NULL && cvs_cmdop == CVS_OP_RDIFF && force_head) { /* -f is not allowed for unknown symbols */ if ((diff_rev1 = rcsnum_parse(rev1)) == NULL) fatal("no such tag %s", rev1); rcsnum_free(diff_rev1); diff_rev1 = cf->file_rcs->rf_head; } cvs_specified_date = -1; } else if (cvs_cmdop == CVS_OP_DIFF) { if (cf->file_ent->ce_status == CVS_ENT_ADDED) diff_rev1 = NULL; else diff_rev1 = cf->file_ent->ce_rev; } if (cf->file_rcs == NULL) diff_rev2 = NULL; else if (rev2 != NULL || date2 != -1) { cvs_specified_date = date2; diff_rev2 = rcs_translate_tag(rev2, cf->file_rcs); if (diff_rev2 == NULL && cvs_cmdop == CVS_OP_DIFF) { if (rev2 != NULL) { cvs_log(LP_ERR, "tag %s not in file %s", rev2, cf->file_path); goto cleanup; } else if (Nflag) { diff_rev2 = NULL; } else { gmtime_r(&cvs_specified_date, &datetm); strftime(tbuf, sizeof(tbuf), "%Y.%m.%d.%H.%M.%S", &datetm); cvs_log(LP_ERR, "no revision for date %s in " "file %s", tbuf, cf->file_path); goto cleanup; } } else if (diff_rev2 == NULL && cvs_cmdop == CVS_OP_RDIFF && force_head) { /* -f is not allowed for unknown symbols */ if ((diff_rev2 = rcsnum_parse(rev2)) == NULL) fatal("no such tag %s", rev2); rcsnum_free(diff_rev2); diff_rev2 = cf->file_rcs->rf_head; } cvs_specified_date = -1; } else if (cvs_cmdop == CVS_OP_RDIFF) diff_rev2 = cf->file_rcs->rf_head; else if (cf->file_ent->ce_status == CVS_ENT_REMOVED) diff_rev2 = NULL; if (diff_rev1 != NULL && diff_rev2 != NULL && rcsnum_cmp(diff_rev1, diff_rev2, 0) == 0) goto cleanup; switch (cvs_cmdop) { case CVS_OP_DIFF: if (cf->file_status == FILE_UPTODATE) { if (diff_rev2 == NULL && !rcsnum_cmp(diff_rev1, cf->file_rcsrev, 0)) goto cleanup; } break; case CVS_OP_RDIFF: if (diff_rev1 == NULL && diff_rev2 == NULL) goto cleanup; break; } cvs_printf("Index: %s\n", cf->file_path); if (cvs_cmdop == CVS_OP_DIFF) cvs_printf("%s\nRCS file: %s\n", RCS_DIFF_DIV, cf->file_rcs != NULL ? cf->file_rpath : cf->file_path); if (diff_rev1 != NULL) { if (cvs_cmdop == CVS_OP_DIFF && diff_rev1 != NULL) { (void)rcsnum_tostr(diff_rev1, rbuf, sizeof(rbuf)); cvs_printf("retrieving revision %s\n", rbuf); } tv[0].tv_sec = rcs_rev_getdate(cf->file_rcs, diff_rev1); tv[0].tv_nsec = 0; tv[1] = tv[0]; (void)xasprintf(&p1, "%s/diff1.XXXXXXXXXX", cvs_tmpdir); fd1 = rcs_rev_write_stmp(cf->file_rcs, diff_rev1, p1, 0); if (futimens(fd1, tv) == -1) fatal("cvs_diff_local: futimens failed"); } if (diff_rev2 != NULL) { if (cvs_cmdop == CVS_OP_DIFF && rev2 != NULL) { (void)rcsnum_tostr(diff_rev2, rbuf, sizeof(rbuf)); cvs_printf("retrieving revision %s\n", rbuf); } tv2[0].tv_sec = rcs_rev_getdate(cf->file_rcs, diff_rev2); tv2[0].tv_nsec = 0; tv2[1] = tv2[0]; (void)xasprintf(&p2, "%s/diff2.XXXXXXXXXX", cvs_tmpdir); fd2 = rcs_rev_write_stmp(cf->file_rcs, diff_rev2, p2, 0); if (futimens(fd2, tv2) == -1) fatal("cvs_diff_local: futimens failed"); } else if (cvs_cmdop == CVS_OP_DIFF && (cf->file_flags & FILE_ON_DISK) && cf->file_ent->ce_status != CVS_ENT_REMOVED) { (void)xasprintf(&p2, "%s/diff2.XXXXXXXXXX", cvs_tmpdir); if (cvs_server_active == 1 && cf->fd == -1) { tv2[0].tv_sec = rcs_rev_getdate(cf->file_rcs, cf->file_ent->ce_rev); tv2[0].tv_nsec = 0; tv2[1] = tv2[0]; fd2 = rcs_rev_write_stmp(cf->file_rcs, cf->file_ent->ce_rev, p2, 0); if (futimens(fd2, tv2) == -1) fatal("cvs_diff_local: futimens failed"); } else { if (fstat(cf->fd, &st) == -1) fatal("fstat failed %s", strerror(errno)); b1 = buf_load_fd(cf->fd); tv2[0].tv_sec = st.st_mtime; tv2[0].tv_nsec = 0; tv2[1] = tv2[0]; fd2 = buf_write_stmp(b1, p2, tv2); buf_free(b1); } } switch (cvs_cmdop) { case CVS_OP_DIFF: cvs_printf("%s", diffargs); if (rev1 != NULL && diff_rev1 != NULL) { (void)rcsnum_tostr(diff_rev1, rbuf, sizeof(rbuf)); cvs_printf(" -r%s", rbuf); if (rev2 != NULL && diff_rev2 != NULL) { (void)rcsnum_tostr(diff_rev2, rbuf, sizeof(rbuf)); cvs_printf(" -r%s", rbuf); } } if (diff_rev2 == NULL) cvs_printf(" %s", cf->file_path); cvs_printf("\n"); break; case CVS_OP_RDIFF: cvs_printf("diff "); switch (diff_format) { case D_CONTEXT: cvs_printf("-c "); break; case D_RCSDIFF: cvs_printf("-n "); break; case D_UNIFIED: cvs_printf("-u "); break; default: break; } if (diff_rev1 == NULL) { cvs_printf("%s ", CVS_PATH_DEVNULL); } else { (void)rcsnum_tostr(diff_rev1, rbuf, sizeof(rbuf)); cvs_printf("%s:%s ", cf->file_path, rbuf); } if (diff_rev2 == NULL) { cvs_printf("%s:removed\n", cf->file_path); } else { (void)rcsnum_tostr(diff_rev2 != NULL ? diff_rev2 : cf->file_rcs->rf_head, rbuf, sizeof(rbuf)); cvs_printf("%s:%s\n", cf->file_path, rbuf); } break; } if (fd1 == -1) { if ((fd1 = open(CVS_PATH_DEVNULL, O_RDONLY, 0)) == -1) fatal("cannot open %s", CVS_PATH_DEVNULL); } if (fd2 == -1) { if ((fd2 = open(CVS_PATH_DEVNULL, O_RDONLY, 0)) == -1) fatal("cannot open %s", CVS_PATH_DEVNULL); } if (diffreg(p1 != NULL ? cf->file_path : CVS_PATH_DEVNULL, p2 != NULL ? cf->file_path : CVS_PATH_DEVNULL, fd1, fd2, NULL, dflags) == D_ERROR) fatal("cvs_diff_local: failed to get RCS patch"); close(fd1); close(fd2); worklist_run(&temp_files, worklist_unlink); if (p1 != NULL) xfree(p1); if (p2 != NULL) xfree(p2); cleanup: if (diff_rev1 != NULL && (cf->file_rcs == NULL || diff_rev1 != cf->file_rcs->rf_head) && (cf->file_ent == NULL || diff_rev1 != cf->file_ent->ce_rev)) xfree(diff_rev1); diff_rev1 = NULL; if (diff_rev2 != NULL && (cf->file_rcs == NULL || diff_rev2 != cf->file_rcs->rf_head)) xfree(diff_rev2); diff_rev2 = NULL; }