| 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) | ||
| 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 | 944 | buf_t out; |
| 940 | 945 | char *status_args[] = { (char *)"status", (char *)"--porcelain=v2", |
| 941 | 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 | 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 | 950 | buf_init(&out); |
| 946 | 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 | 974 | } |
| 970 | 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 | 977 | buf_init(&out); |
| 988 | 978 | if (run_git(r->path, stash_args, &out, GIT_TIMEOUT_S) >= 0) { |
| 989 | 979 | const char *p = out.p; |
| @@ -995,6 +985,23 @@ static void query_repo(repo_t *r) | ||
| 995 | 985 | } |
| 996 | 986 | } |
| 997 | 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 | 1007 | static int repo_cmp(const void *a, const void *b) |
| @@ -1029,7 +1036,7 @@ static void collect_repos(void) | ||
| 1029 | 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 | 1041 | if (g_repo_count > 1) |
| 1035 | 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 | 1217 | for (i = 0; i < g_repo_count; i++) { |
| 1211 | 1218 | if (strcmp(g_repos[i].path, canon) == 0) { r = &g_repos[i]; break; } |
| 1212 | 1219 | } |
| 1220 | + if (r) query_repo(r, 1); | |
| 1213 | 1221 | if (!r) { |
| 1214 | 1222 | if (g_repo_count >= MAX_REPOS) { |
| 1215 | 1223 | json_header(400); |
| @@ -1221,7 +1229,7 @@ static int print_repo_detail(const char *path) | ||
| 1221 | 1229 | str_copy(r->path, sizeof(r->path), canon); |
| 1222 | 1230 | str_copy(r->name, sizeof(r->name), base_name(canon)); |
| 1223 | 1231 | str_copy(r->root, sizeof(r->root), ""); |
| 1224 | - query_repo(r); | |
| 1232 | + query_repo(r, 1); | |
| 1225 | 1233 | g_repo_count++; |
| 1226 | 1234 | } |
| 1227 | 1235 | |
| @@ -1351,7 +1359,7 @@ static int do_fetch(const char *path, int *status_out) | ||
| 1351 | 1359 | |
| 1352 | 1360 | memset(&tmp, 0, sizeof(tmp)); |
| 1353 | 1361 | str_copy(tmp.path, sizeof(tmp.path), canon); |
| 1354 | - query_repo(&tmp); | |
| 1362 | + query_repo(&tmp, 1); | |
| 1355 | 1363 | |
| 1356 | 1364 | buf_init(&b); |
| 1357 | 1365 | buf_printf(&b, "{\"ok\":%s,\"action\":\"fetch\",\"exit\":%d", |
| index 3961ee8..7336499 100755 | ||
| --- a/tests/run.sh | ||
| +++ b/tests/run.sh | ||
| @@ -303,8 +303,13 @@ d=json.load(sys.stdin) | ||
| 303 | 303 | print(json.dumps([r for r in d['repos'] if r['name']=='secretremote'][0]))") |
| 304 | 304 | check_not "credential in the origin URL is redacted (token)" "planttoken123" "$SEC" |
| 305 | 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" | |
| 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" | |
| 308 | 313 | |
| 309 | 314 | check_not "no path outside the root is reported" "$WORK/upstream.git" "$REPOSB" |
| 310 | 315 | |
| 311 | 316 |
| index c3eacb2..1b112cf 100644 | index 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", |
| index 3961ee8..7336499 100755 | index 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 | ||
| 311 | 316 |