diff options
author | Tobias Stoeckmann <tobias@cvs.openbsd.org> | 2008-05-30 11:06:18 +0000 |
---|---|---|
committer | Tobias Stoeckmann <tobias@cvs.openbsd.org> | 2008-05-30 11:06:18 +0000 |
commit | 9d55ff437b88c5b67e70666306efbfbacfea4791 (patch) | |
tree | fed950100e3c6c3a9fa4ec2851c7a75452c3f2ee | |
parent | 227b3407b3924022bb07e0c034c2e56cfbb47e4f (diff) |
diff -D support, also a change in diff_internals to properly print
file name or /dev/null, if file has been removed or added.
-rw-r--r-- | usr.bin/cvs/diff.c | 57 | ||||
-rw-r--r-- | usr.bin/cvs/diff_internals.c | 15 |
2 files changed, 54 insertions, 18 deletions
diff --git a/usr.bin/cvs/diff.c b/usr.bin/cvs/diff.c index f305f7efd2f..92e49ea61e2 100644 --- a/usr.bin/cvs/diff.c +++ b/usr.bin/cvs/diff.c @@ -1,4 +1,4 @@ -/* $OpenBSD: diff.c,v 1.136 2008/05/30 10:12:12 tobias Exp $ */ +/* $OpenBSD: diff.c,v 1.137 2008/05/30 11:06:17 tobias Exp $ */ /* * Copyright (c) 2008 Tobias Stoeckmann <tobias@openbsd.org> * Copyright (c) 2006 Joris Vink <joris@openbsd.org> @@ -36,6 +36,8 @@ static int force_head = 0; static char *koptstr; static char *rev1 = NULL; static char *rev2 = NULL; +static time_t date1 = -1; +static time_t date2 = -1; struct cvs_cmd cvs_cmd_diff = { CVS_OP_DIFF, CVS_USE_WDIR, "diff", @@ -77,6 +79,16 @@ cvs_diff(int argc, char **argv) strlcat(diffargs, " -c", sizeof(diffargs)); diff_format = D_CONTEXT; break; + case 'D': + if (date1 == -1 && rev1 == NULL) { + date1 = cvs_date_parse(optarg); + } else if (date2 == -1 && rev2 == NULL) { + date2 = cvs_date_parse(optarg); + } else { + fatal("no more than 2 revisions/dates can" + " be specified"); + } + break; case 'f': force_head = 1; break; @@ -114,9 +126,9 @@ cvs_diff(int argc, char **argv) flags |= CR_RECURSE_DIRS; break; case 'r': - if (rev1 == NULL) { + if (date1 == -1 && rev1 == NULL) { rev1 = optarg; - } else if (rev2 == NULL) { + } else if (date2 == -1 && rev2 == NULL) { rev2 = optarg; } else { fatal("no more than 2 revisions/dates can" @@ -232,7 +244,8 @@ cvs_diff_local(struct cvs_file *cf) int fd1, fd2; struct stat st; struct timeval tv[2], tv2[2]; - char rbuf[CVS_REV_BUFSZ], *p1, *p2; + struct tm *datetm; + char rbuf[CVS_REV_BUFSZ], tbuf[CVS_TIME_BUFSZ], *p1, *p2; b1 = NULL; fd1 = fd2 = -1; @@ -286,7 +299,6 @@ cvs_diff_local(struct cvs_file *cf) cf->file_path); return; } - break; if (cf->file_rcs == NULL) { cvs_log(LP_ERR, "cannot find RCS file for %s", cf->file_path); @@ -296,7 +308,8 @@ cvs_diff_local(struct cvs_file *cf) } } - if (cf->file_status == FILE_UPTODATE && rev1 == NULL && rev2 == NULL) + if (cf->file_status == FILE_UPTODATE && rev1 == NULL && rev2 == NULL && + date1 == -1 && date2 == -1) return; if (kflag && cf->file_rcs != NULL) @@ -304,11 +317,20 @@ cvs_diff_local(struct cvs_file *cf) if (cf->file_rcs == NULL) diff_rev1 = NULL; - else if (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) { - cvs_log(LP_ERR, "tag %s not in file %s", rev1, - cf->file_path); + if (rev1 != NULL) + cvs_log(LP_ERR, "tag %s not in file %s", rev1, + cf->file_path); + else { + datetm = gmtime(&cvs_specified_date); + 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) { @@ -319,6 +341,7 @@ cvs_diff_local(struct cvs_file *cf) 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; @@ -328,11 +351,20 @@ cvs_diff_local(struct cvs_file *cf) if (cf->file_rcs == NULL) diff_rev2 = NULL; - else if (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) { - cvs_log(LP_ERR, "tag %s not in file %s", rev2, - cf->file_path); + if (rev2 != NULL) { + cvs_log(LP_ERR, "tag %s not in file %s", rev2, + cf->file_path); + } else { + datetm = gmtime(&cvs_specified_date); + 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) { @@ -343,6 +375,7 @@ cvs_diff_local(struct cvs_file *cf) 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 --git a/usr.bin/cvs/diff_internals.c b/usr.bin/cvs/diff_internals.c index ff0a264d3df..50246055dcb 100644 --- a/usr.bin/cvs/diff_internals.c +++ b/usr.bin/cvs/diff_internals.c @@ -1,4 +1,4 @@ -/* $OpenBSD: diff_internals.c,v 1.21 2008/04/24 19:13:56 tobias Exp $ */ +/* $OpenBSD: diff_internals.c,v 1.22 2008/05/30 11:06:17 tobias Exp $ */ /* * Copyright (C) Caldera International Inc. 2001-2002. * All rights reserved. @@ -201,7 +201,8 @@ static int context = 3; int diff_format = D_NORMAL; int diff_iflag = 0; int diff_pflag = 0; -char *diff_file = NULL; +const char *diff_file1 = NULL; +const char *diff_file2 = NULL; RCSNUM *diff_rev1 = NULL; RCSNUM *diff_rev2 = NULL; char diffargs[128]; @@ -300,6 +301,8 @@ cvs_diffreg(const char *file1, const char *file2, int _fd1, int _fd2, BUF *out) FILE *f1, *f2; int i, rval, fd1, fd2; + diff_file1 = file1; + diff_file2 = file2; f1 = f2 = NULL; rval = D_SAME; anychange = 0; @@ -887,7 +890,7 @@ diff_head(void) (void)strftime(buf, sizeof(buf), "%b %G %H:%M:%S -0000", t); diff_output("%s %s %d %s", diff_format == D_CONTEXT ? - "***" : "---", diff_file, t->tm_mday, buf); + "***" : "---", diff_file1, t->tm_mday, buf); if (diff_rev1 != NULL) { rcsnum_tostr(diff_rev1, buf, sizeof(buf)); @@ -900,7 +903,7 @@ diff_head(void) (void)strftime(buf, sizeof(buf), "%b %G %H:%M:%S -0000", t); diff_output("%s %s %d %s", diff_format == D_CONTEXT ? - "---" : "+++", diff_file, t->tm_mday, buf); + "---" : "+++", diff_file2, t->tm_mday, buf); if (diff_rev2 != NULL) { rcsnum_tostr(diff_rev2, buf, sizeof(buf)); @@ -931,7 +934,7 @@ rdiff_head(void) t = gmtime(&stb1.st_atime); } else { rcsnum_tostr(diff_rev1, buf, sizeof(buf)); - diff_output("%s:%s", diff_file, buf); + diff_output("%s:%s", diff_file1, buf); } (void)strftime(buf, sizeof(buf), "%a %b %e %H:%M:%S %G", t); @@ -947,7 +950,7 @@ rdiff_head(void) (void)strftime(buf, sizeof(buf), "%a %b %e %H:%M:%S %G", t); diff_output("%s %s %s\n", diff_format == D_CONTEXT ? "---" : "+++", - diff_file, buf); + diff_file2, buf); } /* |