Skip to content

Commit db98d9b

Browse files
committed
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 11fd66d commit db98d9b

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

transport.c

+17-1
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,25 @@ static int print_one_push_status(struct ref *ref, const char *dest, int count,
429429
return 1;
430430
}
431431

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+
432440
int transport_summary_width(const struct ref *refs)
433441
{
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);
435451
}
436452

437453
void transport_print_push_status(const char *dest, struct ref *refs,

0 commit comments

Comments
 (0)