Skip to content

Commit 1ad029b

Browse files
author
Junio C Hamano
committed
Do not default to --no-index when given two directories.
git-diff -- a/ b/ always defaulted to --no-index, primarily because the function is_in_index() was implemented quite incorrectly. Noticed by Patrick Maaß and Simon Schubert independently, initial patch was provided by Patrick but I fixed it differently. Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent dc61b10 commit 1ad029b

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

diff-lib.c

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,18 +142,34 @@ static int queue_diff(struct diff_options *o,
142142
}
143143
}
144144

145+
/*
146+
* Does the path name a blob in the working tree, or a directory
147+
* in the working tree?
148+
*/
145149
static int is_in_index(const char *path)
146150
{
147-
int len = strlen(path);
148-
int pos = cache_name_pos(path, len);
149-
char c;
150-
151-
if (pos < 0)
152-
return 0;
153-
if (strncmp(active_cache[pos]->name, path, len))
154-
return 0;
155-
c = active_cache[pos]->name[len];
156-
return c == '\0' || c == '/';
151+
int len, pos;
152+
struct cache_entry *ce;
153+
154+
len = strlen(path);
155+
while (path[len-1] == '/')
156+
len--;
157+
if (!len)
158+
return 1; /* "." */
159+
pos = cache_name_pos(path, len);
160+
if (0 <= pos)
161+
return 1;
162+
pos = -1 - pos;
163+
while (pos < active_nr) {
164+
ce = active_cache[pos++];
165+
if (ce_namelen(ce) <= len ||
166+
strncmp(ce->name, path, len) ||
167+
(ce->name[len] > '/'))
168+
break; /* path cannot be a prefix */
169+
if (ce->name[len] == '/')
170+
return 1;
171+
}
172+
return 0;
157173
}
158174

159175
static int handle_diff_files_args(struct rev_info *revs,

0 commit comments

Comments
 (0)