perf(gitstat): read the origin URL only for the repo you open
The board shows the branch and upstream, not the remote URL, so paying for a git config child process on every row was waste - on a Mac with fifty checkouts it was most of a second per row. The detail response still carries it, redacted. porcelain v2 has no stash count (--show-stash only decorates the human output), so the stash child process stays.
AuthorPico <picobot@scorpioplayer.com>
Date2026-11-12 09:50:48
Commitd6f3368a
Parents843327b0
Changed files
src/plugin_gitstat.c+28−20■■■■■
tests/run.sh+7−2■■■■■
2 files+35−22
Diff
src/plugin_gitstat.c+28−20■■■■■
index c3eacb2..1b112cf 100644
--- a/src/plugin_gitstat.c
+++ b/src/plugin_gitstat.c
@@ -934,13 +934,18 @@ static void status_path(const char *line, char *out, size_t sz)
934934 }
935935 }
936936
937-static void query_repo(repo_t *r)
937+/* Three child processes per repository, not four: the origin URL is only read
938+ * for the repository you actually open, not for every row of the board. On a Mac
939+ * with fifty checkouts that is most of a second saved per row. (--show-stash
940+ * would fold the stash count into the status header too, but only in the human
941+ * output - porcelain v2 never carries it, so `stash list` stays.) */
942+static void query_repo(repo_t *r, int with_remote)
938943 {
939944 buf_t out;
940945 char *status_args[] = { (char *)"status", (char *)"--porcelain=v2",
941946 (char *)"--branch", (char *)"--untracked-files=normal", NULL };
942- char *log_args[] = { (char *)"log", (char *)"-1", (char *)"--format=%H%x09%ct%x09%s", NULL };
943947 char *stash_args[] = { (char *)"stash", (char *)"list", (char *)"--format=%gd", NULL };
948+ char *log_args[] = { (char *)"log", (char *)"-1", (char *)"--format=%H%x09%ct%x09%s", NULL };
944949
945950 buf_init(&out);
946951 if (run_git(r->path, status_args, &out, GIT_TIMEOUT_S) >= 0)
@@ -969,21 +974,6 @@ static void query_repo(repo_t *r)
969974 }
970975 buf_free(&out);
971976
972- buf_init(&out);
973- {
974- char *cfg_args[] = { (char *)"config", (char *)"--get",
975- (char *)"remote.origin.url", NULL };
976- if (run_git(r->path, cfg_args, &out, GIT_TIMEOUT_S) >= 0 && out.len > 0) {
977- char raw[512];
978- char clean[512];
979- str_copy(raw, sizeof(raw), out.p);
980- str_trim(raw);
981- redact_url(raw, clean, sizeof(clean));
982- str_copy(r->remote, sizeof(r->remote), clean);
983- }
984- }
985- buf_free(&out);
986-
987977 buf_init(&out);
988978 if (run_git(r->path, stash_args, &out, GIT_TIMEOUT_S) >= 0) {
989979 const char *p = out.p;
@@ -995,6 +985,23 @@ static void query_repo(repo_t *r)
995985 }
996986 }
997987 buf_free(&out);
988+
989+ if (with_remote) {
990+ buf_init(&out);
991+ {
992+ char *cfg_args[] = { (char *)"config", (char *)"--get",
993+ (char *)"remote.origin.url", NULL };
994+ if (run_git(r->path, cfg_args, &out, GIT_TIMEOUT_S) >= 0 && out.len > 0) {
995+ char raw[512];
996+ char clean[512];
997+ str_copy(raw, sizeof(raw), out.p);
998+ str_trim(raw);
999+ redact_url(raw, clean, sizeof(clean));
1000+ str_copy(r->remote, sizeof(r->remote), clean);
1001+ }
1002+ }
1003+ buf_free(&out);
1004+ }
9981005 }
9991006
10001007 static int repo_cmp(const void *a, const void *b)
@@ -1029,7 +1036,7 @@ static void collect_repos(void)
10291036 g_roots[i].count = g_repo_count - before;
10301037 }
10311038
1032- for (i = 0; i < g_repo_count; i++) query_repo(&g_repos[i]);
1039+ for (i = 0; i < g_repo_count; i++) query_repo(&g_repos[i], 0);
10331040
10341041 if (g_repo_count > 1)
10351042 qsort(g_repos, (size_t)g_repo_count, sizeof(repo_t), repo_cmp);
@@ -1210,6 +1217,7 @@ static int print_repo_detail(const char *path)
12101217 for (i = 0; i < g_repo_count; i++) {
12111218 if (strcmp(g_repos[i].path, canon) == 0) { r = &g_repos[i]; break; }
12121219 }
1220+ if (r) query_repo(r, 1);
12131221 if (!r) {
12141222 if (g_repo_count >= MAX_REPOS) {
12151223 json_header(400);
@@ -1221,7 +1229,7 @@ static int print_repo_detail(const char *path)
12211229 str_copy(r->path, sizeof(r->path), canon);
12221230 str_copy(r->name, sizeof(r->name), base_name(canon));
12231231 str_copy(r->root, sizeof(r->root), "");
1224- query_repo(r);
1232+ query_repo(r, 1);
12251233 g_repo_count++;
12261234 }
12271235
@@ -1351,7 +1359,7 @@ static int do_fetch(const char *path, int *status_out)
13511359
13521360 memset(&tmp, 0, sizeof(tmp));
13531361 str_copy(tmp.path, sizeof(tmp.path), canon);
1354- query_repo(&tmp);
1362+ query_repo(&tmp, 1);
13551363
13561364 buf_init(&b);
13571365 buf_printf(&b, "{\"ok\":%s,\"action\":\"fetch\",\"exit\":%d",
tests/run.sh+7−2■■■■■
index 3961ee8..7336499 100755
--- a/tests/run.sh
+++ b/tests/run.sh
@@ -303,8 +303,13 @@ d=json.load(sys.stdin)
303303 print(json.dumps([r for r in d['repos'] if r['name']=='secretremote'][0]))")
304304 check_not "credential in the origin URL is redacted (token)" "planttoken123" "$SEC"
305305 check_not "credential in the origin URL is redacted (user)" "plantuser" "$SEC"
306-check "redacted remote keeps the host" "example.invalid/x.git" "$SEC"
307-check_not "the remote field carries no userinfo" "plantuser" "$(printf '%s' "$SEC" | python3 -c "import json,sys;print(json.load(sys.stdin)['remote'])")"
306+SECUREMOTE=$(env QUERY_STRING="action=repo&path=$ROOTS/secretremote" \
307+ GITSTAT_ONLY_ROOTS=1 GITSTAT_ROOTS="$ROOTS" $BIN | body)
308+check "the board row does not pay for the origin URL" "\"remote\":\"\"" "$SEC"
309+json_ok "the detail reads the origin URL" "$SECUREMOTE" \
310+ "d['repo']['remote']=='https://example.invalid/x.git'"
311+check_not "the detail remote carries no userinfo" "plantuser" "$SECUREMOTE"
312+check_not "the detail remote carries no token" "planttoken123" "$SECUREMOTE"
308313
309314 check_not "no path outside the root is reported" "$WORK/upstream.git" "$REPOSB"
310315
311316
src/plugin_gitstat.c+28−20■■■■■
index c3eacb2..1b112cf 100644index c3eacb2..1b112cf 100644
--- a/src/plugin_gitstat.c--- a/src/plugin_gitstat.c
+++ b/src/plugin_gitstat.c+++ b/src/plugin_gitstat.c
@@ -934,13 +934,18 @@ static void status_path(const char *line, char *out, size_t sz)@@ -934,13 +934,18 @@ static void status_path(const char *line, char *out, size_t sz)
934 }934 }
935 }935 }
936 936
937-static void query_repo(repo_t *r)937+/* Three child processes per repository, not four: the origin URL is only read
938+ * for the repository you actually open, not for every row of the board. On a Mac
939+ * with fifty checkouts that is most of a second saved per row. (--show-stash
940+ * would fold the stash count into the status header too, but only in the human
941+ * output - porcelain v2 never carries it, so `stash list` stays.) */
942+static void query_repo(repo_t *r, int with_remote)
938 {943 {
939 buf_t out;944 buf_t out;
940 char *status_args[] = { (char *)"status", (char *)"--porcelain=v2",945 char *status_args[] = { (char *)"status", (char *)"--porcelain=v2",
941 (char *)"--branch", (char *)"--untracked-files=normal", NULL };946 (char *)"--branch", (char *)"--untracked-files=normal", NULL };
942- char *log_args[] = { (char *)"log", (char *)"-1", (char *)"--format=%H%x09%ct%x09%s", NULL };
943 char *stash_args[] = { (char *)"stash", (char *)"list", (char *)"--format=%gd", NULL };947 char *stash_args[] = { (char *)"stash", (char *)"list", (char *)"--format=%gd", NULL };
948+ char *log_args[] = { (char *)"log", (char *)"-1", (char *)"--format=%H%x09%ct%x09%s", NULL };
944 949
945 buf_init(&out);950 buf_init(&out);
946 if (run_git(r->path, status_args, &out, GIT_TIMEOUT_S) >= 0)951 if (run_git(r->path, status_args, &out, GIT_TIMEOUT_S) >= 0)
@@ -969,21 +974,6 @@ static void query_repo(repo_t *r)@@ -969,21 +974,6 @@ static void query_repo(repo_t *r)
969 }974 }
970 buf_free(&out);975 buf_free(&out);
971 976
972- buf_init(&out);
973- {
974- char *cfg_args[] = { (char *)"config", (char *)"--get",
975- (char *)"remote.origin.url", NULL };
976- if (run_git(r->path, cfg_args, &out, GIT_TIMEOUT_S) >= 0 && out.len > 0) {
977- char raw[512];
978- char clean[512];
979- str_copy(raw, sizeof(raw), out.p);
980- str_trim(raw);
981- redact_url(raw, clean, sizeof(clean));
982- str_copy(r->remote, sizeof(r->remote), clean);
983- }
984- }
985- buf_free(&out);
986-
987 buf_init(&out);977 buf_init(&out);
988 if (run_git(r->path, stash_args, &out, GIT_TIMEOUT_S) >= 0) {978 if (run_git(r->path, stash_args, &out, GIT_TIMEOUT_S) >= 0) {
989 const char *p = out.p;979 const char *p = out.p;
@@ -995,6 +985,23 @@ static void query_repo(repo_t *r)@@ -995,6 +985,23 @@ static void query_repo(repo_t *r)
995 }985 }
996 }986 }
997 buf_free(&out);987 buf_free(&out);
988+
989+ if (with_remote) {
990+ buf_init(&out);
991+ {
992+ char *cfg_args[] = { (char *)"config", (char *)"--get",
993+ (char *)"remote.origin.url", NULL };
994+ if (run_git(r->path, cfg_args, &out, GIT_TIMEOUT_S) >= 0 && out.len > 0) {
995+ char raw[512];
996+ char clean[512];
997+ str_copy(raw, sizeof(raw), out.p);
998+ str_trim(raw);
999+ redact_url(raw, clean, sizeof(clean));
1000+ str_copy(r->remote, sizeof(r->remote), clean);
1001+ }
1002+ }
1003+ buf_free(&out);
1004+ }
998 }1005 }
999 1006
1000 static int repo_cmp(const void *a, const void *b)1007 static int repo_cmp(const void *a, const void *b)
@@ -1029,7 +1036,7 @@ static void collect_repos(void)@@ -1029,7 +1036,7 @@ static void collect_repos(void)
1029 g_roots[i].count = g_repo_count - before;1036 g_roots[i].count = g_repo_count - before;
1030 }1037 }
1031 1038
1032- for (i = 0; i < g_repo_count; i++) query_repo(&g_repos[i]);1039+ for (i = 0; i < g_repo_count; i++) query_repo(&g_repos[i], 0);
1033 1040
1034 if (g_repo_count > 1)1041 if (g_repo_count > 1)
1035 qsort(g_repos, (size_t)g_repo_count, sizeof(repo_t), repo_cmp);1042 qsort(g_repos, (size_t)g_repo_count, sizeof(repo_t), repo_cmp);
@@ -1210,6 +1217,7 @@ static int print_repo_detail(const char *path)@@ -1210,6 +1217,7 @@ static int print_repo_detail(const char *path)
1210 for (i = 0; i < g_repo_count; i++) {1217 for (i = 0; i < g_repo_count; i++) {
1211 if (strcmp(g_repos[i].path, canon) == 0) { r = &g_repos[i]; break; }1218 if (strcmp(g_repos[i].path, canon) == 0) { r = &g_repos[i]; break; }
1212 }1219 }
1220+ if (r) query_repo(r, 1);
1213 if (!r) {1221 if (!r) {
1214 if (g_repo_count >= MAX_REPOS) {1222 if (g_repo_count >= MAX_REPOS) {
1215 json_header(400);1223 json_header(400);
@@ -1221,7 +1229,7 @@ static int print_repo_detail(const char *path)@@ -1221,7 +1229,7 @@ static int print_repo_detail(const char *path)
1221 str_copy(r->path, sizeof(r->path), canon);1229 str_copy(r->path, sizeof(r->path), canon);
1222 str_copy(r->name, sizeof(r->name), base_name(canon));1230 str_copy(r->name, sizeof(r->name), base_name(canon));
1223 str_copy(r->root, sizeof(r->root), "");1231 str_copy(r->root, sizeof(r->root), "");
1224- query_repo(r);1232+ query_repo(r, 1);
1225 g_repo_count++;1233 g_repo_count++;
1226 }1234 }
1227 1235
@@ -1351,7 +1359,7 @@ static int do_fetch(const char *path, int *status_out)@@ -1351,7 +1359,7 @@ static int do_fetch(const char *path, int *status_out)
1351 1359
1352 memset(&tmp, 0, sizeof(tmp));1360 memset(&tmp, 0, sizeof(tmp));
1353 str_copy(tmp.path, sizeof(tmp.path), canon);1361 str_copy(tmp.path, sizeof(tmp.path), canon);
1354- query_repo(&tmp);1362+ query_repo(&tmp, 1);
1355 1363
1356 buf_init(&b);1364 buf_init(&b);
1357 buf_printf(&b, "{\"ok\":%s,\"action\":\"fetch\",\"exit\":%d",1365 buf_printf(&b, "{\"ok\":%s,\"action\":\"fetch\",\"exit\":%d",
tests/run.sh+7−2■■■■■
index 3961ee8..7336499 100755index 3961ee8..7336499 100755
--- a/tests/run.sh--- a/tests/run.sh
+++ b/tests/run.sh+++ b/tests/run.sh
@@ -303,8 +303,13 @@ d=json.load(sys.stdin)@@ -303,8 +303,13 @@ d=json.load(sys.stdin)
303 print(json.dumps([r for r in d['repos'] if r['name']=='secretremote'][0]))")303 print(json.dumps([r for r in d['repos'] if r['name']=='secretremote'][0]))")
304 check_not "credential in the origin URL is redacted (token)" "planttoken123" "$SEC"304 check_not "credential in the origin URL is redacted (token)" "planttoken123" "$SEC"
305 check_not "credential in the origin URL is redacted (user)" "plantuser" "$SEC"305 check_not "credential in the origin URL is redacted (user)" "plantuser" "$SEC"
306-check "redacted remote keeps the host" "example.invalid/x.git" "$SEC"306+SECUREMOTE=$(env QUERY_STRING="action=repo&path=$ROOTS/secretremote" \
307-check_not "the remote field carries no userinfo" "plantuser" "$(printf '%s' "$SEC" | python3 -c "import json,sys;print(json.load(sys.stdin)['remote'])")"307+ GITSTAT_ONLY_ROOTS=1 GITSTAT_ROOTS="$ROOTS" $BIN | body)
308+check "the board row does not pay for the origin URL" "\"remote\":\"\"" "$SEC"
309+json_ok "the detail reads the origin URL" "$SECUREMOTE" \
310+ "d['repo']['remote']=='https://example.invalid/x.git'"
311+check_not "the detail remote carries no userinfo" "plantuser" "$SECUREMOTE"
312+check_not "the detail remote carries no token" "planttoken123" "$SECUREMOTE"
308 313
309 check_not "no path outside the root is reported" "$WORK/upstream.git" "$REPOSB"314 check_not "no path outside the root is reported" "$WORK/upstream.git" "$REPOSB"
310 315
311316