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>
Junio C Hamano committed
Apr 13, 2007 at 03:23 UTC
1ad029b6a1e2fb0254667a2bea8d1ee180cc6ac7
1 file changed
+26
-10
diff-lib.c
+26
-10
@@ -142,18 +142,34 @@ static int queue_diff(struct diff_options *o,
142
}
143
}
144
145
+/*
146
+ * Does the path name a blob in the working tree, or a directory
147
+ * in the working tree?
148
+ */
149
static int is_in_index(const char *path)
150
{
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;
173
}
174
175
static int handle_diff_files_args(struct rev_info *revs,