summaryrefslogtreecommitdiff
path: root/transport.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2016-10-22 04:33:06 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-10-22 16:37:29 (GMT)
commitdb98d9bafa7081aa95c15c278e39b5dfa5af8e48 (patch)
tree11e77d59b76a76863f80a0bab970a7ac62a3051c /transport.c
parent11fd66de9bceac5ffb70ad3ad225203b95d19aa2 (diff)
downloadgit-db98d9bafa7081aa95c15c278e39b5dfa5af8e48.zip
git-db98d9bafa7081aa95c15c278e39b5dfa5af8e48.tar.gz
git-db98d9bafa7081aa95c15c278e39b5dfa5af8e48.tar.bz2
transport: compute summary-width dynamically
Now all that is left to do is to actually iterate over the refs and measure the display width needed to show their abbreviation. Helped-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'transport.c')
-rw-r--r--transport.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/transport.c b/transport.c
index d4b8bf5..2af1109 100644
--- a/transport.c
+++ b/transport.c
@@ -429,9 +429,25 @@ static int print_one_push_status(struct ref *ref, const char *dest, int count,
return 1;
}
+static int measure_abbrev(const struct object_id *oid, int sofar)
+{
+ char hex[GIT_SHA1_HEXSZ + 1];
+ int w = find_unique_abbrev_r(hex, oid->hash, DEFAULT_ABBREV);
+
+ return (w < sofar) ? sofar : w;
+}
+
int transport_summary_width(const struct ref *refs)
{
- return (2 * FALLBACK_DEFAULT_ABBREV + 3);
+ int maxw = -1;
+
+ for (; refs; refs = refs->next) {
+ maxw = measure_abbrev(&refs->old_oid, maxw);
+ maxw = measure_abbrev(&refs->new_oid, maxw);
+ }
+ if (maxw < 0)
+ maxw = FALLBACK_DEFAULT_ABBREV;
+ return (2 * maxw + 3);
}
void transport_print_push_status(const char *dest, struct ref *refs,