@matheusbsbs / matheus-bagliano / commits / b4189aa848
Fork 0

Clean up git-ls-file directory walking library interface

This moves the code to add the per-directory ignore files for the base directory into the library routine. That not only allows us to turn the function push_exclude_per_directory() static again, it also simplifies the library interface a lot (the caller no longer needs to worry about any of the per-directory exclude files at all). Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Linus Torvalds committed May 16, 2006 at 19:46 UTC b4189aa84873718f80c62846cd53e803b5f72362
3 files changed +28 -24
dir.c
+27 -1
@@ -78,7 +78,7 @@ void add_excludes_from_file(struct dir_struct *dir, const char *fname)
78 die("cannot use %s as an exclude file", fname);
79 }
80
81 -int push_exclude_per_directory(struct dir_struct *dir, const char *base, int baselen)
81 +static int push_exclude_per_directory(struct dir_struct *dir, const char *base, int baselen)
82 {
83 char exclude_file[PATH_MAX];
84 struct exclude_list *el = &dir->exclude_list[EXC_DIRS];
@@ -289,6 +289,32 @@ static int cmp_name(const void *p1, const void *p2)
289
290 int read_directory(struct dir_struct *dir, const char *path, const char *base, int baselen)
291 {
292 + /*
293 + * Make sure to do the per-directory exclude for all the
294 + * directories leading up to our base.
295 + */
296 + if (baselen) {
297 + if (dir->exclude_per_dir) {
298 + char *p, *pp = xmalloc(baselen+1);
299 + memcpy(pp, base, baselen+1);
300 + p = pp;
301 + while (1) {
302 + char save = *p;
303 + *p = 0;
304 + push_exclude_per_directory(dir, pp, p-pp);
305 + *p++ = save;
306 + if (!save)
307 + break;
308 + p = strchr(p, '/');
309 + if (p)
310 + p++;
311 + else
312 + p = pp + baselen;
313 + }
314 + free(pp);
315 + }
316 + }
317 +
318 read_directory_recursive(dir, path, base, baselen);
319 qsort(dir->entries, dir->nr, sizeof(struct dir_entry *), cmp_name);
320 return dir->nr;
dir.h
-2
@@ -44,7 +44,5 @@ extern int excluded(struct dir_struct *, const char *);
44 extern void add_excludes_from_file(struct dir_struct *, const char *fname);
45 extern void add_exclude(const char *string, const char *base,
46 int baselen, struct exclude_list *which);
47 -extern int push_exclude_per_directory(struct dir_struct *,
48 - const char *base, int baselen);
47
48 #endif
ls-files.c
+1 -21
@@ -215,28 +215,8 @@ static void show_files(struct dir_struct *dir)
215 const char *path = ".", *base = "";
216 int baselen = prefix_len;
217
218 - if (baselen) {
218 + if (baselen)
219 path = base = prefix;
220 - if (dir->exclude_per_dir) {
221 - char *p, *pp = xmalloc(baselen+1);
222 - memcpy(pp, prefix, baselen+1);
223 - p = pp;
224 - while (1) {
225 - char save = *p;
226 - *p = 0;
227 - push_exclude_per_directory(dir, pp, p-pp);
228 - *p++ = save;
229 - if (!save)
230 - break;
231 - p = strchr(p, '/');
232 - if (p)
233 - p++;
234 - else
235 - p = pp + baselen;
236 - }
237 - free(pp);
238 - }
239 - }
220 read_directory(dir, path, base, baselen);
221 if (show_others)
222 show_other_files(dir);