git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 2/3] diff.c: separate "prefix" from RELATIVE_NAME (aka --relative)
Date: Sun, 26 Jun 2016 19:16:15 +0200	[thread overview]
Message-ID: <20160626171616.27948-3-pclouds@gmail.com> (raw)
In-Reply-To: <20160626171616.27948-1-pclouds@gmail.com>

So far "prefix" and "prefix_length" in struct diff_options are tied to
RELATIVE_NAME flag, making it tricky to add new features that need the
prefix.

This change essentially follows the foot steps in cd676a5 (diff
--relative: output paths as relative to the current subdirectory -
2008-02-12) and makes sure that the prefix stripping/filtering only
happens when RELATIVE_NAME flag is set. The stripping is much simpler
because all stripping now goes through strip_prefix(). So the patch is
mostly about filtering.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 diff.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/diff.c b/diff.c
index b4949a2..bd5d190 100644
--- a/diff.c
+++ b/diff.c
@@ -3153,7 +3153,7 @@ static void strip_prefix(struct diff_options *opt,
 {
 	int prefix_length = opt->prefix_length;
 
-	if (!prefix_length)
+	if (!prefix_length || !DIFF_OPT_TST(opt, RELATIVE_NAME))
 		return;
 
 	/* Strip the prefix but do not molest /dev/null and absolute paths */
@@ -3335,8 +3335,6 @@ void diff_setup_done(struct diff_options *options)
 	if (DIFF_OPT_TST(options, FIND_COPIES_HARDER))
 		options->detect_rename = DIFF_DETECT_COPY;
 
-	if (!DIFF_OPT_TST(options, RELATIVE_NAME))
-		options->prefix = NULL;
 	if (options->prefix)
 		options->prefix_length = strlen(options->prefix);
 	else
@@ -4976,7 +4974,8 @@ void diff_addremove(struct diff_options *options,
 		addremove = (addremove == '+' ? '-' :
 			     addremove == '-' ? '+' : addremove);
 
-	if (options->prefix &&
+	if (DIFF_OPT_TST(options, RELATIVE_NAME) &&
+	    options->prefix &&
 	    strncmp(concatpath, options->prefix, options->prefix_length))
 		return;
 
@@ -5021,7 +5020,8 @@ void diff_change(struct diff_options *options,
 			new_dirty_submodule = tmp;
 	}
 
-	if (options->prefix &&
+	if (DIFF_OPT_TST(options, RELATIVE_NAME) &&
+	    options->prefix &&
 	    strncmp(concatpath, options->prefix, options->prefix_length))
 		return;
 
@@ -5048,7 +5048,8 @@ struct diff_filepair *diff_unmerge(struct diff_options *options, const char *pat
 	struct diff_filepair *pair;
 	struct diff_filespec *one, *two;
 
-	if (options->prefix &&
+	if (DIFF_OPT_TST(options, RELATIVE_NAME) &&
+	    options->prefix &&
 	    strncmp(path, options->prefix, options->prefix_length))
 		return NULL;
 
-- 
2.8.2.531.gd073806


  parent reply	other threads:[~2016-06-26 17:16 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-26 17:16 [PATCH 0/3] diff: add --relative-names Nguyễn Thái Ngọc Duy
2016-06-26 17:16 ` [PATCH 1/3] diff.c: refactor strip_prefix() Nguyễn Thái Ngọc Duy
2016-06-26 17:16 ` Nguyễn Thái Ngọc Duy [this message]
2016-06-26 17:16 ` [PATCH/RFC 3/3] diff.c: add --relative-names to be used with --name-only Nguyễn Thái Ngọc Duy
2016-06-26 23:05   ` Eric Sunshine
2016-06-27 19:24   ` Jeff King
2016-06-27 19:33     ` Duy Nguyen
2016-06-27 19:35       ` Jeff King
2016-06-27 19:39         ` Duy Nguyen

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=20160626171616.27948-3-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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).