From: Junio C Hamano <gitster@pobox.com>
To: Daniel Barkalow <barkalow@iabervon.org>
Cc: Chris Ortman <chrisortman@gmail.com>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>,
git@vger.kernel.org
Subject: [PATCH/RFC] Do not show "diff --git" metainfo with --no-prefix
Date: Tue, 15 Jan 2008 16:58:55 -0800 [thread overview]
Message-ID: <7v4pded1rk.fsf_-_@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <7vhched3kw.fsf@gitster.siamese.dyndns.org> (Junio C. Hamano's message of "Tue, 15 Jan 2008 16:19:43 -0800")
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 "diff --git" format.
This checks the prefix specified when generating diff and 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).
---
diff.c | 52 ++++++++++++++++++++++++++++++++++++++++------------
1 files changed, 40 insertions(+), 12 deletions(-)
diff --git a/diff.c b/diff.c
index b18c140..8126a74 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,30 +1258,46 @@ 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);
+ int is_git_diff = with_standard_prefix(o);
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);
+
+ if (!is_git_diff)
+ printf("%sIndex: %s%s\n", set, b_two, reset);
+ else
+ printf("%sdiff --git %s %s%s\n", set, a_one, b_two, reset);
+
if (lbl[0][0] == '/') {
/* /dev/null */
- printf("%snew file mode %06o%s\n", set, two->mode, reset);
- if (xfrm_msg && xfrm_msg[0])
- printf("%s%s%s\n", set, xfrm_msg, reset);
+ if (is_git_diff) {
+ printf("%snew file mode %06o%s\n",
+ set, two->mode, reset);
+ if (xfrm_msg && xfrm_msg[0])
+ printf("%s%s%s\n", set, xfrm_msg, reset);
+ }
}
else if (lbl[1][0] == '/') {
- printf("%sdeleted file mode %06o%s\n", set, one->mode, reset);
- if (xfrm_msg && xfrm_msg[0])
- printf("%s%s%s\n", set, xfrm_msg, reset);
+ if (is_git_diff) {
+ printf("%sdeleted file mode %06o%s\n",
+ set, one->mode, reset);
+ if (xfrm_msg && xfrm_msg[0])
+ printf("%s%s%s\n", set, xfrm_msg, reset);
+ }
}
else {
- if (one->mode != two->mode) {
- printf("%sold mode %06o%s\n", set, one->mode, reset);
- printf("%snew mode %06o%s\n", set, two->mode, reset);
+ if (is_git_diff) {
+ if (one->mode != two->mode) {
+ printf("%sold mode %06o%s\n",
+ set, one->mode, reset);
+ printf("%snew mode %06o%s\n",
+ set, two->mode, reset);
+ }
+ if (xfrm_msg && xfrm_msg[0])
+ printf("%s%s%s\n", set, xfrm_msg, reset);
}
- if (xfrm_msg && xfrm_msg[0])
- printf("%s%s%s\n", set, xfrm_msg, reset);
/*
* we do not run diff between different kind
* of objects.
next prev parent reply other threads:[~2008-01-16 1:00 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-15 13:59 [FEATURE REQUEST] git-svn format-patch Chris Ortman
2008-01-15 14:45 ` Johannes Schindelin
2008-01-15 15:58 ` Chris Ortman
2008-01-15 16:13 ` Johannes Schindelin
2008-01-15 16:23 ` Chris Ortman
2008-01-15 16:52 ` Johannes Schindelin
2008-01-15 17:07 ` Chris Ortman
2008-01-15 17:11 ` Johannes Schindelin
2008-01-15 19:04 ` Chris Ortman
2008-01-15 20:15 ` Jan Hudec
2008-01-16 6:41 ` Miles Bader
2008-01-16 6:54 ` Shawn O. Pearce
2008-01-15 17:10 ` Pascal Obry
2008-01-15 23:11 ` Daniel Barkalow
2008-01-16 0:19 ` Junio C Hamano
2008-01-16 0:58 ` Junio C Hamano [this message]
2008-01-16 1:37 ` [PATCH/RFC] Do not show "diff --git" metainfo with --no-prefix Johannes Schindelin
2008-01-16 1:46 ` Junio C Hamano
2008-01-16 1:53 ` Johannes Schindelin
2008-01-16 2:04 ` Daniel Barkalow
2008-01-16 2:15 ` Junio C Hamano
2008-01-16 2:08 ` [PATCH v2] " Junio C Hamano
2008-01-16 3:09 ` Linus Torvalds
2008-01-16 3:26 ` Linus Torvalds
2008-01-16 4:04 ` Daniel Barkalow
2008-01-16 4:22 ` Linus Torvalds
2008-01-16 20:19 ` Junio C Hamano
2008-01-16 20:39 ` Daniel Barkalow
2008-01-17 0:57 ` Junio C Hamano
2008-01-17 1:11 ` Johannes Schindelin
2008-01-17 1:19 ` Junio C Hamano
2008-01-17 1:54 ` Johannes Schindelin
2008-01-17 2:28 ` Junio C Hamano
2008-01-17 1:34 ` Junio C Hamano
2008-01-17 1:48 ` Johannes Schindelin
2008-01-17 2:42 ` Junio C Hamano
2008-01-17 2:45 ` Johannes Schindelin
2008-01-17 14:49 ` Jeff King
2008-01-17 15:03 ` Jeff King
2008-01-17 15:12 ` Johannes Schindelin
2008-01-17 15:18 ` Jeff King
2008-01-18 8:22 ` Junio C Hamano
2008-01-16 17:22 ` Junio C Hamano
2008-01-16 3:56 ` Daniel Barkalow
2008-01-19 9:36 ` Jan Hudec
2008-01-16 4:18 ` Junio C Hamano
2008-01-16 2:01 ` [FEATURE REQUEST] git-svn format-patch Chris Ortman
2008-01-15 20:14 ` Jean-Luc Herren
2008-01-15 20:30 ` Chris Ortman
2008-01-16 2:20 ` Daniel Barkalow
2008-03-11 17:38 ` Nigel Magnay
2008-03-11 19:22 ` Jan Hudec
2008-03-12 4:38 ` Daniel Barkalow
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=7v4pded1rk.fsf_-_@gitster.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=barkalow@iabervon.org \
--cc=chrisortman@gmail.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.
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).