Skip to content

Commit 11fd66d

Browse files
committed
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 <[email protected]>
1 parent 901f3d4 commit 11fd66d

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

builtin/fetch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
722722
char *url;
723723
const char *filename = dry_run ? "/dev/null" : git_path_fetch_head();
724724
int want_status;
725-
int summary_width = TRANSPORT_SUMMARY_WIDTH;
725+
int summary_width = transport_summary_width(ref_map);
726726

727727
fp = fopen(filename, "a");
728728
if (!fp)
@@ -906,7 +906,7 @@ static int prune_refs(struct refspec *refs, int ref_count, struct ref *ref_map,
906906
int url_len, i, result = 0;
907907
struct ref *ref, *stale_refs = get_stale_heads(refs, ref_count, ref_map);
908908
char *url;
909-
int summary_width = TRANSPORT_SUMMARY_WIDTH;
909+
int summary_width = transport_summary_width(stale_refs);
910910
const char *dangling_msg = dry_run
911911
? _(" (%s will become dangling)")
912912
: _(" (%s has become dangling)");

transport.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,14 +429,19 @@ static int print_one_push_status(struct ref *ref, const char *dest, int count,
429429
return 1;
430430
}
431431

432+
int transport_summary_width(const struct ref *refs)
433+
{
434+
return (2 * FALLBACK_DEFAULT_ABBREV + 3);
435+
}
436+
432437
void transport_print_push_status(const char *dest, struct ref *refs,
433438
int verbose, int porcelain, unsigned int *reject_reasons)
434439
{
435440
struct ref *ref;
436441
int n = 0;
437442
unsigned char head_sha1[20];
438443
char *head;
439-
int summary_width = TRANSPORT_SUMMARY_WIDTH;
444+
int summary_width = transport_summary_width(refs);
440445

441446
head = resolve_refdup("HEAD", RESOLVE_REF_READING, head_sha1, NULL);
442447

transport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ struct transport {
142142
#define TRANSPORT_PUSH_ATOMIC 8192
143143
#define TRANSPORT_PUSH_OPTIONS 16384
144144

145-
#define TRANSPORT_SUMMARY_WIDTH (2 * FALLBACK_DEFAULT_ABBREV + 3)
145+
extern int transport_summary_width(const struct ref *refs);
146146

147147
/* Returns a transport suitable for the url */
148148
struct transport *transport_get(struct remote *, const char *);

0 commit comments

Comments
 (0)