From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Subject: [PATCH 3/3] transport: allow summary-width to be computed dynamically
Date: Fri, 21 Oct 2016 15:39:27 -0700 [thread overview]
Message-ID: <20161021223927.26364-4-gitster@pobox.com> (raw)
In-Reply-To: <20161021223927.26364-1-gitster@pobox.com>
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>
---
builtin/fetch.c | 4 ++--
transport.c | 7 ++++++-
transport.h | 2 +-
3 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 40696e5338..09813cd826 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -722,7 +722,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
char *url;
const char *filename = dry_run ? "/dev/null" : git_path_fetch_head();
int want_status;
- int summary_width = TRANSPORT_SUMMARY_WIDTH;
+ int summary_width = transport_summary_width(ref_map);
fp = fopen(filename, "a");
if (!fp)
@@ -906,7 +906,7 @@ static int prune_refs(struct refspec *refs, int ref_count, struct ref *ref_map,
int url_len, i, result = 0;
struct ref *ref, *stale_refs = get_stale_heads(refs, ref_count, ref_map);
char *url;
- int summary_width = TRANSPORT_SUMMARY_WIDTH;
+ int summary_width = transport_summary_width(stale_refs);
const char *dangling_msg = dry_run
? _(" (%s will become dangling)")
: _(" (%s has become dangling)");
diff --git a/transport.c b/transport.c
index ec02b78924..d4b8bf5f25 100644
--- a/transport.c
+++ b/transport.c
@@ -429,6 +429,11 @@ static int print_one_push_status(struct ref *ref, const char *dest, int count,
return 1;
}
+int transport_summary_width(const struct ref *refs)
+{
+ return (2 * FALLBACK_DEFAULT_ABBREV + 3);
+}
+
void transport_print_push_status(const char *dest, struct ref *refs,
int verbose, int porcelain, unsigned int *reject_reasons)
{
@@ -436,7 +441,7 @@ void transport_print_push_status(const char *dest, struct ref *refs,
int n = 0;
unsigned char head_sha1[20];
char *head;
- int summary_width = TRANSPORT_SUMMARY_WIDTH;
+ int summary_width = transport_summary_width(refs);
head = resolve_refdup("HEAD", RESOLVE_REF_READING, head_sha1, NULL);
diff --git a/transport.h b/transport.h
index e783377e40..706d99e818 100644
--- a/transport.h
+++ b/transport.h
@@ -142,7 +142,7 @@ struct transport {
#define TRANSPORT_PUSH_ATOMIC 8192
#define TRANSPORT_PUSH_OPTIONS 16384
-#define TRANSPORT_SUMMARY_WIDTH (2 * FALLBACK_DEFAULT_ABBREV + 3)
+extern int transport_summary_width(const struct ref *refs);
/* Returns a transport suitable for the url */
struct transport *transport_get(struct remote *, const char *);
--
2.10.1-723-g2384e83bc3
next prev parent reply other threads:[~2016-10-21 22:39 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-21 0:26 [BUG] fetch output is ugly in 'next' Jeff King
2016-10-21 12:11 ` Duy Nguyen
2016-10-21 13:07 ` Duy Nguyen
2016-10-21 16:50 ` Junio C Hamano
2016-10-21 21:42 ` Jeff King
2016-10-21 22:14 ` Junio C Hamano
2016-10-21 22:39 ` [PATCH 0/3] " Junio C Hamano
2016-10-21 22:39 ` [PATCH 1/3] transport: pass summary_width down the callchain Junio C Hamano
2016-10-21 22:39 ` [PATCH 2/3] fetch: " Junio C Hamano
2016-10-21 22:39 ` Junio C Hamano [this message]
2016-10-22 4:10 ` [PATCH 3/3] transport: allow summary-width to be computed dynamically Jeff King
2016-10-22 4:39 ` Junio C Hamano
2016-10-22 5:04 ` Jeff King
2016-10-22 16:25 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161021223927.26364-4-gitster@pobox.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).