From: Josef Kufner <josef@kufner.cz>
To: gitster@pobox.com
Cc: git@vger.kernel.org, josef@kufner.cz, sunshine@sunshineco.com
Subject: [PATCH 1/3] pretty: Pass graph width to pretty formatting for use in '%>|(N)'
Date: Sat, 12 Sep 2015 01:25:11 +0200 [thread overview]
Message-ID: <1442013913-2970-1-git-send-email-josef@kufner.cz> (raw)
In-Reply-To: <xmqqk2rwzlhi.fsf@gitster.mtv.corp.google.com>
Pass graph width to pretty formatting, so N in '%>|(N)' includes columns
consumed by graph rendered when --graph option is in use.
Example:
git log --all --graph --pretty='format: [%>|(20)%h] %ar%d'
All commit hashes should be aligned at 20th column from edge of the
terminal, not from the edge of the graph.
Signed-off-by: Josef Kufner <josef@kufner.cz>
---
commit.h | 1 +
graph.c | 7 +++++++
graph.h | 5 +++++
log-tree.c | 2 ++
pretty.c | 1 +
5 files changed, 16 insertions(+)
diff --git a/commit.h b/commit.h
index 5d58be0..0a9a707 100644
--- a/commit.h
+++ b/commit.h
@@ -160,6 +160,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 c25a09a..4802411 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 0be62bd..3f48c19 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 7b1b57a..08fd5b6 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -686,6 +686,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 151c2ae..f1cf9e2 100644
--- a/pretty.c
+++ b/pretty.c
@@ -1297,6 +1297,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) {
--
2.5.1
next parent reply other threads:[~2015-09-11 23:25 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <xmqqk2rwzlhi.fsf@gitster.mtv.corp.google.com>
2015-09-11 23:25 ` Josef Kufner [this message]
2015-09-11 23:25 ` [PATCH 2/3] Add tests for "pretty: Pass graph width to pretty formatting for use in '%>|(N)'" Josef Kufner
2015-09-11 23:25 ` [PATCH 3/3] t4205: remove unnecessary use of qz_to_tab_space Josef Kufner
2015-09-21 19:40 ` [PATCH 1/3] pretty: Pass graph width to pretty formatting for use in '%>|(N)' Junio C Hamano
2015-12-22 17:03 ` Duy Nguyen
2015-12-22 22:54 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1442013913-2970-1-git-send-email-josef@kufner.cz \
--to=josef@kufner.cz \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=sunshine@sunshineco.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).