Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
transport: compute summary-width dynamically
author
Junio C Hamano
<gitster@pobox.com>
Sat, 22 Oct 2016 04:33:06 +0000
(21:33 -0700)
committer
Junio C Hamano
<gitster@pobox.com>
Sat, 22 Oct 2016 16:37:29 +0000
(09:37 -0700)
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>
transport.c
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
11fd66d
)
diff --git
a/transport.c
b/transport.c
index d4b8bf5f25c72fa37b68110ba6ccc527456e4ef9..2af1109920db78f01b6bdc1ef1b9027073224315 100644
(file)
--- 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;
}
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)
{
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,
}
void transport_print_push_status(const char *dest, struct ref *refs,