Implement -j for cvs diff, allowing tag:date based diffs (normally date-based

diffs are against the head branch only).

MFC after:	1 week
This commit is contained in:
Matthew Dillon 2001-09-15 05:50:59 +00:00
parent 38f48395d6
commit 3471d10cbc
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=83495

View file

@ -50,6 +50,7 @@ static void diff_mark_errors PROTO((int err));
static char *diff_rev1, *diff_rev2; static char *diff_rev1, *diff_rev2;
/* Command line dates, from -D option. Malloc'd. */ /* Command line dates, from -D option. Malloc'd. */
static char *diff_date1, *diff_date2; static char *diff_date1, *diff_date2;
static char *diff_join1, *diff_join2;
static char *use_rev1, *use_rev2; static char *use_rev1, *use_rev2;
static int have_rev1_label, have_rev2_label; static int have_rev1_label, have_rev2_label;
@ -223,10 +224,12 @@ diff (argc, argv)
diff_rev2 = NULL; diff_rev2 = NULL;
diff_date1 = NULL; diff_date1 = NULL;
diff_date2 = NULL; diff_date2 = NULL;
diff_join1 = NULL;
diff_join2 = NULL;
optind = 0; optind = 0;
while ((c = getopt_long (argc, argv, while ((c = getopt_long (argc, argv,
"+abcdefhilnpstuwy0123456789BHNRTC:D:F:I:L:U:V:W:k:r:", "+abcdefhilnpstuwy0123456789BHNRTC:D:F:I:L:U:V:W:k:r:j:",
longopts, &option_index)) != -1) longopts, &option_index)) != -1)
{ {
switch (c) switch (c)
@ -286,6 +289,27 @@ diff (argc, argv)
free (options); free (options);
options = RCS_check_kflag (optarg); options = RCS_check_kflag (optarg);
break; break;
case 'j':
{
char *ptr;
char *cpy = strdup(optarg);
if ((ptr = strchr(optarg, ':')) != NULL)
*ptr++ = 0;
if (diff_rev2 != NULL || diff_date2 != NULL)
error (1, 0,
"no more than two revisions/dates can be specified");
if (diff_rev1 != NULL || diff_date1 != NULL) {
diff_join2 = cpy;
diff_rev2 = optarg;
diff_date2 = ptr ? Make_Date(ptr) : NULL;
} else {
diff_join1 = cpy;
diff_rev1 = optarg;
diff_date1 = ptr ? Make_Date(ptr) : NULL;
}
}
break;
case 'r': case 'r':
if (diff_rev2 != NULL || diff_date2 != NULL) if (diff_rev2 != NULL || diff_date2 != NULL)
error (1, 0, error (1, 0,
@ -334,13 +358,18 @@ diff (argc, argv)
send_option_string (opts); send_option_string (opts);
if (options[0] != '\0') if (options[0] != '\0')
send_arg (options); send_arg (options);
if (diff_rev1) if (diff_join1)
option_with_arg ("-j", diff_join1);
else if (diff_rev1)
option_with_arg ("-r", diff_rev1); option_with_arg ("-r", diff_rev1);
if (diff_date1) else if (diff_date1)
client_senddate (diff_date1); client_senddate (diff_date1);
if (diff_rev2)
if (diff_join2)
option_with_arg ("-j", diff_join2);
else if (diff_rev2)
option_with_arg ("-r", diff_rev2); option_with_arg ("-r", diff_rev2);
if (diff_date2) else if (diff_date2)
client_senddate (diff_date2); client_senddate (diff_date2);
/* Send the current files unless diffing two revs from the archive */ /* Send the current files unless diffing two revs from the archive */
@ -353,12 +382,9 @@ diff (argc, argv)
send_to_server ("diff\012", 0); send_to_server ("diff\012", 0);
err = get_responses_and_close (); err = get_responses_and_close ();
free (options); } else
options = NULL;
return (err);
}
#endif #endif
{
if (diff_rev1 != NULL) if (diff_rev1 != NULL)
tag_check_valid (diff_rev1, argc, argv, local, 0, ""); tag_check_valid (diff_rev1, argc, argv, local, 0, "");
if (diff_rev2 != NULL) if (diff_rev2 != NULL)
@ -375,6 +401,7 @@ diff (argc, argv)
diff_dirleaveproc, NULL, argc, argv, local, diff_dirleaveproc, NULL, argc, argv, local,
which, 0, 1, (char *) NULL, 1); which, 0, 1, (char *) NULL, 1);
}
/* clean up */ /* clean up */
free (options); free (options);
options = NULL; options = NULL;
@ -383,6 +410,10 @@ diff (argc, argv)
free (diff_date1); free (diff_date1);
if (diff_date2 != NULL) if (diff_date2 != NULL)
free (diff_date2); free (diff_date2);
if (diff_join1 != NULL)
free (diff_join1);
if (diff_join2 != NULL)
free (diff_join2);
return (err); return (err);
} }
@ -432,7 +463,7 @@ diff_fileproc (callerdat, finfo)
int exists; int exists;
exists = 0; exists = 0;
/* special handling for TAG_HEAD */ /* special handling for TAG_HEAD XXX */
if (diff_rev1 && strcmp (diff_rev1, TAG_HEAD) == 0) if (diff_rev1 && strcmp (diff_rev1, TAG_HEAD) == 0)
{ {
char *head = char *head =
@ -840,7 +871,7 @@ diff_file_nodiff (finfo, vers, empty_file)
if (diff_rev1 || diff_date1) if (diff_rev1 || diff_date1)
{ {
/* special handling for TAG_HEAD */ /* special handling for TAG_HEAD XXX */
if (diff_rev1 && strcmp (diff_rev1, TAG_HEAD) == 0) if (diff_rev1 && strcmp (diff_rev1, TAG_HEAD) == 0)
use_rev1 = ((vers->vn_rcs == NULL || vers->srcfile == NULL) use_rev1 = ((vers->vn_rcs == NULL || vers->srcfile == NULL)
? NULL ? NULL
@ -855,7 +886,7 @@ diff_file_nodiff (finfo, vers, empty_file)
} }
if (diff_rev2 || diff_date2) if (diff_rev2 || diff_date2)
{ {
/* special handling for TAG_HEAD */ /* special handling for TAG_HEAD XXX */
if (diff_rev2 && strcmp (diff_rev2, TAG_HEAD) == 0) if (diff_rev2 && strcmp (diff_rev2, TAG_HEAD) == 0)
use_rev2 = ((vers->vn_rcs == NULL || vers->srcfile == NULL) use_rev2 = ((vers->vn_rcs == NULL || vers->srcfile == NULL)
? NULL ? NULL