Teach git-diff-files the new option --no-index
With this flag and given two paths, git-diff-files behaves as a GNU diff
lookalike (plus the git goodies like --check, colour, etc.). This flag
is also available in git-diff. It also works outside of a git repository.
In addition, if git-diff{,-files} is called without revision or stage
parameter, and with exactly two paths at least one of which is not tracked,
the default is --no-index.
So, you can now say
git diff /etc/inittab /etc/fstab
and it actually works!
This also unifies the duplicated argument parsing between cmd_diff_files()
and builtin_diff_files().
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
committed by
Junio C Hamano
parent
f5a9264769
commit
d516c2d119
@ -25,40 +25,6 @@ struct blobinfo {
|
||||
static const char builtin_diff_usage[] =
|
||||
"git-diff <options> <rev>{0,2} -- <path>*";
|
||||
|
||||
static int builtin_diff_files(struct rev_info *revs,
|
||||
int argc, const char **argv)
|
||||
{
|
||||
int silent = 0;
|
||||
while (1 < argc) {
|
||||
const char *arg = argv[1];
|
||||
if (!strcmp(arg, "--base"))
|
||||
revs->max_count = 1;
|
||||
else if (!strcmp(arg, "--ours"))
|
||||
revs->max_count = 2;
|
||||
else if (!strcmp(arg, "--theirs"))
|
||||
revs->max_count = 3;
|
||||
else if (!strcmp(arg, "-q"))
|
||||
silent = 1;
|
||||
else
|
||||
usage(builtin_diff_usage);
|
||||
argv++; argc--;
|
||||
}
|
||||
/*
|
||||
* Make sure there are NO revision (i.e. pending object) parameter,
|
||||
* specified rev.max_count is reasonable (0 <= n <= 3), and
|
||||
* there is no other revision filtering parameter.
|
||||
*/
|
||||
if (revs->pending.nr ||
|
||||
revs->min_age != -1 ||
|
||||
revs->max_age != -1 ||
|
||||
3 < revs->max_count)
|
||||
usage(builtin_diff_usage);
|
||||
if (revs->max_count < 0 &&
|
||||
(revs->diffopt.output_format & DIFF_FORMAT_PATCH))
|
||||
revs->combine_merges = revs->dense_combined_merges = 1;
|
||||
return run_diff_files(revs, silent);
|
||||
}
|
||||
|
||||
static void stuff_change(struct diff_options *opt,
|
||||
unsigned old_mode, unsigned new_mode,
|
||||
const unsigned char *old_sha1,
|
||||
@ -218,6 +184,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
|
||||
int ents = 0, blobs = 0, paths = 0;
|
||||
const char *path = NULL;
|
||||
struct blobinfo blob[2];
|
||||
int nongit = 0;
|
||||
|
||||
/*
|
||||
* We could get N tree-ish in the rev.pending_objects list.
|
||||
@ -239,6 +206,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
|
||||
* Other cases are errors.
|
||||
*/
|
||||
|
||||
prefix = setup_git_directory_gently(&nongit);
|
||||
git_config(git_diff_ui_config);
|
||||
init_revisions(&rev, prefix);
|
||||
|
||||
@ -314,7 +282,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
|
||||
if (!ents) {
|
||||
switch (blobs) {
|
||||
case 0:
|
||||
return builtin_diff_files(&rev, argc, argv);
|
||||
return run_diff_files_cmd(&rev, argc, argv);
|
||||
break;
|
||||
case 1:
|
||||
if (paths != 1)
|
||||
|
||||
Reference in New Issue
Block a user