pretty.c: support <direction>|(<negative number>) forms
%>|(num), %><|(num) and %<|(num), where num is a positive number, sets a fixed column from the screen's left border. There is no way for us to specifiy a column relative to the right border, which is useful when you want to make use of all terminal space (on big screens). Use negative num for that. Inspired by Go's array syntax (*). (*) I know Python has this first (or before Go, at least) but the idea didn't occur to me until I learned Go. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Jun 16, 2016 at 20:18 UTC
066790d7cb0fa22e64f1276d8a0e33d18484f62a
2 files changed
+40
-1
pretty.c
+7
-1
@@ -1022,9 +1022,15 @@ static size_t parse_padding_placeholder(struct strbuf *sb,
1022
int width;
1023
if (!end || end == start)
1024
return 0;
1025
- width = strtoul(start, &next, 10);
1025
+ width = strtol(start, &next, 10);
1026
if (next == start || width == 0)
1027
return 0;
1028
+ if (width < 0) {
1029
+ if (to_column)
1030
+ width += term_columns();
1031
+ if (width < 0)
1032
+ return 0;
1033
+ }
1034
c->padding = to_column ? -width : width;
1035
c->flush_type = flush_type;
1036
t/t4205-log-pretty-formats.sh
+33
@@ -176,6 +176,17 @@ EOF
176
test_cmp expected actual
177
'
178
179
+test_expect_success 'left alignment formatting at the nth column' '
180
+ COLUMNS=50 git log --pretty="tformat:%h %<|(-10)%s" >actual &&
181
+ qz_to_tab_space <<EOF >expected &&
182
+$head1 message two Z
183
+$head2 message one Z
184
+$head3 add bar Z
185
+$head4 $(commit_msg) Z
186
+EOF
187
+ test_cmp expected actual
188
+'
189
+
190
test_expect_success 'left alignment formatting at the nth column. i18n.logOutputEncoding' '
191
git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %<|(40)%s" >actual &&
192
qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
@@ -308,6 +319,17 @@ EOF
319
test_cmp expected actual
320
'
321
322
+test_expect_success 'right alignment formatting at the nth column' '
323
+ COLUMNS=50 git log --pretty="tformat:%h %>|(-10)%s" >actual &&
324
+ qz_to_tab_space <<EOF >expected &&
325
+$head1 message two
326
+$head2 message one
327
+$head3 add bar
328
+$head4 $(commit_msg)
329
+EOF
330
+ test_cmp expected actual
331
+'
332
+
333
test_expect_success 'right alignment formatting at the nth column. i18n.logOutputEncoding' '
334
git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %>|(40)%s" >actual &&
335
qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
@@ -397,6 +419,17 @@ EOF
419
test_cmp expected actual
420
'
421
422
+test_expect_success 'center alignment formatting at the nth column' '
423
+ COLUMNS=70 git log --pretty="tformat:%h %><|(-30)%s" >actual &&
424
+ qz_to_tab_space <<EOF >expected &&
425
+$head1 message two Z
426
+$head2 message one Z
427
+$head3 add bar Z
428
+$head4 $(commit_msg) Z
429
+EOF
430
+ test_cmp expected actual
431
+'
432
+
433
test_expect_success 'center alignment formatting at the nth column. i18n.logOutputEncoding' '
434
git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %><|(40)%s" >actual &&
435
qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&