diff: restrict pathspec limitations to diff b/f case only
builtin_diff_b_f() needs a path, not pathspec. Other modes in diff can deal with pathspec just fine. But because of the current GUARD_PATHSPEC() location, other modes also reject :(glob) and :(icase). Move GUARD_PATHSPEC(), and the "path" assignment statement, which is the reason of this GUARD_PATHSPEC(), inside builtin_diff_b_f(). Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
c8556c6213
commit
887c6c18ba
@ -64,15 +64,18 @@ static void stuff_change(struct diff_options *opt,
|
|||||||
|
|
||||||
static int builtin_diff_b_f(struct rev_info *revs,
|
static int builtin_diff_b_f(struct rev_info *revs,
|
||||||
int argc, const char **argv,
|
int argc, const char **argv,
|
||||||
struct blobinfo *blob,
|
struct blobinfo *blob)
|
||||||
const char *path)
|
|
||||||
{
|
{
|
||||||
/* Blob vs file in the working tree*/
|
/* Blob vs file in the working tree*/
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
const char *path;
|
||||||
|
|
||||||
if (argc > 1)
|
if (argc > 1)
|
||||||
usage(builtin_diff_usage);
|
usage(builtin_diff_usage);
|
||||||
|
|
||||||
|
GUARD_PATHSPEC(&revs->prune_data, PATHSPEC_FROMTOP | PATHSPEC_LITERAL);
|
||||||
|
path = revs->prune_data.items[0].match;
|
||||||
|
|
||||||
if (lstat(path, &st))
|
if (lstat(path, &st))
|
||||||
die_errno(_("failed to stat '%s'"), path);
|
die_errno(_("failed to stat '%s'"), path);
|
||||||
if (!(S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)))
|
if (!(S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)))
|
||||||
@ -255,7 +258,6 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
|
|||||||
struct rev_info rev;
|
struct rev_info rev;
|
||||||
struct object_array ent = OBJECT_ARRAY_INIT;
|
struct object_array ent = OBJECT_ARRAY_INIT;
|
||||||
int blobs = 0, paths = 0;
|
int blobs = 0, paths = 0;
|
||||||
const char *path = NULL;
|
|
||||||
struct blobinfo blob[2];
|
struct blobinfo blob[2];
|
||||||
int nongit;
|
int nongit;
|
||||||
int result = 0;
|
int result = 0;
|
||||||
@ -366,13 +368,8 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
|
|||||||
die(_("unhandled object '%s' given."), name);
|
die(_("unhandled object '%s' given."), name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (rev.prune_data.nr) {
|
if (rev.prune_data.nr)
|
||||||
/* builtin_diff_b_f() */
|
|
||||||
GUARD_PATHSPEC(&rev.prune_data, PATHSPEC_FROMTOP | PATHSPEC_LITERAL);
|
|
||||||
if (!path)
|
|
||||||
path = rev.prune_data.items[0].match;
|
|
||||||
paths += rev.prune_data.nr;
|
paths += rev.prune_data.nr;
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Now, do the arguments look reasonable?
|
* Now, do the arguments look reasonable?
|
||||||
@ -385,7 +382,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
|
|||||||
case 1:
|
case 1:
|
||||||
if (paths != 1)
|
if (paths != 1)
|
||||||
usage(builtin_diff_usage);
|
usage(builtin_diff_usage);
|
||||||
result = builtin_diff_b_f(&rev, argc, argv, blob, path);
|
result = builtin_diff_b_f(&rev, argc, argv, blob);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
if (paths)
|
if (paths)
|
||||||
|
@ -100,4 +100,10 @@ test_expect_success 'match_pathspec_depth matches :(icase)bar with empty prefix'
|
|||||||
test_cmp expect actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success '"git diff" can take magic :(icase) pathspec' '
|
||||||
|
echo FOO/BAR >expect &&
|
||||||
|
git diff --name-only HEAD^ HEAD -- ":(icase)foo/bar" >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
Loading…
Reference in New Issue
Block a user