From: Stefan Beller <sbeller@google.com>
To: git@vger.kernel.org
Cc: Stefan Beller <sbeller@google.com>
Subject: [RFC PATCH 7/7] diff/am: enhance diff format to use */~ for moved lines
Date: Fri, 3 Aug 2018 18:53:17 -0700 [thread overview]
Message-ID: <20180804015317.182683-8-sbeller@google.com> (raw)
In-Reply-To: <20180804015317.182683-1-sbeller@google.com>
Try it out via
./git-format-patch --mark-moved 15ef69314d^..15ef69314d
to see if you like it.
This separates the coloring decision from the detection of moved lines.
When giving --mark-moved, move detection is still performed and the output
markers are adjusted to */~ for new and old code.
git-apply and git-am will also accept these patches by rewriting those
signs back to +/-.
Signed-off-by: Stefan Beller <sbeller@google.com>
---
apply.c | 12 ++++++++++++
diff.c | 21 +++++++++++++++++++++
diff.h | 5 ++++-
3 files changed, 37 insertions(+), 1 deletion(-)
diff --git a/apply.c b/apply.c
index 23a0f25ded8..cc42a4fa02a 100644
--- a/apply.c
+++ b/apply.c
@@ -2900,6 +2900,12 @@ static int apply_one_fragment(struct apply_state *state,
ws_blank_line(patch + 1, plen, ws_rule))
is_blank_context = 1;
/* fallthrough */
+ case '~':
+ /*
+ * For now ignore moved line indicators and apply
+ * as a regular old line
+ */
+ /* fallthrough */
case '-':
memcpy(old, patch + 1, plen);
add_line_info(&preimage, old, plen,
@@ -2908,6 +2914,12 @@ static int apply_one_fragment(struct apply_state *state,
if (first == '-')
break;
/* fallthrough */
+ case '*':
+ /*
+ * For now ignore moved line indicators and apply
+ * as a regular new line
+ */
+ /* fallthrough */
case '+':
/* --no-add does not add new lines */
if (first == '+' && state->no_add)
diff --git a/diff.c b/diff.c
index 56bab011df7..8e39e77229f 100644
--- a/diff.c
+++ b/diff.c
@@ -1043,6 +1043,9 @@ static const char *determine_line_color(struct diff_options *o,
const int off = (eds->s == DIFF_SYMBOL_PLUS) ?
DIFF_FILE_NEW_MOVED - DIFF_FILE_OLD_MOVED : 0;
+ if (!o->color_moved)
+ goto default_color;
+
switch (flags & (DIFF_SYMBOL_MOVED_LINE |
DIFF_SYMBOL_MOVED_LINE_ALT |
DIFF_SYMBOL_MOVED_LINE_UNINTERESTING)) {
@@ -1063,6 +1066,7 @@ static const char *determine_line_color(struct diff_options *o,
set = diff_get_color_opt(o, DIFF_FILE_OLD_MOVED + off);
break;
default:
+default_color:
set = (eds->s == DIFF_SYMBOL_PLUS) ?
diff_get_color_opt(o, DIFF_FILE_NEW):
diff_get_color_opt(o, DIFF_FILE_OLD);
@@ -1152,6 +1156,9 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
first = o->output_indicators[OI_NEW] ?
o->output_indicators[OI_NEW] : "+";
+ if (o->output_indicators[OI_MOVED_NEW] &&
+ (flags & DIFF_SYMBOL_MOVED_LINE))
+ first = "*";
emit_line_ws_markup(o, set_sign, set, reset, first, line, len,
flags & DIFF_SYMBOL_CONTENT_WS_MASK,
flags & DIFF_SYMBOL_CONTENT_BLANK_LINE_EOF);
@@ -1176,6 +1183,9 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
}
first = o->output_indicators[OI_OLD] ?
o->output_indicators[OI_OLD] : "-";
+ if (o->output_indicators[OI_MOVED_NEW] &&
+ (flags & DIFF_SYMBOL_MOVED_LINE))
+ first = "~";
emit_line_ws_markup(o, set_sign, set, reset, first, line, len,
flags & DIFF_SYMBOL_CONTENT_WS_MASK, 0);
break;
@@ -4795,6 +4805,7 @@ int diff_opt_parse(struct diff_options *options,
else if (!strcmp(arg, "--no-color"))
options->use_color = 0;
else if (!strcmp(arg, "--color-moved")) {
+ options->color_moved = 1;
if (diff_color_moved_default)
options->markup_moved = diff_color_moved_default;
if (options->markup_moved == COLOR_MOVED_NO)
@@ -4806,6 +4817,16 @@ int diff_opt_parse(struct diff_options *options,
if (cm < 0)
die("bad --color-moved argument: %s", arg);
options->markup_moved = cm;
+ options->color_moved = 1;
+ } else if (skip_prefix(arg, "--mark-moved", &arg)) {
+ /*
+ * NEEDSWORK:
+ * Once merged with 51da15eb230 (diff.c: add a blocks mode for
+ * moved code detection, 2018-07-16), make it COLOR_MOVED_BLOCKS
+ */
+ options->markup_moved = COLOR_MOVED_PLAIN;
+ options->output_indicators[OI_MOVED_NEW] = "*";
+ options->output_indicators[OI_MOVED_OLD] = "~";
} else if (skip_to_optional_arg_default(arg, "--color-words", &options->word_regex, NULL)) {
options->use_color = 1;
options->word_diff = DIFF_WORDS_COLOR;
diff --git a/diff.h b/diff.h
index 0dd1651dda4..0058602c849 100644
--- a/diff.h
+++ b/diff.h
@@ -197,7 +197,9 @@ struct diff_options {
#define OI_NEW 0
#define OI_OLD 1
#define OI_CONTEXT 2
- const char *output_indicators[3];
+#define OI_MOVED_NEW 3
+#define OI_MOVED_OLD 4
+ const char *output_indicators[5];
struct pathspec pathspec;
pathchange_fn_t pathchange;
@@ -211,6 +213,7 @@ struct diff_options {
int diff_path_counter;
+ unsigned color_moved : 1;
struct emitted_diff_symbols *emitted_symbols;
enum {
COLOR_MOVED_NO = 0,
--
2.18.0.597.ga71716f1ad-goog
next prev parent reply other threads:[~2018-08-04 1:53 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-04 1:53 [PATCH 0/7] improve range-diffs coloring and [RFC] move detection Stefan Beller
2018-08-04 1:53 ` [PATCH 1/7] diff.c: emit_line_0 to take string instead of first sign Stefan Beller
2018-08-04 1:53 ` [PATCH 2/7] diff.c: add --output-indicator-{new, old, context} Stefan Beller
2018-08-04 1:53 ` [PATCH 3/7] range-diff: make use of different output indicators Stefan Beller
2018-08-04 1:53 ` [PATCH 4/7] range-diff: indent special lines as context Stefan Beller
2018-08-04 1:53 ` [PATCH 5/7] diff.c: rename color_moved to markup_moved Stefan Beller
2018-08-04 1:53 ` [PATCH 6/7] diff.c: factor determine_line_color out of emit_diff_symbol_from_struct Stefan Beller
2018-08-04 1:53 ` Stefan Beller [this message]
2018-08-04 17:15 ` [RFC PATCH 7/7] diff/am: enhance diff format to use */~ for moved lines Junio C Hamano
2018-08-06 6:07 ` Stefan Beller
2018-08-04 16:57 ` [PATCH 0/7] improve range-diffs coloring and [RFC] move detection Junio C Hamano
2018-08-06 6:01 ` Stefan Beller
2018-08-06 20:18 ` 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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180804015317.182683-8-sbeller@google.com \
--to=sbeller@google.com \
--cc=git@vger.kernel.org \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).