| 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) | ||
| 1228 | 1228 | memset(r, 0, sizeof(*r)); |
| 1229 | 1229 | str_copy(r->path, sizeof(r->path), canon); |
| 1230 | 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 | 1245 | query_repo(r, 1); |
| 1233 | 1246 | g_repo_count++; |
| 1234 | 1247 | } |
| 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" | ||
| 370 | 370 | json_ok "each commit has hash/ct/author/subject" "$DETB" \ |
| 371 | 371 | "all(set(c)>=set(['hash','ct','author','subject']) for c in d['commits'])" |
| 372 | 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 | 387 | AHEADD=$(env QUERY_STRING="action=repo&path=$ROOTS/aheadrepo" \ |
| 375 | 388 | GITSTAT_ONLY_ROOTS=1 GITSTAT_ROOTS="$ROOTS" $BIN) |
| 376 | 389 |
| index 1b112cf..f8f9399 100644 | index 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 | } |
| index 8f40cc3..9a5385c 100755 | index 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) |
| 376 | 389 |