Skip to content

Commit b18aaaa

Browse files
pks-tgitster
authored andcommitted
fetch: skip computing output width when not printing anything
When updating references via git-fetch(1), then by default we report to the user which references have been changed. This output is formatted in a nice table such that the different columns are aligned. Because the first column contains abbreviated object IDs we thus need to iterate over all refs which have changed and compute the minimum length for their respective abbreviated hashes. While this effort makes sense in most cases, it is wasteful when the user passes the `--quiet` flag: we don't print the summary, but still compute the length. Skip computing the summary width when the user asked for us to be quiet. This gives us a speedup of nearly 10% when doing a mirror-fetch in a repository with thousands of references being updated: Benchmark 1: git fetch --quiet +refs/*:refs/* (HEAD~) Time (mean ± σ): 96.078 s ± 0.508 s [User: 91.378 s, System: 10.870 s] Range (min … max): 95.449 s … 96.760 s 5 runs Benchmark 2: git fetch --quiet +refs/*:refs/* (HEAD) Time (mean ± σ): 88.214 s ± 0.192 s [User: 83.274 s, System: 10.978 s] Range (min … max): 87.998 s … 88.446 s 5 runs Summary 'git fetch --quiet +refs/*:refs/* (HEAD)' ran 1.09 ± 0.01 times faster than 'git fetch --quiet +refs/*:refs/* (HEAD~)' Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6fd1cc8 commit b18aaaa

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

builtin/fetch.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,12 +1094,15 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
10941094
struct ref *rm;
10951095
char *url;
10961096
int want_status;
1097-
int summary_width = transport_summary_width(ref_map);
1097+
int summary_width = 0;
10981098

10991099
rc = open_fetch_head(&fetch_head);
11001100
if (rc)
11011101
return -1;
11021102

1103+
if (verbosity >= 0)
1104+
summary_width = transport_summary_width(ref_map);
1105+
11031106
if (raw_url)
11041107
url = transport_anonymize_url(raw_url);
11051108
else
@@ -1345,7 +1348,6 @@ static int prune_refs(struct refspec *rs, struct ref *ref_map,
13451348
int url_len, i, result = 0;
13461349
struct ref *ref, *stale_refs = get_stale_heads(rs, ref_map);
13471350
char *url;
1348-
int summary_width = transport_summary_width(stale_refs);
13491351
const char *dangling_msg = dry_run
13501352
? _(" (%s will become dangling)")
13511353
: _(" (%s has become dangling)");
@@ -1374,6 +1376,8 @@ static int prune_refs(struct refspec *rs, struct ref *ref_map,
13741376
}
13751377

13761378
if (verbosity >= 0) {
1379+
int summary_width = transport_summary_width(stale_refs);
1380+
13771381
for (ref = stale_refs; ref; ref = ref->next) {
13781382
struct strbuf sb = STRBUF_INIT;
13791383
if (!shown_url) {

0 commit comments

Comments
 (0)