[PATCH 1/2] fetch: better alignment in ref summary
- From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
- Date
- May 22, 2016, 11:20 UTC
- Message-ID
- <20160522112019.26516-2-pclouds@gmail.com>
- In-Reply-To
- <20160522112019.26516-1-pclouds@gmail.com>
Currently fetch hard-codes the "remote" column to be 10. For repos with long branch names, the output could look ugly like this
From github.com:pclouds/git * [new branch] 2nd-index -> pclouds/2nd-index * [new branch] 3nd-index -> pclouds/3nd-index * [new branch] file-watcher -> pclouds/file-watcher * [new branch] inst -> pclouds/inst * [new branch] large-file-fixes -> pclouds/large-file-fixes * [new branch] ls -> pclouds/ls * [new branch] master -> pclouds/master * [new branch] multiple-work-trees -> pclouds/multiple-work-trees * [new branch] mv -> pclouds/mv * [new branch] read-cache-daemon -> pclouds/read-cache-daemon * [new branch] split-blob -> pclouds/split-blob * [new branch] split-index -> pclouds/split-index * [new branch] status-fast-fast -> pclouds/status-fast-fast * [new branch] untracked-cache -> pclouds/untracked-cache
This patch makes the output a bit better with minimum code change
From github.com:pclouds/git * [new branch] 2nd-index -> pclouds/2nd-index * [new branch] 3nd-index -> pclouds/3nd-index * [new branch] file-watcher -> pclouds/file-watcher * [new branch] inst -> pclouds/inst * [new branch] large-file-fixes -> pclouds/large-file-fixes * [new branch] ls -> pclouds/ls * [new branch] master -> pclouds/master * [new branch] multiple-work-trees -> pclouds/multiple-work-trees * [new branch] mv -> pclouds/mv * [new branch] read-cache-daemon -> pclouds/read-cache-daemon * [new branch] split-blob -> pclouds/split-blob * [new branch] split-index -> pclouds/split-index * [new branch] status-fast-fast -> pclouds/status-fast-fast * [new branch] untracked-cache -> pclouds/untracked-cache
To make all "->" aligned, we may need to go through the ref list twice, or buffer the output and let column.c align it. Either way needs a lot more work than this.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> --- builtin/fetch.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/builtin/fetch.c b/builtin/fetch.c index 1cf15d0..223e09b 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -465,7 +465,14 @@ fail: : STORE_REF_ERROR_OTHER; } -#define REFCOL_WIDTH 10 +static int REFCOL_WIDTH = 10; + +static void adjust_refcol_width(int len) +{ + if (REFCOL_WIDTH < len) { + REFCOL_WIDTH = len; + } +} static int update_local_ref(struct ref *ref, const char *remote, @@ -477,6 +484,8 @@ static int update_local_ref(struct ref *ref, struct branch *current_branch = branch_get(NULL); const char *pretty_ref = prettify_refname(ref->name); + adjust_refcol_width(gettext_width(remote)); + type = sha1_object_info(ref->new_oid.hash, NULL); if (type < 0) die(_("object %s not found"), oid_to_hex(&ref->new_oid));
-- 2.8.2.524.g6ff3d78