@matheusbsbs / matheus-bagliano / commits / 475005a117
Fork 0

tree_entry_interesting(): remove dependency on struct diff_options

This function can be potentially used in more places than just tree-diff.c. "struct diff_options" does not make much sense outside diff_tree_sha1(). While removing the use of diff_options, it also removes tree_entry_extract() call, which means S_ISDIR() uses the entry->mode directly, without being filtered by canon_mode() (called internally inside tree_entry_extract). The only use of the mode information in this function is to check the type of the entry by giving it to S_ISDIR() macro, and the result does not change with or without canon_mode(), so it is ok to bypass tree_entry_extract(). 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 Dec 15, 2010 at 22:02 UTC 475005a11768a3906c42fac55e8b3371794bdef3
1 file changed +10 -16
tree-diff.c
+10 -16
@@ -93,24 +93,19 @@ static int compare_tree_entry(struct tree_desc *t1, struct tree_desc *t2, const
93 * - zero for no
94 * - negative for "no, and no subsequent entries will be either"
95 */
96 -static int tree_entry_interesting(struct tree_desc *desc, const char *base, int baselen, struct diff_options *opt)
96 +static int tree_entry_interesting(const struct name_entry *entry, const char *base, int baselen, const struct pathspec *ps)
97 {
98 - const char *path;
99 - const unsigned char *sha1;
100 - unsigned mode;
98 int i;
99 int pathlen;
100 int never_interesting = -1;
101
105 - if (!opt->pathspec.nr)
102 + if (!ps || !ps->nr)
103 return 2;
104
108 - sha1 = tree_entry_extract(desc, &path, &mode);
109 -
110 - pathlen = tree_entry_len(path, sha1);
105 + pathlen = tree_entry_len(entry->path, entry->sha1);
106
112 - for (i = 0; i < opt->pathspec.nr; i++) {
113 - const struct pathspec_item *item = opt->pathspec.items+i;
107 + for (i = 0; i < ps->nr; i++) {
108 + const struct pathspec_item *item = ps->items+i;
109 const char *match = item->match;
110 int matchlen = item->len;
111 int m = -1; /* signals that we haven't called strncmp() */
@@ -150,7 +145,7 @@ static int tree_entry_interesting(struct tree_desc *desc, const char *base, int
145 * Does match sort strictly earlier than path
146 * with their common parts?
147 */
153 - m = strncmp(match, path,
148 + m = strncmp(match, entry->path,
149 (matchlen < pathlen) ? matchlen : pathlen);
150 if (m < 0)
151 continue;
@@ -177,7 +172,7 @@ static int tree_entry_interesting(struct tree_desc *desc, const char *base, int
172 if (matchlen > pathlen) {
173 if (match[pathlen] != '/')
174 continue;
180 - if (!S_ISDIR(mode))
175 + if (!S_ISDIR(entry->mode))
176 continue;
177 }
178
@@ -186,7 +181,7 @@ static int tree_entry_interesting(struct tree_desc *desc, const char *base, int
181 * we cheated and did not do strncmp(), so we do
182 * that here.
183 */
189 - m = strncmp(match, path, pathlen);
184 + m = strncmp(match, entry->path, pathlen);
185
186 /*
187 * If common part matched earlier then it is a hit,
@@ -209,8 +204,7 @@ static void show_tree(struct diff_options *opt, const char *prefix, struct tree_
204 if (all_interesting)
205 show = 1;
206 else {
212 - show = tree_entry_interesting(desc, base, baselen,
213 - opt);
207 + show = tree_entry_interesting(&desc->entry, base, baselen, &opt->pathspec);
208 if (show == 2)
209 all_interesting = 1;
210 }
@@ -263,7 +257,7 @@ static void show_entry(struct diff_options *opt, const char *prefix, struct tree
257 static void skip_uninteresting(struct tree_desc *t, const char *base, int baselen, struct diff_options *opt, int *all_interesting)
258 {
259 while (t->size) {
266 - int show = tree_entry_interesting(t, base, baselen, opt);
260 + int show = tree_entry_interesting(&t->entry, base, baselen, &opt->pathspec);
261 if (show == 2)
262 *all_interesting = 1;
263 if (!show) {