Annotation of src/usr.bin/cvs/commit.c, Revision 1.122
1.122 ! tobias 1: /* $OpenBSD: commit.c,v 1.121 2008/01/28 21:26:51 tobias Exp $ */
1.1 jfb 2: /*
1.55 joris 3: * Copyright (c) 2006 Joris Vink <joris@openbsd.org>
1.71 xsa 4: * Copyright (c) 2006 Xavier Santolaria <xsa@openbsd.org>
1.1 jfb 5: *
1.55 joris 6: * Permission to use, copy, modify, and distribute this software for any
7: * purpose with or without fee is hereby granted, provided that the above
8: * copyright notice and this permission notice appear in all copies.
1.1 jfb 9: *
1.55 joris 10: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1.1 jfb 17: */
18:
1.105 otto 19: #include <sys/stat.h>
20:
21: #include <errno.h>
22: #include <fcntl.h>
23: #include <string.h>
24: #include <unistd.h>
1.1 jfb 25:
26: #include "cvs.h"
1.55 joris 27: #include "diff.h"
1.80 joris 28: #include "remote.h"
1.1 jfb 29:
1.55 joris 30: void cvs_commit_local(struct cvs_file *);
1.86 joris 31: void cvs_commit_check_files(struct cvs_file *);
1.55 joris 32:
1.112 joris 33: static BUF *commit_diff(struct cvs_file *, RCSNUM *, int);
1.71 xsa 34: static void commit_desc_set(struct cvs_file *);
1.55 joris 35:
36: struct cvs_flisthead files_affected;
1.86 joris 37: struct cvs_flisthead files_added;
38: struct cvs_flisthead files_removed;
39: struct cvs_flisthead files_modified;
40:
1.55 joris 41: int conflicts_found;
1.86 joris 42: char *logmsg = NULL;
1.34 jfb 43:
44: struct cvs_cmd cvs_cmd_commit = {
1.74 joris 45: CVS_OP_COMMIT, 0, "commit",
1.55 joris 46: { "ci", "com" },
1.34 jfb 47: "Check files into the repository",
48: "[-flR] [-F logfile | -m msg] [-r rev] ...",
49: "F:flm:Rr:",
1.18 joris 50: NULL,
1.55 joris 51: cvs_commit
1.18 joris 52: };
1.1 jfb 53:
1.55 joris 54: int
55: cvs_commit(int argc, char **argv)
1.1 jfb 56: {
1.121 tobias 57: int ch, Fflag, mflag;
1.55 joris 58: char *arg = ".";
1.58 joris 59: int flags;
1.55 joris 60: struct cvs_recursion cr;
1.3 krapht 61:
1.58 joris 62: flags = CR_RECURSE_DIRS;
1.121 tobias 63: Fflag = mflag = 0;
1.58 joris 64:
1.55 joris 65: while ((ch = getopt(argc, argv, cvs_cmd_commit.cmd_opts)) != -1) {
1.1 jfb 66: switch (ch) {
67: case 'F':
1.121 tobias 68: /* free previously assigned value */
69: if (logmsg != NULL)
70: xfree(logmsg);
1.88 joris 71: logmsg = cvs_logmsg_read(optarg);
1.121 tobias 72: Fflag = 1;
1.1 jfb 73: break;
1.82 xsa 74: case 'f':
75: break;
1.1 jfb 76: case 'l':
1.58 joris 77: flags &= ~CR_RECURSE_DIRS;
1.1 jfb 78: break;
79: case 'm':
1.121 tobias 80: /* free previously assigned value */
81: if (logmsg != NULL)
82: xfree(logmsg);
1.55 joris 83: logmsg = xstrdup(optarg);
1.121 tobias 84: mflag = 1;
1.55 joris 85: break;
1.82 xsa 86: case 'R':
1.120 tobias 87: flags |= CR_RECURSE_DIRS;
1.82 xsa 88: break;
1.55 joris 89: case 'r':
1.1 jfb 90: break;
91: default:
1.55 joris 92: fatal("%s", cvs_cmd_commit.cmd_synopsis);
1.1 jfb 93: }
94: }
95:
1.55 joris 96: argc -= optind;
97: argv += optind;
1.121 tobias 98:
99: /* -F and -m are mutually exclusive */
100: if (Fflag && mflag)
101: fatal("cannot specify both a log file and a message");
1.1 jfb 102:
1.86 joris 103: TAILQ_INIT(&files_affected);
104: TAILQ_INIT(&files_added);
105: TAILQ_INIT(&files_removed);
106: TAILQ_INIT(&files_modified);
107: conflicts_found = 0;
108:
109: cr.enterdir = NULL;
110: cr.leavedir = NULL;
111: cr.fileproc = cvs_commit_check_files;
112: cr.flags = flags;
113:
114: if (argc > 0)
115: cvs_file_run(argc, argv, &cr);
116: else
117: cvs_file_run(1, &arg, &cr);
118:
119: if (conflicts_found != 0)
120: fatal("%d conflicts found, please correct these first",
121: conflicts_found);
1.92 joris 122:
123: if (TAILQ_EMPTY(&files_affected))
124: return (0);
1.86 joris 125:
126: if (logmsg == NULL && cvs_server_active == 0) {
127: logmsg = cvs_logmsg_create(&files_added, &files_removed,
128: &files_modified);
129: }
130:
1.55 joris 131: if (logmsg == NULL)
1.86 joris 132: fatal("This shouldnt happen, honestly!");
1.87 joris 133:
134: cvs_file_freelist(&files_modified);
135: cvs_file_freelist(&files_removed);
136: cvs_file_freelist(&files_added);
1.80 joris 137:
138: if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
1.89 joris 139: cvs_client_connect_to_server();
1.80 joris 140: cr.fileproc = cvs_client_sendfile;
141:
142: if (argc > 0)
143: cvs_file_run(argc, argv, &cr);
144: else
145: cvs_file_run(1, &arg, &cr);
1.99 xsa 146:
147: if (!(flags & CR_RECURSE_DIRS))
148: cvs_client_send_request("Argument -l");
1.80 joris 149:
1.109 joris 150: if (logmsg != NULL)
151: cvs_client_send_logmsg(logmsg);
1.80 joris 152:
153: cvs_client_send_files(argv, argc);
154: cvs_client_senddir(".");
155: cvs_client_send_request("ci");
156: cvs_client_get_responses();
1.86 joris 157: } else {
158: cr.fileproc = cvs_commit_local;
159: cvs_file_walklist(&files_affected, &cr);
160: cvs_file_freelist(&files_affected);
1.80 joris 161: }
1.1 jfb 162:
1.18 joris 163: return (0);
164: }
1.1 jfb 165:
1.55 joris 166: void
1.86 joris 167: cvs_commit_check_files(struct cvs_file *cf)
1.18 joris 168: {
1.112 joris 169: char *tag;
170: RCSNUM *branch, *brev;
171: char rev[CVS_REV_BUFSZ];
172:
1.86 joris 173: cvs_log(LP_TRACE, "cvs_commit_check_files(%s)", cf->file_path);
1.44 joris 174:
1.108 joris 175: if (current_cvsroot->cr_method != CVS_METHOD_LOCAL)
176: cvs_remote_classify_file(cf);
177: else
1.110 joris 178: cvs_file_classify(cf, cvs_directory_tag);
1.59 joris 179:
180: if (cf->file_type == CVS_DIR) {
181: if (verbosity > 1)
182: cvs_log(LP_NOTICE, "Examining %s", cf->file_path);
183: return;
184: }
1.32 joris 185:
1.55 joris 186: if (cf->file_status == FILE_CONFLICT ||
1.79 joris 187: cf->file_status == FILE_UNLINK) {
1.55 joris 188: conflicts_found++;
1.79 joris 189: return;
190: }
1.57 joris 191:
1.63 joris 192: if (cf->file_status != FILE_REMOVED &&
193: update_has_conflict_markers(cf)) {
1.60 joris 194: cvs_log(LP_ERR, "conflict: unresolved conflicts in %s from "
195: "merging, please fix these first", cf->file_path);
196: conflicts_found++;
1.79 joris 197: return;
1.60 joris 198: }
199:
1.57 joris 200: if (cf->file_status == FILE_MERGE ||
1.72 joris 201: cf->file_status == FILE_PATCH ||
1.79 joris 202: cf->file_status == FILE_CHECKOUT ||
203: cf->file_status == FILE_LOST) {
1.57 joris 204: cvs_log(LP_ERR, "conflict: %s is not up-to-date",
205: cf->file_path);
206: conflicts_found++;
1.79 joris 207: return;
1.57 joris 208: }
1.55 joris 209:
1.112 joris 210: if (current_cvsroot->cr_method == CVS_METHOD_LOCAL) {
211: tag = cvs_directory_tag;
212: if (cf->file_ent != NULL)
213: tag = cf->file_ent->ce_tag;
214:
215: if (tag != NULL && cf->file_rcs != NULL) {
216: brev = rcs_sym_getrev(cf->file_rcs, tag);
217: if (brev != NULL) {
218: if (RCSNUM_ISBRANCH(brev))
219: goto next;
220: }
221:
222: brev = rcs_translate_tag(tag, cf->file_rcs);
223:
224: if (brev == NULL) {
225: fatal("failed to resolve tag: %s",
226: cf->file_ent->ce_tag);
227: }
228:
229: rcsnum_tostr(brev, rev, sizeof(rev));
230: if ((branch = rcsnum_revtobr(brev)) == NULL) {
231: cvs_log(LP_ERR, "%s is not a branch revision",
232: rev);
233: conflicts_found++;
234: return;
235: }
236:
237: if (!RCSNUM_ISBRANCHREV(brev)) {
238: cvs_log(LP_ERR, "%s is not a branch revision",
239: rev);
240: conflicts_found++;
241: return;
242: }
243:
244: rcsnum_tostr(branch, rev, sizeof(rev));
245: if (!RCSNUM_ISBRANCH(branch)) {
246: cvs_log(LP_ERR, "%s (%s) is not a branch",
247: cf->file_ent->ce_tag, rev);
248: conflicts_found++;
249: return;
250: }
251: }
252: }
253:
254: next:
1.55 joris 255: if (cf->file_status == FILE_ADDED ||
256: cf->file_status == FILE_REMOVED ||
257: cf->file_status == FILE_MODIFIED)
1.110 joris 258: cvs_file_get(cf->file_path, 0, &files_affected);
1.86 joris 259:
260: switch (cf->file_status) {
261: case FILE_ADDED:
1.110 joris 262: cvs_file_get(cf->file_path, 0, &files_added);
1.86 joris 263: break;
264: case FILE_REMOVED:
1.110 joris 265: cvs_file_get(cf->file_path, 0, &files_removed);
1.86 joris 266: break;
267: case FILE_MODIFIED:
1.110 joris 268: cvs_file_get(cf->file_path, 0, &files_modified);
1.86 joris 269: break;
270: }
1.55 joris 271: }
1.1 jfb 272:
1.55 joris 273: void
274: cvs_commit_local(struct cvs_file *cf)
275: {
1.112 joris 276: char *tag;
1.91 joris 277: BUF *b, *d;
1.112 joris 278: int onbranch, isnew, histtype;
279: RCSNUM *nrev, *crev, *rrev, *brev;
1.102 xsa 280: int openflags, rcsflags;
1.119 tobias 281: char rbuf[CVS_REV_BUFSZ], nbuf[CVS_REV_BUFSZ];
1.56 joris 282: CVSENTRIES *entlist;
1.100 otto 283: char attic[MAXPATHLEN], repo[MAXPATHLEN], rcsfile[MAXPATHLEN];
1.17 joris 284:
1.55 joris 285: cvs_log(LP_TRACE, "cvs_commit_local(%s)", cf->file_path);
1.110 joris 286: cvs_file_classify(cf, cvs_directory_tag);
1.69 joris 287:
288: if (cvs_noexec == 1)
289: return;
1.35 xsa 290:
1.64 joris 291: if (cf->file_type != CVS_FILE)
292: fatal("cvs_commit_local: '%s' is not a file", cf->file_path);
293:
1.107 joris 294: if (cf->file_status != FILE_MODIFIED &&
295: cf->file_status != FILE_ADDED &&
296: cf->file_status != FILE_REMOVED) {
297: cvs_log(LP_ERR, "skipping bogus file `%s'", cf->file_path);
298: return;
299: }
300:
1.112 joris 301: onbranch = 0;
302: nrev = RCS_HEAD_REV;
303: crev = NULL;
304: rrev = NULL;
305:
1.115 joris 306: if (cf->file_rcs != NULL && cf->file_rcs->rf_branch != NULL) {
1.114 joris 307: rcsnum_free(cf->file_rcs->rf_branch);
308: cf->file_rcs->rf_branch = NULL;
309: }
310:
1.56 joris 311: if (cf->file_status == FILE_MODIFIED ||
1.66 joris 312: cf->file_status == FILE_REMOVED || (cf->file_status == FILE_ADDED
1.93 joris 313: && cf->file_rcs != NULL && cf->file_rcs->rf_dead == 1)) {
1.112 joris 314: rrev = rcs_head_get(cf->file_rcs);
315: crev = rcs_head_get(cf->file_rcs);
1.116 tobias 316: if (crev == NULL || rrev == NULL)
317: fatal("RCS head empty or missing in %s\n",
318: cf->file_rcs->rf_path);
1.112 joris 319:
320: tag = cvs_directory_tag;
321: if (cf->file_ent != NULL && cf->file_ent->ce_tag != NULL)
322: tag = cf->file_ent->ce_tag;
323:
324: if (tag != NULL) {
325: rcsnum_free(crev);
326: crev = rcs_translate_tag(tag, cf->file_rcs);
327: if (crev == NULL) {
328: fatal("failed to resolve existing tag: %s",
329: tag);
330: }
331:
332: if (RCSNUM_ISBRANCHREV(crev)) {
333: nrev = rcsnum_alloc();
334: rcsnum_cpy(crev, nrev, 0);
335: rcsnum_inc(nrev);
336: } else if (!RCSNUM_ISBRANCH(crev)) {
337: brev = rcs_sym_getrev(cf->file_rcs, tag);
338: if (brev == NULL)
339: fatal("no more tag?");
340: nrev = rcsnum_brtorev(brev);
341: if (nrev == NULL)
342: fatal("failed to create branch rev");
343: } else {
344: fatal("this isnt suppose to happen, honestly");
345: }
346:
347: rcsnum_free(rrev);
348: rrev = rcsnum_branch_root(nrev);
349:
350: /* branch stuff was checked in cvs_commit_check_files */
351: onbranch = 1;
352: }
353:
354: rcsnum_tostr(crev, rbuf, sizeof(rbuf));
1.93 joris 355: } else {
1.61 joris 356: strlcpy(rbuf, "Non-existent", sizeof(rbuf));
1.93 joris 357: }
1.61 joris 358:
1.67 joris 359: isnew = 0;
1.66 joris 360: if (cf->file_status == FILE_ADDED) {
1.67 joris 361: isnew = 1;
1.66 joris 362: rcsflags = RCS_CREATE;
363: openflags = O_CREAT | O_TRUNC | O_WRONLY;
364: if (cf->file_rcs != NULL) {
1.106 niallo 365: if (cf->in_attic == 0)
1.66 joris 366: cvs_log(LP_ERR, "warning: expected %s "
367: "to be in the Attic", cf->file_path);
368:
369: if (cf->file_rcs->rf_dead == 0)
370: cvs_log(LP_ERR, "warning: expected %s "
371: "to be dead", cf->file_path);
372:
373: cvs_get_repository_path(cf->file_wd, repo, MAXPATHLEN);
1.102 xsa 374: (void)xsnprintf(rcsfile, MAXPATHLEN, "%s/%s%s",
1.66 joris 375: repo, cf->file_name, RCS_FILE_EXT);
376:
377: if (rename(cf->file_rpath, rcsfile) == -1)
378: fatal("cvs_commit_local: failed to move %s "
379: "outside the Attic: %s", cf->file_path,
380: strerror(errno));
381:
382: xfree(cf->file_rpath);
383: cf->file_rpath = xstrdup(rcsfile);
384:
385: rcsflags = RCS_READ | RCS_PARSE_FULLY;
386: openflags = O_RDONLY;
387: rcs_close(cf->file_rcs);
1.67 joris 388: isnew = 0;
1.66 joris 389: }
390:
391: cf->repo_fd = open(cf->file_rpath, openflags);
1.61 joris 392: if (cf->repo_fd < 0)
393: fatal("cvs_commit_local: %s", strerror(errno));
394:
395: cf->file_rcs = rcs_open(cf->file_rpath, cf->repo_fd,
1.103 otto 396: rcsflags, 0444);
1.61 joris 397: if (cf->file_rcs == NULL)
398: fatal("cvs_commit_local: failed to create RCS file "
399: "for %s", cf->file_path);
1.71 xsa 400:
401: commit_desc_set(cf);
1.61 joris 402: }
1.36 joris 403:
1.77 reyk 404: if (verbosity > 1) {
405: cvs_printf("Checking in %s:\n", cf->file_path);
406: cvs_printf("%s <- %s\n", cf->file_rpath, cf->file_path);
407: cvs_printf("old revision: %s; ", rbuf);
408: }
1.7 jfb 409:
1.112 joris 410: if (isnew == 0 && onbranch == 0)
411: d = commit_diff(cf, cf->file_rcs->rf_head, 0);
1.7 jfb 412:
1.56 joris 413: if (cf->file_status == FILE_REMOVED) {
1.112 joris 414: b = rcs_rev_getbuf(cf->file_rcs, crev, 0);
1.56 joris 415: if (b == NULL)
1.112 joris 416: fatal("cvs_commit_local: failed to get crev");
417: } else if (onbranch == 1) {
418: b = commit_diff(cf, crev, 1);
1.61 joris 419: } else {
1.73 joris 420: if ((b = cvs_buf_load_fd(cf->fd, BUF_AUTOEXT)) == NULL)
1.56 joris 421: fatal("cvs_commit_local: failed to load file");
422: }
1.7 jfb 423:
1.112 joris 424: if (isnew == 0 && onbranch == 0) {
425: if (rcs_deltatext_set(cf->file_rcs, crev, d) == -1)
1.61 joris 426: fatal("cvs_commit_local: failed to set delta");
427: }
1.3 krapht 428:
1.112 joris 429: if (rcs_rev_add(cf->file_rcs, nrev, logmsg, -1, NULL) == -1)
1.55 joris 430: fatal("cvs_commit_local: failed to add new revision");
1.3 krapht 431:
1.112 joris 432: if (nrev == RCS_HEAD_REV)
433: nrev = cf->file_rcs->rf_head;
434:
435: if (rcs_deltatext_set(cf->file_rcs, nrev, b) == -1)
1.55 joris 436: fatal("cvs_commit_local: failed to set new HEAD delta");
1.3 krapht 437:
1.56 joris 438: if (cf->file_status == FILE_REMOVED) {
1.112 joris 439: if (rcs_state_set(cf->file_rcs, nrev, RCS_STATE_DEAD) == -1)
1.56 joris 440: fatal("cvs_commit_local: failed to set state");
1.101 xsa 441: }
442:
443: if (cf->file_status == FILE_ADDED && cf->file_ent->ce_opts != NULL) {
444: int kflag;
445:
446: kflag = rcs_kflag_get(cf->file_ent->ce_opts + 2);
447: rcs_kwexp_set(cf->file_rcs, kflag);
1.56 joris 448: }
449:
1.55 joris 450: rcs_write(cf->file_rcs);
1.6 jfb 451:
1.56 joris 452: if (cf->file_status == FILE_REMOVED) {
1.77 reyk 453: strlcpy(nbuf, "Removed", sizeof(nbuf));
1.61 joris 454: } else if (cf->file_status == FILE_ADDED) {
1.66 joris 455: if (cf->file_rcs->rf_dead == 1)
1.77 reyk 456: strlcpy(nbuf, "Initial Revision", sizeof(nbuf));
1.63 joris 457: else
1.112 joris 458: rcsnum_tostr(nrev, nbuf, sizeof(nbuf));
1.56 joris 459: } else if (cf->file_status == FILE_MODIFIED) {
1.112 joris 460: rcsnum_tostr(nrev, nbuf, sizeof(nbuf));
1.56 joris 461: }
462:
1.77 reyk 463: if (verbosity > 1)
464: cvs_printf("new revision: %s\n", nbuf);
1.3 krapht 465:
1.55 joris 466: (void)unlink(cf->file_path);
467: (void)close(cf->fd);
468: cf->fd = -1;
1.56 joris 469:
470: if (cf->file_status != FILE_REMOVED) {
1.112 joris 471: cvs_checkout_file(cf, nrev, NULL, CO_COMMIT);
1.56 joris 472: } else {
473: entlist = cvs_ent_open(cf->file_wd);
474: cvs_ent_remove(entlist, cf->file_name);
475: cvs_ent_close(entlist, ENT_SYNC);
1.64 joris 476:
477: cvs_get_repository_path(cf->file_wd, repo, MAXPATHLEN);
478:
1.102 xsa 479: (void)xsnprintf(attic, MAXPATHLEN, "%s/%s",
480: repo, CVS_PATH_ATTIC);
1.64 joris 481:
482: if (mkdir(attic, 0755) == -1 && errno != EEXIST)
483: fatal("cvs_commit_local: failed to create Attic");
484:
1.102 xsa 485: (void)xsnprintf(attic, MAXPATHLEN, "%s/%s/%s%s", repo,
1.64 joris 486: CVS_PATH_ATTIC, cf->file_name, RCS_FILE_EXT);
487:
488: if (rename(cf->file_rpath, attic) == -1)
489: fatal("cvs_commit_local: failed to move %s to Attic",
490: cf->file_path);
491:
1.85 joris 492: if (cvs_server_active == 1)
493: cvs_server_update_entry("Remove-entry", cf);
1.56 joris 494: }
1.3 krapht 495:
1.77 reyk 496: if (verbosity > 1)
497: cvs_printf("done\n");
498: else {
499: cvs_log(LP_NOTICE, "checking in '%s'; revision %s -> %s",
500: cf->file_path, rbuf, nbuf);
501: }
1.107 joris 502:
503: switch (cf->file_status) {
504: case FILE_MODIFIED:
505: histtype = CVS_HISTORY_COMMIT_MODIFIED;
506: break;
507: case FILE_ADDED:
508: histtype = CVS_HISTORY_COMMIT_ADDED;
509: break;
510: case FILE_REMOVED:
511: histtype = CVS_HISTORY_COMMIT_REMOVED;
512: break;
513: }
514:
515: cvs_history_add(histtype, cf, NULL);
1.39 xsa 516: }
517:
1.91 joris 518: static BUF *
1.112 joris 519: commit_diff(struct cvs_file *cf, RCSNUM *rev, int reverse)
1.39 xsa 520: {
1.112 joris 521: char *p1, *p2, *p;
1.122 ! tobias 522: BUF *b;
1.97 joris 523:
524: (void)xasprintf(&p1, "%s/diff1.XXXXXXXXXX", cvs_tmpdir);
1.39 xsa 525:
1.63 joris 526: if (cf->file_status == FILE_MODIFIED ||
527: cf->file_status == FILE_ADDED) {
1.122 ! tobias 528: if ((b = cvs_buf_load_fd(cf->fd, BUF_AUTOEXT)) == NULL)
1.118 tobias 529: fatal("commit_diff: failed to load '%s'",
1.56 joris 530: cf->file_path);
1.122 ! tobias 531: cvs_buf_write_stmp(b, p1, NULL);
! 532: cvs_buf_free(b);
1.63 joris 533: } else {
1.112 joris 534: rcs_rev_write_stmp(cf->file_rcs, rev, p1, 0);
1.56 joris 535: }
1.3 krapht 536:
1.97 joris 537: (void)xasprintf(&p2, "%s/diff2.XXXXXXXXXX", cvs_tmpdir);
1.117 tobias 538: rcs_rev_write_stmp(cf->file_rcs, rev, p2, RCS_KWEXP_NONE);
1.55 joris 539:
1.122 ! tobias 540: if ((b = cvs_buf_alloc(128, BUF_AUTOEXT)) == NULL)
1.112 joris 541: fatal("commit_diff: failed to create diff buf");
1.55 joris 542:
543: diff_format = D_RCSDIFF;
1.112 joris 544:
545: if (reverse == 1) {
546: p = p1;
547: p1 = p2;
548: p2 = p;
549: }
550:
1.122 ! tobias 551: if (cvs_diffreg(p1, p2, b) == D_ERROR)
1.112 joris 552: fatal("commit_diff: failed to get RCS patch");
1.96 joris 553:
554: xfree(p1);
555: xfree(p2);
1.55 joris 556:
1.122 ! tobias 557: return (b);
1.71 xsa 558: }
559:
560: static void
561: commit_desc_set(struct cvs_file *cf)
562: {
563: BUF *bp;
1.102 xsa 564: int fd;
1.100 otto 565: char desc_path[MAXPATHLEN], *desc;
1.71 xsa 566:
1.102 xsa 567: (void)xsnprintf(desc_path, MAXPATHLEN, "%s/%s%s",
1.71 xsa 568: CVS_PATH_CVSDIR, cf->file_name, CVS_DESCR_FILE_EXT);
569:
1.100 otto 570: if ((fd = open(desc_path, O_RDONLY)) == -1)
1.71 xsa 571: return;
572:
1.78 joris 573: bp = cvs_buf_load_fd(fd, BUF_AUTOEXT);
1.71 xsa 574: cvs_buf_putc(bp, '\0');
575: desc = cvs_buf_release(bp);
576:
577: rcs_desc_set(cf->file_rcs, desc);
578:
1.76 joris 579: (void)close(fd);
1.71 xsa 580: (void)cvs_unlink(desc_path);
581:
582: xfree(desc);
1.1 jfb 583: }