fix(gitstat): attribute an on-demand repository to its root
?action=repo&path= for a repository the discovery walk never visited (one inside node_modules, or past the entry budget) answered with an empty root field, so the drawer showed the repo with no origin. Fill it from the same canonical prefix test that authorises the request.
AuthorPico <picobot@scorpioplayer.com>
Date2026-11-12 10:04:43
Commitac1845c5
Parents99f9295a
Changed files
src/plugin_gitstat.c+14−1■■■■■
tests/run.sh+13−0■■■■■
2 files+27−1
Diff
src/plugin_gitstat.c+14−1■■■■■
index 1b112cf..f8f9399 100644
--- a/src/plugin_gitstat.c
+++ b/src/plugin_gitstat.c
@@ -1228,7 +1228,20 @@ static int print_repo_detail(const char *path)
12281228 memset(r, 0, sizeof(*r));
12291229 str_copy(r->path, sizeof(r->path), canon);
12301230 str_copy(r->name, sizeof(r->name), base_name(canon));
1231- str_copy(r->root, sizeof(r->root), "");
1231+ {
1232+ /* Keep the row shaped like a discovered one: attribute it to the
1233+ * root it actually sits under rather than reporting an empty root. */
1234+ int k;
1235+ for (k = 0; k < g_root_count; k++) {
1236+ const char *rp = g_roots[k].canon[0] ? g_roots[k].canon : g_roots[k].root;
1237+ size_t n = strlen(rp);
1238+ if (n && strncmp(canon, rp, n) == 0 &&
1239+ (canon[n] == '\0' || canon[n] == '/' || canon[n] == '\\')) {
1240+ str_copy(r->root, sizeof(r->root), g_roots[k].root);
1241+ break;
1242+ }
1243+ }
1244+ }
12321245 query_repo(r, 1);
12331246 g_repo_count++;
12341247 }
tests/run.sh+13−0■■■■■
index 8f40cc3..9a5385c 100755
--- a/tests/run.sh
+++ b/tests/run.sh
@@ -370,6 +370,19 @@ json_ok "repo detail has recent commits" "$DETB" "len(d['commits'])>=1"
370370 json_ok "each commit has hash/ct/author/subject" "$DETB" \
371371 "all(set(c)>=set(['hash','ct','author','subject']) for c in d['commits'])"
372372 json_ok "changed_count is reported" "$DETB" "d['changed_count']==3"
373+json_ok "a discovered repo keeps its root attribution" "$DETB" "d['repo']['root']!=''"
374+
375+# a repo the walk deliberately skipped (it lives inside a node_modules tree) is
376+# still served when asked for by path, and is attributed to its root
377+mkdir -p "$ROOTS/node_modules"
378+cp -a "$ROOTS/cleanrepo" "$ROOTS/node_modules/skipped"
379+UNSEEN=$(body "$(env QUERY_STRING="action=repo&path=$ROOTS/node_modules/skipped" \
380+ GITSTAT_ONLY_ROOTS=1 GITSTAT_ROOTS="$ROOTS" $BIN)")
381+json_ok "the walk skips node_modules" "$REPOSB" \
382+ "not any('node_modules' in r['path'] for r in d['repos'])"
383+json_ok "an undiscovered repo is read on demand" "$UNSEEN" "d['ok'] is True"
384+json_ok "a skipped repo is attributed to its root" "$UNSEEN" \
385+ "d['repo']['root']=='$ROOTS'"
373386
374387 AHEADD=$(env QUERY_STRING="action=repo&path=$ROOTS/aheadrepo" \
375388 GITSTAT_ONLY_ROOTS=1 GITSTAT_ROOTS="$ROOTS" $BIN)
376389
src/plugin_gitstat.c+14−1■■■■■
index 1b112cf..f8f9399 100644index 1b112cf..f8f9399 100644
--- a/src/plugin_gitstat.c--- a/src/plugin_gitstat.c
+++ b/src/plugin_gitstat.c+++ b/src/plugin_gitstat.c
@@ -1228,7 +1228,20 @@ static int print_repo_detail(const char *path)@@ -1228,7 +1228,20 @@ static int print_repo_detail(const char *path)
1228 memset(r, 0, sizeof(*r));1228 memset(r, 0, sizeof(*r));
1229 str_copy(r->path, sizeof(r->path), canon);1229 str_copy(r->path, sizeof(r->path), canon);
1230 str_copy(r->name, sizeof(r->name), base_name(canon));1230 str_copy(r->name, sizeof(r->name), base_name(canon));
1231- str_copy(r->root, sizeof(r->root), "");1231+ {
1232+ /* Keep the row shaped like a discovered one: attribute it to the
1233+ * root it actually sits under rather than reporting an empty root. */
1234+ int k;
1235+ for (k = 0; k < g_root_count; k++) {
1236+ const char *rp = g_roots[k].canon[0] ? g_roots[k].canon : g_roots[k].root;
1237+ size_t n = strlen(rp);
1238+ if (n && strncmp(canon, rp, n) == 0 &&
1239+ (canon[n] == '\0' || canon[n] == '/' || canon[n] == '\\')) {
1240+ str_copy(r->root, sizeof(r->root), g_roots[k].root);
1241+ break;
1242+ }
1243+ }
1244+ }
1232 query_repo(r, 1);1245 query_repo(r, 1);
1233 g_repo_count++;1246 g_repo_count++;
1234 }1247 }
tests/run.sh+13−0■■■■■
index 8f40cc3..9a5385c 100755index 8f40cc3..9a5385c 100755
--- a/tests/run.sh--- a/tests/run.sh
+++ b/tests/run.sh+++ b/tests/run.sh
@@ -370,6 +370,19 @@ json_ok "repo detail has recent commits" "$DETB" "len(d['commits'])>=1"@@ -370,6 +370,19 @@ json_ok "repo detail has recent commits" "$DETB" "len(d['commits'])>=1"
370 json_ok "each commit has hash/ct/author/subject" "$DETB" \370 json_ok "each commit has hash/ct/author/subject" "$DETB" \
371 "all(set(c)>=set(['hash','ct','author','subject']) for c in d['commits'])"371 "all(set(c)>=set(['hash','ct','author','subject']) for c in d['commits'])"
372 json_ok "changed_count is reported" "$DETB" "d['changed_count']==3"372 json_ok "changed_count is reported" "$DETB" "d['changed_count']==3"
373+json_ok "a discovered repo keeps its root attribution" "$DETB" "d['repo']['root']!=''"
374+
375+# a repo the walk deliberately skipped (it lives inside a node_modules tree) is
376+# still served when asked for by path, and is attributed to its root
377+mkdir -p "$ROOTS/node_modules"
378+cp -a "$ROOTS/cleanrepo" "$ROOTS/node_modules/skipped"
379+UNSEEN=$(body "$(env QUERY_STRING="action=repo&path=$ROOTS/node_modules/skipped" \
380+ GITSTAT_ONLY_ROOTS=1 GITSTAT_ROOTS="$ROOTS" $BIN)")
381+json_ok "the walk skips node_modules" "$REPOSB" \
382+ "not any('node_modules' in r['path'] for r in d['repos'])"
383+json_ok "an undiscovered repo is read on demand" "$UNSEEN" "d['ok'] is True"
384+json_ok "a skipped repo is attributed to its root" "$UNSEEN" \
385+ "d['repo']['root']=='$ROOTS'"
373 386
374 AHEADD=$(env QUERY_STRING="action=repo&path=$ROOTS/aheadrepo" \387 AHEADD=$(env QUERY_STRING="action=repo&path=$ROOTS/aheadrepo" \
375 GITSTAT_ONLY_ROOTS=1 GITSTAT_ROOTS="$ROOTS" $BIN)388 GITSTAT_ONLY_ROOTS=1 GITSTAT_ROOTS="$ROOTS" $BIN)
376389