[PATCH v2] Do not show "diff --git" metainfo with --no-prefix

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Daniel Barkalow <barkalow@...>
Cc: Chris Ortman <chrisortman@...>, Johannes Schindelin <Johannes.Schindelin@...>, <git@...>
Date: Tuesday, January 15, 2008 - 10:08 pm

If a non-standard prefix is used by --no-prefix, --src-prefix,
or --dst-prefix options, the resulting diff becomes something
git-apply would not grok.  In such a case, we should not trigger
the more strict check git-apply does for patches in "diff --git"
format.

This checks the prefix specified when generating diff.  If src
and dst prefix are not one-level of directory name followed by a
slash (i.e. the standard "diff --git a/foo b/foo" is fine, a
custom "diff --git l/foo k/foo" is Ok, but "diff --git foo foo"
is NOT Ok), we are generating with a custom prefix that would
fail git-apply's stricter check.  In such a case, we do not say
"diff --git" but just say "diff" in the header.

Metainformation (e.g. "index", "similarity", etc.) lines will
safely be ignored by patch and git-apply (even when the latter
parses a non-git diff output), so this patch does not bother
stripping them away.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---

 * I am signing this off, but I am not thinking straight today
   and did not test it, so I will not commit it for now and
   leave it in the list archive, to be commented on.

 diff.c |   17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/diff.c b/diff.c
index b18c140..8321492 100644
--- a/diff.c
+++ b/diff.c
@@ -1233,6 +1233,18 @@ static const char *diff_funcname_pattern(struct diff_filespec *one)
 	return NULL;
 }
 
+static int with_standard_prefix(struct diff_options *o)
+{
+	const char *slash;
+	slash = strchr(o->a_prefix, '/');
+	if (!slash || slash[1])
+		return 0;
+	slash = strchr(o->b_prefix, '/');
+	if (!slash || slash[1])
+		return 0;
+	return 1;
+}
+
 static void builtin_diff(const char *name_a,
 			 const char *name_b,
 			 struct diff_filespec *one,
@@ -1246,12 +1258,15 @@ static void builtin_diff(const char *name_a,
 	char *a_one, *b_two;
 	const char *set = diff_get_color_opt(o, DIFF_METAINFO);
 	const char *reset = diff_get_color_opt(o, DIFF_RESET);
+	const char *gitdiff;
+
+	gitdiff = with_standard_prefix(o) ? " --git" : "";
 
 	a_one = quote_two(o->a_prefix, name_a + (*name_a == '/'));
 	b_two = quote_two(o->b_prefix, name_b + (*name_b == '/'));
 	lbl[0] = DIFF_FILE_VALID(one) ? a_one : "/dev/null";
 	lbl[1] = DIFF_FILE_VALID(two) ? b_two : "/dev/null";
-	printf("%sdiff --git %s %s%s\n", set, a_one, b_two, reset);
+	printf("%sdiff%s %s %s%s\n", set, gitdiff, a_one, b_two, reset);
 	if (lbl[0][0] == '/') {
 		/* /dev/null */
 		printf("%snew file mode %06o%s\n", set, two->mode, reset);
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[FEATURE REQUEST] git-svn format-patch, Chris Ortman, (Tue Jan 15, 9:59 am)
Re: [FEATURE REQUEST] git-svn format-patch, Jean-Luc Herren, (Tue Jan 15, 4:14 pm)
Re: [FEATURE REQUEST] git-svn format-patch, Chris Ortman, (Tue Jan 15, 4:30 pm)
Re: [FEATURE REQUEST] git-svn format-patch, Daniel Barkalow, (Tue Jan 15, 10:20 pm)
Re: [FEATURE REQUEST] git-svn format-patch, Nigel Magnay, (Tue Mar 11, 1:38 pm)
Re: [FEATURE REQUEST] git-svn format-patch, Daniel Barkalow, (Wed Mar 12, 12:38 am)
Re: [FEATURE REQUEST] git-svn format-patch, Jan Hudec, (Tue Mar 11, 3:22 pm)
Re: [FEATURE REQUEST] git-svn format-patch, Johannes Schindelin, (Tue Jan 15, 10:45 am)
Re: [FEATURE REQUEST] git-svn format-patch, Chris Ortman, (Tue Jan 15, 11:58 am)
Re: [FEATURE REQUEST] git-svn format-patch, Daniel Barkalow, (Tue Jan 15, 7:11 pm)
Re: [FEATURE REQUEST] git-svn format-patch, Chris Ortman, (Tue Jan 15, 10:01 pm)
Re: [FEATURE REQUEST] git-svn format-patch, Junio C Hamano, (Tue Jan 15, 8:19 pm)
[PATCH v2] Do not show "diff --git" metainfo with --no-prefix, Junio C Hamano, (Tue Jan 15, 10:08 pm)
Re: [PATCH v2] Do not show "diff --git" metainfo with --no-p..., Johannes Schindelin, (Wed Jan 16, 9:11 pm)
Re: [PATCH v2] Do not show "diff --git" metainfo with --no-p..., Johannes Schindelin, (Wed Jan 16, 9:48 pm)
Re: [PATCH v2] Do not show "diff --git" metainfo with --no-p..., Johannes Schindelin, (Thu Jan 17, 11:12 am)
Re: [PATCH v2] Do not show "diff --git" metainfo with --no-p..., Johannes Schindelin, (Wed Jan 16, 10:45 pm)
Re: [PATCH v2] Do not show "diff --git" metainfo with --no-p..., Johannes Schindelin, (Wed Jan 16, 9:54 pm)
Re: [PATCH/RFC] Do not show "diff --git" metainfo with --no-..., Johannes Schindelin, (Tue Jan 15, 9:37 pm)
Re: [PATCH/RFC] Do not show "diff --git" metainfo with --no-..., Johannes Schindelin, (Tue Jan 15, 9:53 pm)
Re: [FEATURE REQUEST] git-svn format-patch, Pascal Obry, (Tue Jan 15, 1:10 pm)
Re: [FEATURE REQUEST] git-svn format-patch, Johannes Schindelin, (Tue Jan 15, 12:13 pm)
Re: [FEATURE REQUEST] git-svn format-patch, Chris Ortman, (Tue Jan 15, 12:23 pm)
Re: [FEATURE REQUEST] git-svn format-patch, Johannes Schindelin, (Tue Jan 15, 12:52 pm)
Re: [FEATURE REQUEST] git-svn format-patch, Chris Ortman, (Tue Jan 15, 1:07 pm)
Re: [FEATURE REQUEST] git-svn format-patch, Johannes Schindelin, (Tue Jan 15, 1:11 pm)
Re: [FEATURE REQUEST] git-svn format-patch, Chris Ortman, (Tue Jan 15, 3:04 pm)
Re: [FEATURE REQUEST] git-svn format-patch, Jan Hudec, (Tue Jan 15, 4:15 pm)
Re: [FEATURE REQUEST] git-svn format-patch, Miles Bader, (Wed Jan 16, 2:41 am)
Re: [FEATURE REQUEST] git-svn format-patch, Shawn O. Pearce, (Wed Jan 16, 2:54 am)