From: Jacob Keller <jacob.e.keller@intel.com>
To: git@vger.kernel.org
Cc: Jacob Keller <jacob.keller@gmail.com>
Subject: [PATCH v3 1/2] diff: add --line-prefix option for passing in a prefix
Date: Wed, 10 Aug 2016 14:17:09 -0700 [thread overview]
Message-ID: <20160810211710.23173-1-jacob.e.keller@intel.com> (raw)
From: Jacob Keller <jacob.keller@gmail.com>
This will be used by a future patch which implements a diff mode for
submodule display. Without this, the diff output would incorrectly
display when using both -p and --graph during a git-log.
Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
---
As suggested by Junio, I implemented --line-prefix to enable the graph
display correctly. This works by a neat trick of adding to the msgbuf,
so no code needs to be altered. I presumed that the line prefix should
go *after* the graphs own prefix.
Documentation/diff-options.txt | 3 +++
diff.c | 12 +++++++++++-
diff.h | 1 +
3 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
index 705a87394200..e7b729f3644f 100644
--- a/Documentation/diff-options.txt
+++ b/Documentation/diff-options.txt
@@ -569,5 +569,8 @@ endif::git-format-patch[]
--no-prefix::
Do not show any source or destination prefix.
+--line-prefix=<prefix>::
+ Prepend an additional prefix to every diff output line.
+
For more detailed explanation on these common options, see also
linkgit:gitdiffcore[7].
diff --git a/diff.c b/diff.c
index b43d3dd2ecb7..6fe5c6d084a3 100644
--- a/diff.c
+++ b/diff.c
@@ -1167,10 +1167,16 @@ const char *diff_get_color(int diff_use_color, enum color_diff ix)
const char *diff_line_prefix(struct diff_options *opt)
{
struct strbuf *msgbuf;
+
if (!opt->output_prefix)
- return "";
+ if (opt->line_prefix)
+ return opt->line_prefix;
+ else
+ return "";
msgbuf = opt->output_prefix(opt, opt->output_prefix_data);
+ if (opt->line_prefix)
+ strbuf_addstr(msgbuf, opt->line_prefix);
return msgbuf->buf;
}
@@ -3966,6 +3972,10 @@ int diff_opt_parse(struct diff_options *options,
options->a_prefix = optarg;
return argcount;
}
+ else if ((argcount = parse_long_opt("line-prefix", av, &optarg))) {
+ options->line_prefix = optarg;
+ return argcount;
+ }
else if ((argcount = parse_long_opt("dst-prefix", av, &optarg))) {
options->b_prefix = optarg;
return argcount;
diff --git a/diff.h b/diff.h
index 125447be09eb..6a91a1139686 100644
--- a/diff.h
+++ b/diff.h
@@ -115,6 +115,7 @@ struct diff_options {
const char *pickaxe;
const char *single_follow;
const char *a_prefix, *b_prefix;
+ const char *line_prefix;
unsigned flags;
unsigned touched_flags;
--
2.9.2.872.g0b694e0.dirty
next reply other threads:[~2016-08-10 21:17 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-10 21:17 Jacob Keller [this message]
2016-08-10 21:17 ` [PATCH v3 2/2] diff: add SUBMODULE_DIFF format to display submodule diff Jacob Keller
2016-08-10 22:05 ` Junio C Hamano
2016-08-10 22:45 ` Jacob Keller
2016-08-10 21:58 ` [PATCH v3 1/2] diff: add --line-prefix option for passing in a prefix Junio C Hamano
2016-08-10 22:42 ` Jacob Keller
2016-08-10 22:53 ` Jacob Keller
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=20160810211710.23173-1-jacob.e.keller@intel.com \
--to=jacob.e.keller@intel.com \
--cc=git@vger.kernel.org \
--cc=jacob.keller@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.