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>
Nguyễn Thái Ngọc Duy committed
Nov 20, 2013 at 08:26 UTC
887c6c18ba84da8d722b1528fe8cdde65d9f9860
2 files changed
+13
-10
builtin/diff.c
+7
-10
@@ -64,15 +64,18 @@ static void stuff_change(struct diff_options *opt,
64
65
static int builtin_diff_b_f(struct rev_info *revs,
66
int argc, const char **argv,
67
- struct blobinfo *blob,
68
- const char *path)
67
+ struct blobinfo *blob)
68
{
69
/* Blob vs file in the working tree*/
70
struct stat st;
71
+ const char *path;
72
73
if (argc > 1)
74
usage(builtin_diff_usage);
75
76
+ GUARD_PATHSPEC(&revs->prune_data, PATHSPEC_FROMTOP | PATHSPEC_LITERAL);
77
+ path = revs->prune_data.items[0].match;
78
+
79
if (lstat(path, &st))
80
die_errno(_("failed to stat '%s'"), path);
81
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)
258
struct rev_info rev;
259
struct object_array ent = OBJECT_ARRAY_INIT;
260
int blobs = 0, paths = 0;
258
- const char *path = NULL;
261
struct blobinfo blob[2];
262
int nongit;
263
int result = 0;
@@ -366,13 +368,8 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
368
die(_("unhandled object '%s' given."), name);
369
}
370
}
369
- if (rev.prune_data.nr) {
370
- /* builtin_diff_b_f() */
371
- GUARD_PATHSPEC(&rev.prune_data, PATHSPEC_FROMTOP | PATHSPEC_LITERAL);
372
- if (!path)
373
- path = rev.prune_data.items[0].match;
371
+ if (rev.prune_data.nr)
372
paths += rev.prune_data.nr;
375
- }
373
374
/*
375
* Now, do the arguments look reasonable?
@@ -385,7 +382,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
382
case 1:
383
if (paths != 1)
384
usage(builtin_diff_usage);
388
- result = builtin_diff_b_f(&rev, argc, argv, blob, path);
385
+ result = builtin_diff_b_f(&rev, argc, argv, blob);
386
break;
387
case 2:
388
if (paths)
t/t6131-pathspec-icase.sh
+6
@@ -100,4 +100,10 @@ test_expect_success 'match_pathspec_depth matches :(icase)bar with empty prefix'
100
test_cmp expect actual
101
'
102
103
+test_expect_success '"git diff" can take magic :(icase) pathspec' '
104
+ echo FOO/BAR >expect &&
105
+ git diff --name-only HEAD^ HEAD -- ":(icase)foo/bar" >actual &&
106
+ test_cmp expect actual
107
+'
108
+
109
test_done