[PATCH] Add format-patch option --no-name-prefix.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This option can be used to generate a patch file
where file names are relative to the Git root
directory. Such a patch can then be applied with
the standard patch tool using option -p0.

Signed-off-by: Pascal Obry <pascal@xxxxxxxx>
---
 Documentation/git-format-patch.txt |    6 +++++-
 builtin-log.c                      |    7 ++++++-
 diff.c                             |   10 ++++++++--
 diff.h                             |    1 +
 4 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt
index 6fb9429..5a642ad 100644
--- a/Documentation/git-format-patch.txt
+++ b/Documentation/git-format-patch.txt
@@ -15,7 +15,7 @@ SYNOPSIS
                    [-n | --numbered | -N | --no-numbered]
                    [--start-number <n>] [--numbered-files]
                    [--in-reply-to=Message-Id] [--suffix=.<sfx>]
-                   [--ignore-if-in-upstream]
+                   [--ignore-if-in-upstream] [--no-name-prefix]
                    [--subject-prefix=Subject-Prefix]
 		   [ <since> | <revision range> ]
 
@@ -90,6 +90,10 @@ include::diff-options.txt[]
 	without the default first line of the commit appended.
 	Mutually exclusive with the --stdout option.
 
+--no-name-prefix::
+	Generate a patch file that can be applied with a patch(1) -p0
+	from the Git root directory.
+
 -k|--keep-subject::
 	Do not strip/add '[PATCH]' from the first line of the
 	commit log message.
diff --git a/builtin-log.c b/builtin-log.c
index cc3cc90..36582bd 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -599,6 +599,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 	int subject_prefix = 0;
 	int ignore_if_in_upstream = 0;
 	int thread = 0;
+	int no_name_prefix = 0;
 	const char *in_reply_to = NULL;
 	struct patch_ids ids;
 	char *add_signoff = NULL;
@@ -636,6 +637,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 		}
 		else if (!prefixcmp(argv[i], "--start-number="))
 			start_number = strtol(argv[i] + 15, NULL, 10);
+		else if (!prefixcmp(argv[i], "--no-name-prefix"))
+			no_name_prefix = 1;
 		else if (!strcmp(argv[i], "--numbered-files"))
 			numbered_files = 1;
 		else if (!strcmp(argv[i], "--start-number")) {
@@ -719,8 +722,10 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 		die ("unrecognized argument: %s", argv[1]);
 
 	if (!rev.diffopt.output_format)
-		rev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_SUMMARY | DIFF_FORMAT_PATCH;
+		rev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_SUMMARY | DIFF_FORMAT_PATCH | DIFF_FORMAT_NAME_PREFIX;
 
+	if (no_name_prefix)
+		rev.diffopt.output_format &= ~DIFF_FORMAT_NAME_PREFIX;
 	if (!DIFF_OPT_TST(&rev.diffopt, TEXT))
 		DIFF_OPT_SET(&rev.diffopt, BINARY);
 
diff --git a/diff.c b/diff.c
index e26584c..f07d9c0 100644
--- a/diff.c
+++ b/diff.c
@@ -1212,8 +1212,14 @@ static void builtin_diff(const char *name_a,
 	const char *set = diff_get_color_opt(o, DIFF_METAINFO);
 	const char *reset = diff_get_color_opt(o, DIFF_RESET);
 
-	a_one = quote_two("a/", name_a + (*name_a == '/'));
-	b_two = quote_two("b/", name_b + (*name_b == '/'));
+	if (o->output_format & DIFF_FORMAT_NAME_PREFIX) {
+		a_one = quote_two("a/", name_a + (*name_a == '/'));
+		b_two = quote_two("b/", name_b + (*name_b == '/'));
+	}
+	else {
+		a_one = quote_two("", name_a + (*name_a == '/'));
+		b_two = quote_two("", 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);
diff --git a/diff.h b/diff.h
index 7e8000a..86458a3 100644
--- a/diff.h
+++ b/diff.h
@@ -30,6 +30,7 @@ typedef void (*diff_format_fn_t)(struct diff_queue_struct *q,
 #define DIFF_FORMAT_SUMMARY	0x0008
 #define DIFF_FORMAT_PATCH	0x0010
 #define DIFF_FORMAT_SHORTSTAT	0x0020
+#define DIFF_FORMAT_NAME_PREFIX 0x0040
 
 /* These override all above */
 #define DIFF_FORMAT_NAME	0x0100
-- 
1.5.4.rc0.56.g6fbe

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux