Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
List scanned repositories in path order
readdir hands entries back in whatever order the filesystem keeps
them, so proj111 could come before proj105 and a section could start
twice. section-sort is off by default to keep the order written in
cgitrc, and a scan has none to keep.
Diffstat (limited to 'source/scan-tree.c')
| -rw-r--r-- | source/scan-tree.c | 17 |
1 file changed, 13 insertions, 4 deletions
diff --git a/source/scan-tree.c b/source/scan-tree.c index ec991e0..91db419 100644 --- a/source/scan-tree.c +++ b/source/scan-tree.c @@ -296,6 +296,8 @@ static void scan_path(const char *base, const char *path) { DIR *dir; struct dirent *ent; + struct string_list entries = STRING_LIST_INIT_DUP; + struct string_list_item *entry; struct strbuf pathbuf = STRBUF_INIT; size_t pathlen = strlen(path); struct stat st; @@ -321,11 +323,17 @@ static void scan_path(const char *base, const char *path) // Take in the '/' that "/.git" left in the buffer, since the loop below // truncates to this length and then appends an entry name straight on. pathlen++; - while ((ent = readdir(dir))) { - if (!should_scan(ent)) - continue; + while ((ent = readdir(dir))) + if (should_scan(ent)) + string_list_append(&entries, ent->d_name); + // A scan has no cgitrc order for the index to keep, and readdir hands + // entries back in whatever order the filesystem stores them, so they + // are taken by name, compared the way the index compares names. + entries.cmp = ctx.cfg.case_sensitive_sort ? strcmp : strcasecmp; + string_list_sort(&entries); + for_each_string_list_item(entry, &entries) { strbuf_setlen(&pathbuf, pathlen); - strbuf_addstr(&pathbuf, ent->d_name); + strbuf_addstr(&pathbuf, entry->string); if (stat(pathbuf.buf, &st)) { fprintf(stderr, "[cgit] Unable to stat %s: %s (%d)\n", pathbuf.buf, strerror(errno), errno); @@ -335,6 +343,7 @@ static void scan_path(const char *base, const char *path) scan_path(base, pathbuf.buf); } end: + string_list_clear(&entries, 0); strbuf_release(&pathbuf); closedir(dir); } |
