summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosef Kufner <josef@kufner.cz>2015-09-12 01:25:11 +0200
committerJunio C Hamano <gitster@pobox.com>2015-09-14 13:02:47 -0700
commitc03fd1bd3a84a1923ef130f20ab0c01ec3d8c742 (patch)
tree3dac1ec6c496a1323ac927fe4fdb3747cb13de93
parent441c4a40173fe1ee8a5c0094e587dfc47e2a6460 (diff)
downloadgit-jk/graph-format-padding.tar.gz
pretty: pass graph width to pretty formatting for use in '%>|(N)'jk/graph-format-padding
Pass graph width to pretty formatting, to make N in '%>|(N)' include columns consumed by graph rendered when --graph option is in use. For example, in the output of git log --all --graph --pretty='format: [%>|(20)%h] %ar%d' this change will make all commit hashes align at 20th column from the edge of the terminal, not from the edge of the graph. Signed-off-by: Josef Kufner <josef@kufner.cz> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--commit.h1
-rw-r--r--graph.c7
-rw-r--r--graph.h5
-rw-r--r--log-tree.c2
-rw-r--r--pretty.c1
-rwxr-xr-xt/t4205-log-pretty-formats.sh24
6 files changed, 40 insertions, 0 deletions
diff --git a/commit.h b/commit.h
index bc68ccbe69..ec6ecf8fff 100644
--- a/commit.h
+++ b/commit.h
@@ -156,6 +156,7 @@ struct pretty_print_context {
* should not be counted on by callers.
*/
struct string_list in_body_headers;
+ int graph_width;
};
struct userformat_want {
diff --git a/graph.c b/graph.c
index c25a09a8fd..48024113a6 100644
--- a/graph.c
+++ b/graph.c
@@ -671,6 +671,13 @@ static void graph_output_padding_line(struct git_graph *graph,
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)
{
/*
diff --git a/graph.h b/graph.h
index 0be62bd8b1..3f48c19b62 100644
--- a/graph.h
+++ b/graph.h
@@ -68,6 +68,11 @@ 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
*/
diff --git a/log-tree.c b/log-tree.c
index 7f0890e4ac..a456ed015b 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -612,6 +612,8 @@ void show_log(struct rev_info *opt)
ctx.output_encoding = get_log_output_encoding();
if (opt->from_ident.mail_begin && opt->from_ident.name_begin)
ctx.from_ident = &opt->from_ident;
+ if (opt->graph)
+ ctx.graph_width = graph_width(opt->graph);
pretty_print_commit(&ctx, commit, &msgbuf);
if (opt->add_signoff)
diff --git a/pretty.c b/pretty.c
index 9d34d02db1..bf8a0a9a80 100644
--- a/pretty.c
+++ b/pretty.c
@@ -1296,6 +1296,7 @@ static size_t format_and_pad_commit(struct strbuf *sb, /* in UTF-8 */
if (!start)
start = sb->buf;
occupied = utf8_strnwidth(start, -1, 1);
+ occupied += c->pretty_ctx->graph_width;
padding = (-padding) - occupied;
}
while (1) {
diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh
index 7398605e7b..d75cdbbf9c 100755
--- a/t/t4205-log-pretty-formats.sh
+++ b/t/t4205-log-pretty-formats.sh
@@ -319,6 +319,19 @@ EOF
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' '
git log --pretty="tformat:%>(1)%s" >actual &&
cat <<EOF >expected &&
@@ -330,6 +343,17 @@ EOF
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' '
git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%>(1)%s" >actual &&
cat <<EOF | iconv -f utf-8 -t $test_encoding >expected &&