Merge branch 'nd/graph-width-padded'
"log --graph --format=" learned that "%>|(N)" specifies the width relative to the terminal's left edge, not relative to the area to draw text that is to the right of the ancestry-graph section. It also now accepts negative N that means the column limit is relative to the right border. * nd/graph-width-padded: pretty.c: support <direction>|(<negative number>) forms pretty: pass graph width to pretty formatting for use in '%>|(N)'
This commit is contained in:
commit
f2140c3890
1
commit.h
1
commit.h
@ -167,6 +167,7 @@ struct pretty_print_context {
|
|||||||
* should not be counted on by callers.
|
* should not be counted on by callers.
|
||||||
*/
|
*/
|
||||||
struct string_list in_body_headers;
|
struct string_list in_body_headers;
|
||||||
|
int graph_width;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct userformat_want {
|
struct userformat_want {
|
||||||
|
7
graph.c
7
graph.c
@ -669,6 +669,13 @@ static void graph_output_padding_line(struct git_graph *graph,
|
|||||||
graph_pad_horizontally(graph, sb, graph->num_new_columns * 2);
|
graph_pad_horizontally(graph, sb, graph->num_new_columns * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int graph_width(struct git_graph *graph)
|
||||||
|
{
|
||||||
|
return graph->width;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void graph_output_skip_line(struct git_graph *graph, struct strbuf *sb)
|
static void graph_output_skip_line(struct git_graph *graph, struct strbuf *sb)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
5
graph.h
5
graph.h
@ -67,6 +67,11 @@ int graph_is_commit_finished(struct git_graph const *graph);
|
|||||||
int graph_next_line(struct git_graph *graph, struct strbuf *sb);
|
int graph_next_line(struct git_graph *graph, struct strbuf *sb);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return current width of the graph in on-screen characters.
|
||||||
|
*/
|
||||||
|
int graph_width(struct git_graph *graph);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* graph_show_*: helper functions for printing to stdout
|
* graph_show_*: helper functions for printing to stdout
|
||||||
*/
|
*/
|
||||||
|
@ -687,6 +687,8 @@ void show_log(struct rev_info *opt)
|
|||||||
ctx.output_encoding = get_log_output_encoding();
|
ctx.output_encoding = get_log_output_encoding();
|
||||||
if (opt->from_ident.mail_begin && opt->from_ident.name_begin)
|
if (opt->from_ident.mail_begin && opt->from_ident.name_begin)
|
||||||
ctx.from_ident = &opt->from_ident;
|
ctx.from_ident = &opt->from_ident;
|
||||||
|
if (opt->graph)
|
||||||
|
ctx.graph_width = graph_width(opt->graph);
|
||||||
pretty_print_commit(&ctx, commit, &msgbuf);
|
pretty_print_commit(&ctx, commit, &msgbuf);
|
||||||
|
|
||||||
if (opt->add_signoff)
|
if (opt->add_signoff)
|
||||||
|
9
pretty.c
9
pretty.c
@ -1024,9 +1024,15 @@ static size_t parse_padding_placeholder(struct strbuf *sb,
|
|||||||
int width;
|
int width;
|
||||||
if (!end || end == start)
|
if (!end || end == start)
|
||||||
return 0;
|
return 0;
|
||||||
width = strtoul(start, &next, 10);
|
width = strtol(start, &next, 10);
|
||||||
if (next == start || width == 0)
|
if (next == start || width == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
if (width < 0) {
|
||||||
|
if (to_column)
|
||||||
|
width += term_columns();
|
||||||
|
if (width < 0)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
c->padding = to_column ? -width : width;
|
c->padding = to_column ? -width : width;
|
||||||
c->flush_type = flush_type;
|
c->flush_type = flush_type;
|
||||||
|
|
||||||
@ -1301,6 +1307,7 @@ static size_t format_and_pad_commit(struct strbuf *sb, /* in UTF-8 */
|
|||||||
if (!start)
|
if (!start)
|
||||||
start = sb->buf;
|
start = sb->buf;
|
||||||
occupied = utf8_strnwidth(start, -1, 1);
|
occupied = utf8_strnwidth(start, -1, 1);
|
||||||
|
occupied += c->pretty_ctx->graph_width;
|
||||||
padding = (-padding) - occupied;
|
padding = (-padding) - occupied;
|
||||||
}
|
}
|
||||||
while (1) {
|
while (1) {
|
||||||
|
@ -176,6 +176,17 @@ EOF
|
|||||||
test_cmp expected actual
|
test_cmp expected actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'left alignment formatting at the nth column' '
|
||||||
|
COLUMNS=50 git log --pretty="tformat:%h %<|(-10)%s" >actual &&
|
||||||
|
qz_to_tab_space <<EOF >expected &&
|
||||||
|
$head1 message two Z
|
||||||
|
$head2 message one Z
|
||||||
|
$head3 add bar Z
|
||||||
|
$head4 $(commit_msg) Z
|
||||||
|
EOF
|
||||||
|
test_cmp expected actual
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'left alignment formatting at the nth column. i18n.logOutputEncoding' '
|
test_expect_success 'left alignment formatting at the nth column. i18n.logOutputEncoding' '
|
||||||
git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %<|(40)%s" >actual &&
|
git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %<|(40)%s" >actual &&
|
||||||
qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
|
qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
|
||||||
@ -308,6 +319,17 @@ EOF
|
|||||||
test_cmp expected actual
|
test_cmp expected actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'right alignment formatting at the nth column' '
|
||||||
|
COLUMNS=50 git log --pretty="tformat:%h %>|(-10)%s" >actual &&
|
||||||
|
qz_to_tab_space <<EOF >expected &&
|
||||||
|
$head1 message two
|
||||||
|
$head2 message one
|
||||||
|
$head3 add bar
|
||||||
|
$head4 $(commit_msg)
|
||||||
|
EOF
|
||||||
|
test_cmp expected actual
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'right alignment formatting at the nth column. i18n.logOutputEncoding' '
|
test_expect_success 'right alignment formatting at the nth column. i18n.logOutputEncoding' '
|
||||||
git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %>|(40)%s" >actual &&
|
git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %>|(40)%s" >actual &&
|
||||||
qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
|
qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
|
||||||
@ -319,6 +341,19 @@ EOF
|
|||||||
test_cmp expected actual
|
test_cmp expected actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
# Note: Space between 'message' and 'two' should be in the same column
|
||||||
|
# as in previous test.
|
||||||
|
test_expect_success 'right alignment formatting at the nth column with --graph. i18n.logOutputEncoding' '
|
||||||
|
git -c i18n.logOutputEncoding=$test_encoding log --graph --pretty="tformat:%h %>|(40)%s" >actual &&
|
||||||
|
iconv -f utf-8 -t $test_encoding >expected <<EOF&&
|
||||||
|
* $head1 message two
|
||||||
|
* $head2 message one
|
||||||
|
* $head3 add bar
|
||||||
|
* $head4 $(commit_msg)
|
||||||
|
EOF
|
||||||
|
test_cmp expected actual
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'right alignment formatting with no padding' '
|
test_expect_success 'right alignment formatting with no padding' '
|
||||||
git log --pretty="tformat:%>(1)%s" >actual &&
|
git log --pretty="tformat:%>(1)%s" >actual &&
|
||||||
cat <<EOF >expected &&
|
cat <<EOF >expected &&
|
||||||
@ -330,6 +365,17 @@ EOF
|
|||||||
test_cmp expected actual
|
test_cmp expected actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'right alignment formatting with no padding and with --graph' '
|
||||||
|
git log --graph --pretty="tformat:%>(1)%s" >actual &&
|
||||||
|
cat <<EOF >expected &&
|
||||||
|
* message two
|
||||||
|
* message one
|
||||||
|
* add bar
|
||||||
|
* $(commit_msg)
|
||||||
|
EOF
|
||||||
|
test_cmp expected actual
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'right alignment formatting with no padding. i18n.logOutputEncoding' '
|
test_expect_success 'right alignment formatting with no padding. i18n.logOutputEncoding' '
|
||||||
git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%>(1)%s" >actual &&
|
git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%>(1)%s" >actual &&
|
||||||
cat <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
|
cat <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
|
||||||
@ -373,6 +419,17 @@ EOF
|
|||||||
test_cmp expected actual
|
test_cmp expected actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'center alignment formatting at the nth column' '
|
||||||
|
COLUMNS=70 git log --pretty="tformat:%h %><|(-30)%s" >actual &&
|
||||||
|
qz_to_tab_space <<EOF >expected &&
|
||||||
|
$head1 message two Z
|
||||||
|
$head2 message one Z
|
||||||
|
$head3 add bar Z
|
||||||
|
$head4 $(commit_msg) Z
|
||||||
|
EOF
|
||||||
|
test_cmp expected actual
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'center alignment formatting at the nth column. i18n.logOutputEncoding' '
|
test_expect_success 'center alignment formatting at the nth column. i18n.logOutputEncoding' '
|
||||||
git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %><|(40)%s" >actual &&
|
git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %><|(40)%s" >actual &&
|
||||||
qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
|
qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
|
||||||
|
Loading…
Reference in New Issue
Block a user