Annotation of src/usr.bin/cvs/diff.c, Revision 1.160
1.160 ! nicm 1: /* $OpenBSD: diff.c,v 1.159 2010/07/30 21:47:18 ray Exp $ */
1.1 jfb 2: /*
1.136 tobias 3: * Copyright (c) 2008 Tobias Stoeckmann <tobias@openbsd.org>
1.91 joris 4: * Copyright (c) 2006 Joris Vink <joris@openbsd.org>
1.1 jfb 5: *
1.91 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.
9: *
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.118 otto 19: #include <sys/stat.h>
1.125 tobias 20: #include <sys/time.h>
1.118 otto 21:
22: #include <errno.h>
1.131 joris 23: #include <fcntl.h>
1.125 tobias 24: #include <stdlib.h>
1.118 otto 25: #include <string.h>
1.139 tobias 26: #include <time.h>
1.118 otto 27: #include <unistd.h>
1.1 jfb 28:
29: #include "cvs.h"
1.56 niallo 30: #include "diff.h"
1.108 joris 31: #include "remote.h"
1.86 joris 32:
1.91 joris 33: void cvs_diff_local(struct cvs_file *);
1.46 xsa 34:
1.154 ray 35: static int dflags = 0;
1.126 tobias 36: static int Nflag = 0;
37: static int force_head = 0;
38: static char *koptstr;
39: static char *rev1 = NULL;
40: static char *rev2 = NULL;
1.137 tobias 41: static time_t date1 = -1;
42: static time_t date2 = -1;
1.144 tobias 43: static char *dateflag1 = NULL;
44: static char *dateflag2 = NULL;
1.94 joris 45:
1.36 jfb 46: struct cvs_cmd cvs_cmd_diff = {
1.124 tobias 47: CVS_OP_DIFF, CVS_USE_WDIR, "diff",
1.36 jfb 48: { "di", "dif" },
49: "Show differences between revisions",
1.152 sthen 50: "[-abcdilNnpRuw] [[-D date] [-r rev] [-D date2 | -r rev2]] "
1.43 xsa 51: "[-k mode] [file ...]",
1.158 nicm 52: "abcfC:dD:ik:lNnpr:RuU:w",
1.125 tobias 53: NULL,
54: cvs_diff
55: };
56:
57: struct cvs_cmd cvs_cmd_rdiff = {
58: CVS_OP_RDIFF, 0, "rdiff",
59: { "patch", "pa" },
60: "Show differences between revisions",
61: "[-flR] [-c | -u] [-s | -t] [-V ver] -D date | -r rev\n"
62: "[-D date2 | -r rev2] [-k mode] module ...",
1.126 tobias 63: "cfD:k:lr:RuV:",
1.36 jfb 64: NULL,
1.91 joris 65: cvs_diff
1.36 jfb 66: };
67:
1.91 joris 68: int
69: cvs_diff(int argc, char **argv)
1.1 jfb 70: {
1.127 tobias 71: int ch, flags;
1.91 joris 72: char *arg = ".";
1.158 nicm 73: const char *errstr;
1.91 joris 74: struct cvs_recursion cr;
1.1 jfb 75:
1.92 joris 76: flags = CR_RECURSE_DIRS;
1.128 tobias 77: strlcpy(diffargs, cvs_cmdop == CVS_OP_DIFF ? "diff" : "rdiff",
78: sizeof(diffargs));
1.1 jfb 79:
1.127 tobias 80: while ((ch = getopt(argc, argv, cvs_cmdop == CVS_OP_DIFF ?
81: cvs_cmd_diff.cmd_opts : cvs_cmd_rdiff.cmd_opts)) != -1) {
1.1 jfb 82: switch (ch) {
1.152 sthen 83: case 'a':
84: strlcat(diffargs, " -a", sizeof(diffargs));
1.154 ray 85: dflags |= D_FORCEASCII;
1.152 sthen 86: break;
87: case 'b':
88: strlcat(diffargs, " -b", sizeof(diffargs));
1.154 ray 89: dflags |= D_FOLDBLANKS;
1.152 sthen 90: break;
1.1 jfb 91: case 'c':
1.2 jfb 92: strlcat(diffargs, " -c", sizeof(diffargs));
1.58 niallo 93: diff_format = D_CONTEXT;
1.1 jfb 94: break;
1.158 nicm 95: case 'C':
96: diff_context = strtonum(optarg, 0, INT_MAX, &errstr);
97: if (errstr != NULL)
98: fatal("context lines %s: %s", errstr, optarg);
99: strlcat(diffargs, " -C ", sizeof(diffargs));
100: strlcat(diffargs, optarg, sizeof(diffargs));
101: diff_format = D_CONTEXT;
102: break;
1.152 sthen 103: case 'd':
104: strlcat(diffargs, " -d", sizeof(diffargs));
1.154 ray 105: dflags |= D_MINIMAL;
1.152 sthen 106: break;
1.137 tobias 107: case 'D':
108: if (date1 == -1 && rev1 == NULL) {
1.159 ray 109: if ((date1 = date_parse(optarg)) == -1)
110: fatal("invalid date: %s", optarg);
1.144 tobias 111: dateflag1 = optarg;
1.137 tobias 112: } else if (date2 == -1 && rev2 == NULL) {
1.159 ray 113: if ((date2 = date_parse(optarg)) == -1)
114: fatal("invalid date: %s", optarg);
1.144 tobias 115: dateflag2 = optarg;
1.137 tobias 116: } else {
117: fatal("no more than 2 revisions/dates can"
118: " be specified");
119: }
120: break;
1.125 tobias 121: case 'f':
122: force_head = 1;
123: break;
124: case 'i':
125: strlcat(diffargs, " -i", sizeof(diffargs));
1.154 ray 126: dflags |= D_IGNORECASE;
1.125 tobias 127: break;
1.126 tobias 128: case 'k':
129: koptstr = optarg;
130: kflag = rcs_kflag_get(koptstr);
1.132 deraadt 131: if (RCS_KWEXP_INVAL(kflag)) {
1.126 tobias 132: cvs_log(LP_ERR,
1.135 tobias 133: "invalid RCS keyword expansion mode");
1.133 tobias 134: fatal("%s", cvs_cmdop == CVS_OP_DIFF ?
135: cvs_cmd_diff.cmd_synopsis :
136: cvs_cmd_rdiff.cmd_synopsis);
1.126 tobias 137: }
138: break;
1.92 joris 139: case 'l':
140: flags &= ~CR_RECURSE_DIRS;
141: break;
1.33 jfb 142: case 'n':
143: strlcat(diffargs, " -n", sizeof(diffargs));
1.58 niallo 144: diff_format = D_RCSDIFF;
1.33 jfb 145: break;
1.94 joris 146: case 'N':
1.136 tobias 147: strlcat(diffargs, " -N", sizeof(diffargs));
1.95 joris 148: Nflag = 1;
1.94 joris 149: break;
1.101 joris 150: case 'p':
151: strlcat(diffargs, " -p", sizeof(diffargs));
1.154 ray 152: dflags |= D_PROTOTYPE;
1.122 tobias 153: break;
154: case 'R':
155: flags |= CR_RECURSE_DIRS;
1.101 joris 156: break;
1.1 jfb 157: case 'r':
1.137 tobias 158: if (date1 == -1 && rev1 == NULL) {
1.97 joris 159: rev1 = optarg;
1.137 tobias 160: } else if (date2 == -1 && rev2 == NULL) {
1.97 joris 161: rev2 = optarg;
1.23 joris 162: } else {
1.91 joris 163: fatal("no more than 2 revisions/dates can"
164: " be specified");
1.1 jfb 165: }
1.32 joris 166: break;
1.154 ray 167: case 't':
168: strlcat(diffargs, " -t", sizeof(diffargs));
169: dflags |= D_EXPANDTABS;
170: break;
1.1 jfb 171: case 'u':
1.2 jfb 172: strlcat(diffargs, " -u", sizeof(diffargs));
1.58 niallo 173: diff_format = D_UNIFIED;
1.1 jfb 174: break;
1.158 nicm 175: case 'U':
176: diff_context = strtonum(optarg, 0, INT_MAX, &errstr);
177: if (errstr != NULL)
178: fatal("context lines %s: %s", errstr, optarg);
179: strlcat(diffargs, " -U ", sizeof(diffargs));
180: strlcat(diffargs, optarg, sizeof(diffargs));
181: diff_format = D_UNIFIED;
182: break;
1.126 tobias 183: case 'V':
184: fatal("the -V option is obsolete "
185: "and should not be used");
1.152 sthen 186: case 'w':
187: strlcat(diffargs, " -w", sizeof(diffargs));
1.154 ray 188: dflags |= D_IGNOREBLANKS;
1.152 sthen 189: break;
1.1 jfb 190: default:
1.133 tobias 191: fatal("%s", cvs_cmdop == CVS_OP_DIFF ?
192: cvs_cmd_diff.cmd_synopsis :
193: cvs_cmd_rdiff.cmd_synopsis);
1.36 jfb 194: }
1.13 jfb 195: }
196:
1.91 joris 197: argc -= optind;
198: argv += optind;
1.1 jfb 199:
1.91 joris 200: cr.enterdir = NULL;
201: cr.leavedir = NULL;
1.108 joris 202:
1.125 tobias 203: if (cvs_cmdop == CVS_OP_RDIFF) {
1.144 tobias 204: if (rev1 == NULL && rev2 == NULL && dateflag1 == NULL &&
205: dateflag2 == NULL)
1.125 tobias 206: fatal("must specify at least one revision/date!");
207:
1.136 tobias 208: if (!argc)
209: fatal("%s", cvs_cmd_rdiff.cmd_synopsis);
210:
1.125 tobias 211: if (!diff_format) {
212: strlcat(diffargs, " -c", sizeof(diffargs));
213: diff_format = D_CONTEXT;
214: }
215:
216: flags |= CR_REPO;
217: }
218:
1.108 joris 219: if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
1.110 joris 220: cvs_client_connect_to_server();
1.108 joris 221: cr.fileproc = cvs_client_sendfile;
222:
223: if (!(flags & CR_RECURSE_DIRS))
224: cvs_client_send_request("Argument -l");
225:
1.126 tobias 226: if (kflag)
227: cvs_client_send_request("Argument -k%s", koptstr);
228:
1.108 joris 229: switch (diff_format) {
230: case D_CONTEXT:
1.158 nicm 231: if (cvs_cmdop == CVS_OP_RDIFF)
232: cvs_client_send_request("Argument -c");
233: else {
234: cvs_client_send_request("Argument -C %d",
235: diff_context);
236: }
1.108 joris 237: break;
238: case D_RCSDIFF:
239: cvs_client_send_request("Argument -n");
240: break;
241: case D_UNIFIED:
1.160 ! nicm 242: if (cvs_cmdop == CVS_OP_RDIFF || diff_context == 3)
1.158 nicm 243: cvs_client_send_request("Argument -u");
244: else {
245: cvs_client_send_request("Argument -U %d",
246: diff_context);
247: }
1.108 joris 248: break;
249: default:
250: break;
251: }
252:
253: if (Nflag == 1)
254: cvs_client_send_request("Argument -N");
255:
1.154 ray 256: if (dflags & D_PROTOTYPE)
1.108 joris 257: cvs_client_send_request("Argument -p");
258:
259: if (rev1 != NULL)
260: cvs_client_send_request("Argument -r%s", rev1);
261: if (rev2 != NULL)
262: cvs_client_send_request("Argument -r%s", rev2);
1.144 tobias 263:
264: if (dateflag1 != NULL)
265: cvs_client_send_request("Argument -D%s", dateflag1);
266: if (dateflag2 != NULL)
267: cvs_client_send_request("Argument -D%s", dateflag2);
1.108 joris 268: } else {
1.125 tobias 269: if (cvs_cmdop == CVS_OP_RDIFF &&
270: chdir(current_cvsroot->cr_dir) == -1)
271: fatal("cvs_diff: %s", strerror(errno));
272:
1.108 joris 273: cr.fileproc = cvs_diff_local;
274: }
275:
1.92 joris 276: cr.flags = flags;
1.7 jfb 277:
1.97 joris 278: diff_rev1 = diff_rev2 = NULL;
279:
1.125 tobias 280: if (cvs_cmdop == CVS_OP_DIFF ||
281: current_cvsroot->cr_method == CVS_METHOD_LOCAL) {
282: if (argc > 0)
283: cvs_file_run(argc, argv, &cr);
284: else
285: cvs_file_run(1, &arg, &cr);
286: }
1.108 joris 287:
288: if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
289: cvs_client_send_files(argv, argc);
290: cvs_client_senddir(".");
1.125 tobias 291:
292: cvs_client_send_request((cvs_cmdop == CVS_OP_RDIFF) ?
293: "rdiff" : "diff");
294:
1.108 joris 295: cvs_client_get_responses();
296: }
1.36 jfb 297:
298: return (0);
299: }
300:
1.91 joris 301: void
302: cvs_diff_local(struct cvs_file *cf)
1.36 jfb 303: {
1.114 joris 304: BUF *b1;
1.131 joris 305: int fd1, fd2;
1.91 joris 306: struct stat st;
1.69 niallo 307: struct timeval tv[2], tv2[2];
1.139 tobias 308: struct tm datetm;
1.137 tobias 309: char rbuf[CVS_REV_BUFSZ], tbuf[CVS_TIME_BUFSZ], *p1, *p2;
1.111 xsa 310:
1.114 joris 311: b1 = NULL;
1.136 tobias 312: fd1 = fd2 = -1;
313: p1 = p2 = NULL;
1.69 niallo 314:
1.91 joris 315: cvs_log(LP_TRACE, "cvs_diff_local(%s)", cf->file_path);
1.1 jfb 316:
1.91 joris 317: if (cf->file_type == CVS_DIR) {
1.46 xsa 318: if (verbosity > 1)
1.147 joris 319: cvs_log(LP_ERR, "Diffing inside %s", cf->file_path);
1.1 jfb 320: return;
321: }
322:
1.121 joris 323: cvs_file_classify(cf, cvs_directory_tag);
1.1 jfb 324:
1.136 tobias 325: if (cvs_cmdop == CVS_OP_DIFF) {
326: if (cf->file_ent == NULL) {
327: cvs_log(LP_ERR, "I know nothing about %s",
328: cf->file_path);
329: return;
330: }
1.126 tobias 331:
1.136 tobias 332: switch (cf->file_ent->ce_status) {
333: case CVS_ENT_ADDED:
334: if (Nflag == 0) {
335: cvs_log(LP_ERR, "%s is a new entry, no "
336: "comparison available", cf->file_path);
1.125 tobias 337: return;
338: }
1.145 joris 339: if (!(cf->file_flags & FILE_ON_DISK)) {
340: cvs_log(LP_ERR, "cannot find %s",
341: cf->file_path);
1.136 tobias 342: return;
1.125 tobias 343: }
1.136 tobias 344: break;
345: case CVS_ENT_REMOVED:
346: if (Nflag == 0) {
347: cvs_log(LP_ERR, "%s was removed, no "
348: "comparison available", cf->file_path);
1.125 tobias 349: return;
350: }
1.136 tobias 351: if (cf->file_rcs == NULL) {
352: cvs_log(LP_ERR, "cannot find RCS file for %s",
353: cf->file_path);
354: return;
1.125 tobias 355: }
1.136 tobias 356: break;
357: default:
1.145 joris 358: if (!(cf->file_flags & FILE_ON_DISK)) {
1.147 joris 359: cvs_printf("? %s\n", cf->file_path);
1.136 tobias 360: return;
361: }
1.140 joris 362:
1.136 tobias 363: if (cf->file_rcs == NULL) {
364: cvs_log(LP_ERR, "cannot find RCS file for %s",
365: cf->file_path);
366: return;
367: }
368: break;
1.123 tobias 369: }
1.136 tobias 370: }
1.1 jfb 371:
1.137 tobias 372: if (cf->file_status == FILE_UPTODATE && rev1 == NULL && rev2 == NULL &&
373: date1 == -1 && date2 == -1)
1.146 joris 374: return;
375:
1.142 joris 376: if (cf->file_rcs != NULL && cf->file_rcs->rf_head == NULL) {
1.141 tobias 377: cvs_log(LP_ERR, "no head revision in RCS file for %s\n",
378: cf->file_path);
379: return;
380: }
1.125 tobias 381:
1.136 tobias 382: if (kflag && cf->file_rcs != NULL)
383: rcs_kwexp_set(cf->file_rcs, kflag);
1.125 tobias 384:
1.136 tobias 385: if (cf->file_rcs == NULL)
386: diff_rev1 = NULL;
1.137 tobias 387: else if (rev1 != NULL || date1 != -1) {
388: cvs_specified_date = date1;
1.136 tobias 389: diff_rev1 = rcs_translate_tag(rev1, cf->file_rcs);
390: if (diff_rev1 == NULL && cvs_cmdop == CVS_OP_DIFF) {
1.143 tobias 391: if (rev1 != NULL) {
1.137 tobias 392: cvs_log(LP_ERR, "tag %s not in file %s", rev1,
393: cf->file_path);
1.143 tobias 394: goto cleanup;
395: } else if (Nflag) {
396: diff_rev1 = NULL;
397: } else {
1.139 tobias 398: gmtime_r(&cvs_specified_date, &datetm);
1.137 tobias 399: strftime(tbuf, sizeof(tbuf),
1.139 tobias 400: "%Y.%m.%d.%H.%M.%S", &datetm);
1.137 tobias 401: cvs_log(LP_ERR, "no revision for date %s in "
402: "file %s", tbuf, cf->file_path);
1.143 tobias 403: goto cleanup;
1.137 tobias 404: }
1.136 tobias 405: } else if (diff_rev1 == NULL && cvs_cmdop == CVS_OP_RDIFF &&
406: force_head) {
407: /* -f is not allowed for unknown symbols */
408: if ((diff_rev1 = rcsnum_parse(rev1)) == NULL)
409: fatal("no such tag %s", rev1);
410: rcsnum_free(diff_rev1);
1.1 jfb 411:
1.136 tobias 412: diff_rev1 = cf->file_rcs->rf_head;
413: }
1.137 tobias 414: cvs_specified_date = -1;
1.136 tobias 415: } else if (cvs_cmdop == CVS_OP_DIFF) {
416: if (cf->file_ent->ce_status == CVS_ENT_ADDED)
417: diff_rev1 = NULL;
1.94 joris 418: else
1.136 tobias 419: diff_rev1 = cf->file_ent->ce_rev;
420: }
1.1 jfb 421:
1.136 tobias 422: if (cf->file_rcs == NULL)
423: diff_rev2 = NULL;
1.137 tobias 424: else if (rev2 != NULL || date2 != -1) {
425: cvs_specified_date = date2;
1.136 tobias 426: diff_rev2 = rcs_translate_tag(rev2, cf->file_rcs);
427: if (diff_rev2 == NULL && cvs_cmdop == CVS_OP_DIFF) {
1.137 tobias 428: if (rev2 != NULL) {
429: cvs_log(LP_ERR, "tag %s not in file %s", rev2,
430: cf->file_path);
1.143 tobias 431: goto cleanup;
432: } else if (Nflag) {
433: diff_rev2 = NULL;
1.137 tobias 434: } else {
1.139 tobias 435: gmtime_r(&cvs_specified_date, &datetm);
1.137 tobias 436: strftime(tbuf, sizeof(tbuf),
1.139 tobias 437: "%Y.%m.%d.%H.%M.%S", &datetm);
1.137 tobias 438: cvs_log(LP_ERR, "no revision for date %s in "
439: "file %s", tbuf, cf->file_path);
1.143 tobias 440: goto cleanup;
1.137 tobias 441: }
1.136 tobias 442: } else if (diff_rev2 == NULL && cvs_cmdop == CVS_OP_RDIFF &&
443: force_head) {
444: /* -f is not allowed for unknown symbols */
445: if ((diff_rev2 = rcsnum_parse(rev2)) == NULL)
446: fatal("no such tag %s", rev2);
447: rcsnum_free(diff_rev2);
1.91 joris 448:
1.136 tobias 449: diff_rev2 = cf->file_rcs->rf_head;
450: }
1.137 tobias 451: cvs_specified_date = -1;
1.136 tobias 452: } else if (cvs_cmdop == CVS_OP_RDIFF)
453: diff_rev2 = cf->file_rcs->rf_head;
454: else if (cf->file_ent->ce_status == CVS_ENT_REMOVED)
455: diff_rev2 = NULL;
1.114 joris 456:
1.136 tobias 457: if (diff_rev1 != NULL && diff_rev2 != NULL &&
458: rcsnum_cmp(diff_rev1, diff_rev2, 0) == 0)
459: goto cleanup;
1.125 tobias 460:
1.136 tobias 461: switch (cvs_cmdop) {
462: case CVS_OP_DIFF:
1.151 joris 463: if (cf->file_status == FILE_UPTODATE) {
464: if (diff_rev2 == NULL &&
465: !rcsnum_cmp(diff_rev1, cf->file_rcsrev, 0))
466: goto cleanup;
467: }
1.136 tobias 468: break;
469: case CVS_OP_RDIFF:
470: if (diff_rev1 == NULL && diff_rev2 == NULL)
471: goto cleanup;
472: break;
473: }
474:
475: cvs_printf("Index: %s\n", cf->file_path);
476: if (cvs_cmdop == CVS_OP_DIFF)
477: cvs_printf("%s\nRCS file: %s\n", RCS_DIFF_DIV,
478: cf->file_rcs != NULL ? cf->file_rpath : cf->file_path);
479:
480: if (diff_rev1 != NULL) {
481: if (cvs_cmdop == CVS_OP_DIFF && diff_rev1 != NULL) {
482: (void)rcsnum_tostr(diff_rev1, rbuf, sizeof(rbuf));
483: cvs_printf("retrieving revision %s\n", rbuf);
1.125 tobias 484: }
1.136 tobias 485:
486: tv[0].tv_sec = rcs_rev_getdate(cf->file_rcs, diff_rev1);
487: tv[0].tv_usec = 0;
488: tv[1] = tv[0];
489:
490: (void)xasprintf(&p1, "%s/diff1.XXXXXXXXXX", cvs_tmpdir);
491: fd1 = rcs_rev_write_stmp(cf->file_rcs, diff_rev1, p1, 0);
492: if (futimes(fd1, tv) == -1)
493: fatal("cvs_diff_local: utimes failed");
1.94 joris 494: }
1.91 joris 495:
1.136 tobias 496: if (diff_rev2 != NULL) {
497: if (cvs_cmdop == CVS_OP_DIFF && rev2 != NULL) {
498: (void)rcsnum_tostr(diff_rev2, rbuf, sizeof(rbuf));
499: cvs_printf("retrieving revision %s\n", rbuf);
500: }
1.91 joris 501:
502: tv2[0].tv_sec = rcs_rev_getdate(cf->file_rcs, diff_rev2);
503: tv2[0].tv_usec = 0;
504: tv2[1] = tv2[0];
1.114 joris 505:
1.136 tobias 506: (void)xasprintf(&p2, "%s/diff2.XXXXXXXXXX", cvs_tmpdir);
1.131 joris 507: fd2 = rcs_rev_write_stmp(cf->file_rcs, diff_rev2, p2, 0);
508: if (futimes(fd2, tv2) == -1)
1.125 tobias 509: fatal("cvs_diff_local: utimes failed");
1.145 joris 510: } else if (cvs_cmdop == CVS_OP_DIFF &&
511: (cf->file_flags & FILE_ON_DISK) &&
1.136 tobias 512: cf->file_ent->ce_status != CVS_ENT_REMOVED) {
1.149 joris 513: (void)xasprintf(&p2, "%s/diff2.XXXXXXXXXX", cvs_tmpdir);
514: if (cvs_server_active == 1 && cf->fd == -1) {
515: tv2[0].tv_sec = rcs_rev_getdate(cf->file_rcs,
516: cf->file_ent->ce_rev);
517: tv2[0].tv_usec = 0;
518: tv2[1] = tv2[0];
1.125 tobias 519:
1.149 joris 520: fd2 = rcs_rev_write_stmp(cf->file_rcs,
521: cf->file_ent->ce_rev, p2, 0);
522: if (futimes(fd2, tv2) == -1)
523: fatal("cvs_diff_local: futimes failed");
524: } else {
525: if (fstat(cf->fd, &st) == -1)
526: fatal("fstat failed %s", strerror(errno));
1.157 ray 527: b1 = buf_load_fd(cf->fd);
1.121 joris 528:
1.149 joris 529: tv2[0].tv_sec = st.st_mtime;
530: tv2[0].tv_usec = 0;
531: tv2[1] = tv2[0];
532:
1.157 ray 533: fd2 = buf_write_stmp(b1, p2, tv2);
534: buf_free(b1);
1.149 joris 535: }
1.17 jfb 536: }
537:
1.136 tobias 538: switch (cvs_cmdop) {
539: case CVS_OP_DIFF:
1.125 tobias 540: cvs_printf("%s", diffargs);
541:
1.136 tobias 542: if (rev1 != NULL && diff_rev1 != NULL) {
543: (void)rcsnum_tostr(diff_rev1, rbuf, sizeof(rbuf));
1.125 tobias 544: cvs_printf(" -r%s", rbuf);
545:
1.136 tobias 546: if (rev2 != NULL && diff_rev2 != NULL) {
1.125 tobias 547: (void)rcsnum_tostr(diff_rev2, rbuf,
548: sizeof(rbuf));
549: cvs_printf(" -r%s", rbuf);
550: }
551: }
1.1 jfb 552:
1.125 tobias 553: if (diff_rev2 == NULL)
1.136 tobias 554: cvs_printf(" %s", cf->file_path);
1.130 tobias 555: cvs_printf("\n");
1.136 tobias 556: break;
557: case CVS_OP_RDIFF:
1.125 tobias 558: cvs_printf("diff ");
559: switch (diff_format) {
560: case D_CONTEXT:
561: cvs_printf("-c ");
562: break;
563: case D_RCSDIFF:
564: cvs_printf("-n ");
565: break;
566: case D_UNIFIED:
567: cvs_printf("-u ");
568: break;
569: default:
570: break;
571: }
572: if (diff_rev1 == NULL) {
573: cvs_printf("%s ", CVS_PATH_DEVNULL);
574: } else {
575: (void)rcsnum_tostr(diff_rev1, rbuf, sizeof(rbuf));
576: cvs_printf("%s:%s ", cf->file_path, rbuf);
577: }
1.1 jfb 578:
1.125 tobias 579: if (diff_rev2 == NULL) {
580: cvs_printf("%s:removed\n", cf->file_path);
581: } else {
582: (void)rcsnum_tostr(diff_rev2 != NULL ? diff_rev2 :
583: cf->file_rcs->rf_head, rbuf, sizeof(rbuf));
584: cvs_printf("%s:%s\n", cf->file_path, rbuf);
1.94 joris 585: }
1.136 tobias 586: break;
1.1 jfb 587: }
588:
1.136 tobias 589: if (fd1 == -1) {
590: if ((fd1 = open(CVS_PATH_DEVNULL, O_RDONLY, 0)) == -1)
591: fatal("cannot open %s", CVS_PATH_DEVNULL);
1.114 joris 592: }
1.136 tobias 593: if (fd2 == -1) {
594: if ((fd2 = open(CVS_PATH_DEVNULL, O_RDONLY, 0)) == -1)
595: fatal("cannot open %s", CVS_PATH_DEVNULL);
596: }
1.111 xsa 597:
1.155 ray 598: if (diffreg(p1 != NULL ? cf->file_path : CVS_PATH_DEVNULL,
1.154 ray 599: p2 != NULL ? cf->file_path : CVS_PATH_DEVNULL, fd1, fd2, NULL,
600: dflags) == D_ERROR)
1.111 xsa 601: fatal("cvs_diff_local: failed to get RCS patch");
1.131 joris 602:
603: close(fd1);
604: close(fd2);
1.58 niallo 605:
1.156 ray 606: worklist_run(&temp_files, worklist_unlink);
1.111 xsa 607:
608: if (p1 != NULL)
609: xfree(p1);
610: if (p2 != NULL)
611: xfree(p2);
1.101 joris 612:
1.136 tobias 613: cleanup:
614: if (diff_rev1 != NULL &&
615: (cf->file_rcs == NULL || diff_rev1 != cf->file_rcs->rf_head) &&
616: (cf->file_ent == NULL || diff_rev1 != cf->file_ent->ce_rev))
617: xfree(diff_rev1);
618: diff_rev1 = NULL;
1.94 joris 619:
1.136 tobias 620: if (diff_rev2 != NULL &&
621: (cf->file_rcs == NULL || diff_rev2 != cf->file_rcs->rf_head))
622: xfree(diff_rev2);
623: diff_rev2 = NULL;
1.1 jfb 624: }