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>
Junio C Hamano committed
Oct 21, 2016 at 21:33 UTC
db98d9bafa7081aa95c15c278e39b5dfa5af8e48
1 file changed
+17
-1
transport.c
+17
-1
@@ -429,9 +429,25 @@ static int print_one_push_status(struct ref *ref, const char *dest, int count,
429
return 1;
430
}
431
432
+static int measure_abbrev(const struct object_id *oid, int sofar)
433
+{
434
+ char hex[GIT_SHA1_HEXSZ + 1];
435
+ int w = find_unique_abbrev_r(hex, oid->hash, DEFAULT_ABBREV);
436
+
437
+ return (w < sofar) ? sofar : w;
438
+}
439
+
440
int transport_summary_width(const struct ref *refs)
441
{
434
- return (2 * FALLBACK_DEFAULT_ABBREV + 3);
442
+ int maxw = -1;
443
+
444
+ for (; refs; refs = refs->next) {
445
+ maxw = measure_abbrev(&refs->old_oid, maxw);
446
+ maxw = measure_abbrev(&refs->new_oid, maxw);
447
+ }
448
+ if (maxw < 0)
449
+ maxw = FALLBACK_DEFAULT_ABBREV;
450
+ return (2 * maxw + 3);
451
}
452
453
void transport_print_push_status(const char *dest, struct ref *refs,