@matheusbsbs / matheus-bagliano / commits / 112d0bafd6
Fork 0

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>

Linus Torvalds committed Dec 18, 2005 at 12:41 UTC 112d0bafd620c0e0f10614a3ba021d4de4fae331
1 file changed +12 -9
git.c
+12 -9
@@ -85,25 +85,28 @@ static int cmdname_compare(const void *a_, const void *b_)
85
86 static void pretty_print_string_list(struct cmdname **cmdname, int longest)
87 {
88 - int cols = 1;
88 + int cols = 1, rows;
89 int space = longest + 1; /* min 1 SP between words */
90 int max_cols = term_columns() - 1; /* don't print *on* the edge */
91 - int i;
91 + int i, j;
92
93 if (space < max_cols)
94 cols = max_cols / space;
95 + rows = (cmdname_cnt + cols - 1) / cols;
96
97 qsort(cmdname, cmdname_cnt, sizeof(*cmdname), cmdname_compare);
98
98 - for (i = 0; i < cmdname_cnt; ) {
99 - int c;
99 + for (i = 0; i < rows; i++) {
100 printf(" ");
101
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);
110 }
111 putchar('\n');
112 }