Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remote: align --verbose output with spaces #1837

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 32 additions & 8 deletions builtin/remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "strvec.h"
#include "commit-reach.h"
#include "progress.h"
#include "utf8.h"

static const char * const builtin_remote_usage[] = {
"git remote [-v | --verbose]",
Expand Down Expand Up @@ -1279,6 +1280,20 @@ static int get_one_entry(struct remote *remote, void *priv)
return 0;
}

static int calc_maxwidth(struct string_list *list)
{
int max = 0;
struct string_list_item *item;

for_each_string_list_item (item, list) {
int w = utf8_strwidth(item->string);

if (w > max)
max = w;
}
return max;
}

static int show_all(void)
{
struct string_list list = STRING_LIST_INIT_DUP;
Expand All @@ -1287,16 +1302,25 @@ static int show_all(void)
result = for_each_remote(get_one_entry, &list);

if (!result) {
int i;
int maxwidth = 0;
struct string_list_item *item;

if (verbose)
maxwidth = calc_maxwidth(&list);
string_list_sort(&list);
for (i = 0; i < list.nr; i++) {
struct string_list_item *item = list.items + i;
if (verbose)
printf("%s\t%s\n", item->string,
item->util ? (const char *)item->util : "");
else {
if (i && !strcmp((item - 1)->string, item->string))
for_each_string_list_item (item, &list) {
if (verbose) {
struct strbuf s = STRBUF_INIT;

strbuf_utf8_align(&s, ALIGN_LEFT, maxwidth + 1,
item->string);
if (item->util)
strbuf_addstr(&s, item->util);
printf("%s\n", s.buf);
strbuf_release(&s);
} else {
if (item != list.items &&
!strcmp((item - 1)->string, item->string))
continue;
printf("%s\n", item->string);
}
Expand Down
4 changes: 2 additions & 2 deletions t/t5505-remote.sh
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ test_expect_success 'without subcommand' '

test_expect_success 'without subcommand accepts -v' '
cat >expect <<-EOF &&
origin $(pwd)/one (fetch)
origin $(pwd)/one (push)
origin $(pwd)/one (fetch)
origin $(pwd)/one (push)
EOF
git -C test remote -v >actual &&
test_cmp expect actual
Expand Down
Loading