transport: allow summary-width to be computed dynamically
Now we have identified three callchains that have a set of refs that they want to show their <old, new> object names in an aligned output, we can replace their reference to the constant TRANSPORT_SUMMARY_WIDTH with a helper function call to transport_summary_width() that takes the set of ref as a parameter. This step does not yet iterate over the refs and compute, which is left as an exercise to the readers. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Oct 21, 2016 at 15:28 UTC
11fd66de9bceac5ffb70ad3ad225203b95d19aa2
3 files changed
+9
-4
builtin/fetch.c
+2
-2
@@ -722,7 +722,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
722
char *url;
723
const char *filename = dry_run ? "/dev/null" : git_path_fetch_head();
724
int want_status;
725
- int summary_width = TRANSPORT_SUMMARY_WIDTH;
725
+ int summary_width = transport_summary_width(ref_map);
726
727
fp = fopen(filename, "a");
728
if (!fp)
@@ -906,7 +906,7 @@ static int prune_refs(struct refspec *refs, int ref_count, struct ref *ref_map,
906
int url_len, i, result = 0;
907
struct ref *ref, *stale_refs = get_stale_heads(refs, ref_count, ref_map);
908
char *url;
909
- int summary_width = TRANSPORT_SUMMARY_WIDTH;
909
+ int summary_width = transport_summary_width(stale_refs);
910
const char *dangling_msg = dry_run
911
? _(" (%s will become dangling)")
912
: _(" (%s has become dangling)");
transport.c
+6
-1
@@ -429,6 +429,11 @@ static int print_one_push_status(struct ref *ref, const char *dest, int count,
429
return 1;
430
}
431
432
+int transport_summary_width(const struct ref *refs)
433
+{
434
+ return (2 * FALLBACK_DEFAULT_ABBREV + 3);
435
+}
436
+
437
void transport_print_push_status(const char *dest, struct ref *refs,
438
int verbose, int porcelain, unsigned int *reject_reasons)
439
{
@@ -436,7 +441,7 @@ void transport_print_push_status(const char *dest, struct ref *refs,
441
int n = 0;
442
unsigned char head_sha1[20];
443
char *head;
439
- int summary_width = TRANSPORT_SUMMARY_WIDTH;
444
+ int summary_width = transport_summary_width(refs);
445
446
head = resolve_refdup("HEAD", RESOLVE_REF_READING, head_sha1, NULL);
447
transport.h
+1
-1
@@ -142,7 +142,7 @@ struct transport {
142
#define TRANSPORT_PUSH_ATOMIC 8192
143
#define TRANSPORT_PUSH_OPTIONS 16384
144
145
-#define TRANSPORT_SUMMARY_WIDTH (2 * FALLBACK_DEFAULT_ABBREV + 3)
145
+extern int transport_summary_width(const struct ref *refs);
146
147
/* Returns a transport suitable for the url */
148
struct transport *transport_get(struct remote *, const char *);