tree_entry_interesting(): allow it to say "everything is interesting"
In addition to optimizing pathspecs that would never match, which was done earlier, this optimizes pathspecs that would always match (e.g. "arch/" while the traversal is already in "arch/i386/" hierarchy). This patch makes the worst case slightly more palatable, while improving average case. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Mar 21, 2007 at 17:00 UTC
1d848f643cd8ba86044d729d08d6866425c1539e
1 file changed
+28
-5
tree-diff.c
+28
-5
@@ -70,7 +70,8 @@ static int compare_tree_entry(struct tree_desc *t1, struct tree_desc *t2, const
70
* Is a tree entry interesting given the pathspec we have?
71
*
72
* Return:
73
- * - positive for yes
73
+ * - 2 for "yes, and all subsequent entries will be"
74
+ * - 1 for yes
75
* - zero for no
76
* - negative for "no, and no subsequent entries will be either"
77
*/
@@ -100,8 +101,11 @@ static int tree_entry_interesting(struct tree_desc *desc, const char *base, int
101
if (strncmp(base, match, matchlen))
102
continue;
103
103
- /* The base is a subdirectory of a path which was specified. */
104
- return 1;
104
+ /*
105
+ * The base is a subdirectory of a path which
106
+ * was specified, so all of them are interesting.
107
+ */
108
+ return 2;
109
}
110
111
/* Does the base match? */
@@ -173,8 +177,18 @@ static int tree_entry_interesting(struct tree_desc *desc, const char *base, int
177
/* A whole sub-tree went away or appeared */
178
static void show_tree(struct diff_options *opt, const char *prefix, struct tree_desc *desc, const char *base, int baselen)
179
{
180
+ int all_interesting = 0;
181
while (desc->size) {
177
- int show = tree_entry_interesting(desc, base, baselen, opt);
182
+ int show;
183
+
184
+ if (all_interesting)
185
+ show = 1;
186
+ else {
187
+ show = tree_entry_interesting(desc, base, baselen,
188
+ opt);
189
+ if (show == 2)
190
+ all_interesting = 1;
191
+ }
192
if (show < 0)
193
break;
194
if (show)
@@ -215,8 +229,17 @@ static void show_entry(struct diff_options *opt, const char *prefix, struct tree
229
230
static void skip_uninteresting(struct tree_desc *t, const char *base, int baselen, struct diff_options *opt)
231
{
232
+ int all_interesting = 0;
233
while (t->size) {
219
- int show = tree_entry_interesting(t, base, baselen, opt);
234
+ int show;
235
+
236
+ if (all_interesting)
237
+ show = 1;
238
+ else {
239
+ show = tree_entry_interesting(t, base, baselen, opt);
240
+ if (show == 2)
241
+ all_interesting = 1;
242
+ }
243
if (!show) {
244
update_tree_entry(t);
245
continue;