Skip to content

Commit 112d0ba

Browse files
Linus TorvaldsJunio C Hamano
authored andcommitted
Make "git help" sort git commands in columns
This changes "pretty_print_string_list()" to show the git commands alphabetically in column order, which is the normal one. Ie instead of doing git commands available in '/home/torvalds/bin' ---------------------------------------------- add am ... applypatch archimport ... cat-file check-ref-format ... ... it does git commands available in '/home/torvalds/bin' ---------------------------------------------- add diff-tree ... am fetch ... apply fetch-pack ... ... where each column is sorted. This is how "ls" sorts things too, and since visually the columns are much more distinct than the rows, so it _looks_ more sorted. The "ls" command has a "-x" option that lists entries by lines (the way git.c used to): if somebody wants to do that, the new print-out logic could be easily accomodated to that too. Matter of taste and preference, I guess. Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent ea77e67 commit 112d0ba

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

git.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,25 +85,28 @@ static int cmdname_compare(const void *a_, const void *b_)
8585

8686
static void pretty_print_string_list(struct cmdname **cmdname, int longest)
8787
{
88-
int cols = 1;
88+
int cols = 1, rows;
8989
int space = longest + 1; /* min 1 SP between words */
9090
int max_cols = term_columns() - 1; /* don't print *on* the edge */
91-
int i;
91+
int i, j;
9292

9393
if (space < max_cols)
9494
cols = max_cols / space;
95+
rows = (cmdname_cnt + cols - 1) / cols;
9596

9697
qsort(cmdname, cmdname_cnt, sizeof(*cmdname), cmdname_compare);
9798

98-
for (i = 0; i < cmdname_cnt; ) {
99-
int c;
99+
for (i = 0; i < rows; i++) {
100100
printf(" ");
101101

102-
for (c = cols; c && i < cmdname_cnt; i++) {
103-
printf("%s", cmdname[i]->name);
104-
105-
if (--c)
106-
mput_char(' ', space - cmdname[i]->len);
102+
for (j = 0; j < cols; j++) {
103+
int n = j * rows + i;
104+
int size = space;
105+
if (n >= cmdname_cnt)
106+
break;
107+
if (j == cols-1 || n + rows >= cmdname_cnt)
108+
size = 1;
109+
printf("%-*s", size, cmdname[n]->name);
107110
}
108111
putchar('\n');
109112
}

0 commit comments

Comments
 (0)