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

Simplify read_directory[_recursive]() arguments

Stop the insanity with separate 'path' and 'base' arguments that must match. We don't need that crazy interface any more, since we cleaned up handling of 'path' in commit da4b3e8c28b1dc2b856d2555ac7bb47ab712598c. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Linus Torvalds committed Jul 8, 2009 at 19:24 UTC dba2e2037f40685bffc87d3e7114a02c5bda1eff
3 files changed +30 -31
dir.c
+28 -29
@@ -14,8 +14,7 @@ struct path_simplify {
14 const char *path;
15 };
16
17 -static int read_directory_recursive(struct dir_struct *dir,
18 - const char *path, const char *base, int baselen,
17 +static int read_directory_recursive(struct dir_struct *dir, const char *path, int len,
18 int check_only, const struct path_simplify *simplify);
19 static int get_dtype(struct dirent *de, const char *path);
20
@@ -54,23 +53,22 @@ static int common_prefix(const char **pathspec)
53
54 int fill_directory(struct dir_struct *dir, const char **pathspec)
55 {
57 - const char *path, *base;
58 - int baselen;
56 + const char *path;
57 + int len;
58
59 /*
60 * Calculate common prefix for the pathspec, and
61 * use that to optimize the directory walk
62 */
64 - baselen = common_prefix(pathspec);
63 + len = common_prefix(pathspec);
64 path = "";
66 - base = "";
65
68 - if (baselen)
69 - path = base = xmemdupz(*pathspec, baselen);
66 + if (len)
67 + path = xmemdupz(*pathspec, len);
68
69 /* Read the directory and prune it */
72 - read_directory(dir, path, base, baselen, pathspec);
73 - return baselen;
70 + read_directory(dir, path, len, pathspec);
71 + return len;
72 }
73
74 /*
@@ -526,7 +524,7 @@ static enum directory_treatment treat_directory(struct dir_struct *dir,
524 /* This is the "show_other_directories" case */
525 if (!(dir->flags & DIR_HIDE_EMPTY_DIRECTORIES))
526 return show_directory;
529 - if (!read_directory_recursive(dir, dirname, dirname, len, 1, simplify))
527 + if (!read_directory_recursive(dir, dirname, len, 1, simplify))
528 return ignore_directory;
529 return show_directory;
530 }
@@ -595,15 +593,15 @@ static int get_dtype(struct dirent *de, const char *path)
593 * Also, we ignore the name ".git" (even if it is not a directory).
594 * That likely will not change.
595 */
598 -static int read_directory_recursive(struct dir_struct *dir, const char *path, const char *base, int baselen, int check_only, const struct path_simplify *simplify)
596 +static int read_directory_recursive(struct dir_struct *dir, const char *base, int baselen, int check_only, const struct path_simplify *simplify)
597 {
600 - DIR *fdir = opendir(*path ? path : ".");
598 + DIR *fdir = opendir(*base ? base : ".");
599 int contents = 0;
600
601 if (fdir) {
602 struct dirent *de;
605 - char fullname[PATH_MAX + 1];
606 - memcpy(fullname, base, baselen);
603 + char path[PATH_MAX + 1];
604 + memcpy(path, base, baselen);
605
606 while ((de = readdir(fdir)) != NULL) {
607 int len, dtype;
@@ -614,17 +612,18 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co
612 continue;
613 len = strlen(de->d_name);
614 /* Ignore overly long pathnames! */
617 - if (len + baselen + 8 > sizeof(fullname))
615 + if (len + baselen + 8 > sizeof(path))
616 continue;
619 - memcpy(fullname + baselen, de->d_name, len+1);
620 - if (simplify_away(fullname, baselen + len, simplify))
617 + memcpy(path + baselen, de->d_name, len+1);
618 + len = baselen + len;
619 + if (simplify_away(path, len, simplify))
620 continue;
621
622 dtype = DTYPE(de);
624 - exclude = excluded(dir, fullname, &dtype);
623 + exclude = excluded(dir, path, &dtype);
624 if (exclude && (dir->flags & DIR_COLLECT_IGNORED)
626 - && in_pathspec(fullname, baselen + len, simplify))
627 - dir_add_ignored(dir, fullname, baselen + len);
625 + && in_pathspec(path, len, simplify))
626 + dir_add_ignored(dir, path,len);
627
628 /*
629 * Excluded? If we don't explicitly want to show
@@ -634,7 +633,7 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co
633 continue;
634
635 if (dtype == DT_UNKNOWN)
637 - dtype = get_dtype(de, fullname);
636 + dtype = get_dtype(de, path);
637
638 /*
639 * Do we want to see just the ignored files?
@@ -651,9 +650,9 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co
650 default:
651 continue;
652 case DT_DIR:
654 - memcpy(fullname + baselen + len, "/", 2);
653 + memcpy(path + len, "/", 2);
654 len++;
656 - switch (treat_directory(dir, fullname, baselen + len, simplify)) {
655 + switch (treat_directory(dir, path, len, simplify)) {
656 case show_directory:
657 if (exclude != !!(dir->flags
658 & DIR_SHOW_IGNORED))
@@ -661,7 +660,7 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co
660 break;
661 case recurse_into_directory:
662 contents += read_directory_recursive(dir,
664 - fullname, fullname, baselen + len, 0, simplify);
663 + path, len, 0, simplify);
664 continue;
665 case ignore_directory:
666 continue;
@@ -675,7 +674,7 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co
674 if (check_only)
675 goto exit_early;
676 else
678 - dir_add_name(dir, fullname, baselen + len);
677 + dir_add_name(dir, path, len);
678 }
679 exit_early:
680 closedir(fdir);
@@ -738,15 +737,15 @@ static void free_simplify(struct path_simplify *simplify)
737 free(simplify);
738 }
739
741 -int read_directory(struct dir_struct *dir, const char *path, const char *base, int baselen, const char **pathspec)
740 +int read_directory(struct dir_struct *dir, const char *path, int len, const char **pathspec)
741 {
742 struct path_simplify *simplify;
743
745 - if (has_symlink_leading_path(path, strlen(path)))
744 + if (has_symlink_leading_path(path, len))
745 return dir->nr;
746
747 simplify = create_simplify(pathspec);
749 - read_directory_recursive(dir, path, base, baselen, 0, simplify);
748 + read_directory_recursive(dir, path, len, 0, simplify);
749 free_simplify(simplify);
750 qsort(dir->entries, dir->nr, sizeof(struct dir_entry *), cmp_name);
751 qsort(dir->ignored, dir->ignored_nr, sizeof(struct dir_entry *), cmp_name);
dir.h
+1 -1
@@ -67,7 +67,7 @@ struct dir_struct {
67 extern int match_pathspec(const char **pathspec, const char *name, int namelen, int prefix, char *seen);
68
69 extern int fill_directory(struct dir_struct *dir, const char **pathspec);
70 -extern int read_directory(struct dir_struct *, const char *path, const char *base, int baselen, const char **pathspec);
70 +extern int read_directory(struct dir_struct *, const char *path, int len, const char **pathspec);
71
72 extern int excluded(struct dir_struct *, const char *, int *);
73 extern void add_excludes_from_file(struct dir_struct *, const char *fname);
unpack-trees.c
+1 -1
@@ -551,7 +551,7 @@ static int verify_clean_subdirectory(struct cache_entry *ce, const char *action,
551 memset(&d, 0, sizeof(d));
552 if (o->dir)
553 d.exclude_per_dir = o->dir->exclude_per_dir;
554 - i = read_directory(&d, ce->name, pathbuf, namelen+1, NULL);
554 + i = read_directory(&d, pathbuf, namelen+1, NULL);
555 if (i)
556 return o->gently ? -1 :
557 error(ERRORMSG(o, not_uptodate_dir), ce->name);