git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Make apply accept the -pNUM option like patch does.

From
Daniel Barkalow <barkalow@iabervon.org>
Date
Jan 31, 2006, 05:36 UTC
Message-ID
<Pine.LNX.4.64.0601310015460.25300@iabervon.org>
In-Reply-To
<43DE1DB7.20909@f2s.com>
This only applies to traditional diffs, not to git diffs.
Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>

--- On Mon, 30 Jan 2006, Ian Molton wrote:

> Hi.
> 
> is there any reason why git insists diffs be -p1 format ?
Try this patch. Completely untested; if it works, tell Junio. :)
 Documentation/git-apply.txt |    6 +++++-
 apply.c                     |    8 ++++++--
 2 files changed, 11 insertions(+), 3 deletions(-)
2490f3129103a0eae9013eb2a6f564f4a7290fbd
diff --git a/Documentation/git-apply.txt b/Documentation/git-apply.txt
index 51c7d47..75076b6 100644
--- a/Documentation/git-apply.txt
+++ b/Documentation/git-apply.txt
@@ -10,7 +10,7 @@ SYNOPSIS
 --------
 [verse]
 'git-apply' [--stat] [--numstat] [--summary] [--check] [--index] [--apply]
-	  [--no-add] [--index-info] [--allow-binary-replacement] [-z]
+	  [--no-add] [--index-info] [--allow-binary-replacement] [-z] [-pNUM]
 	  [<patch>...]
 
 DESCRIPTION
@@ -68,6 +68,10 @@ OPTIONS
 	backslash characters replaced with `\t`, `\n`, and `\\`,
 	respectively.
 
+-p<n>::
+	Remove <n> leading slashes from traditional diff paths. The
+	default is 1.
+
 --apply::
 	If you use any of the options marked ``Turns off
 	"apply"'' above, git-apply reads and outputs the
diff --git a/apply.c b/apply.c
index c471a82..79e23a7 100644
--- a/apply.c
+++ b/apply.c
@@ -19,6 +19,7 @@
 static const char *prefix;
 static int prefix_length = -1;
 
+static int p_value = 1;
 static int allow_binary_replacement = 0;
 static int check_index = 0;
 static int write_index = 0;
@@ -31,7 +32,7 @@ static int no_add = 0;
 static int show_index_info = 0;
 static int line_termination = '\n';
 static const char apply_usage[] =
-"git-apply [--stat] [--numstat] [--summary] [--check] [--index] [--apply] [--no-add] [--index-info] [--allow-binary-replacement] [-z] <patch>...";
+"git-apply [--stat] [--numstat] [--summary] [--check] [--index] [--apply] [--no-add] [--index-info] [--allow-binary-replacement] [-z] [-pNUM] <patch>...";
 
 /*
  * For "diff-stat" like behaviour, we keep track of the biggest change
@@ -217,7 +218,6 @@ static char * find_name(const char *line
  */
 static void parse_traditional_patch(const char *first, const char *second, struct patch *patch)
 {
-	int p_value = 1;
 	char *name;
 
 	first += 4;	// skip "--- "
@@ -1799,6 +1799,10 @@ int main(int argc, char **argv)
 			excludes = x;
 			continue;
 		}
+		if (!strncmp(arg, "-p", 2)) {
+			p_value = atoi(arg + 2);
+			continue;
+		}
 		if (!strcmp(arg, "--no-add")) {
 			no_add = 1;
 			continue;
-- 
0.99.6.g3480
Previous: Greg KHNext: Linus Torvalds
Message 3 of 4 in “Importing diffs”
  1. Ian MoltonJan 30, 2006
  2. Greg KHJan 30, 2006
  3. Make apply accept the -pNUM option like patch does.Daniel Barkalow, Jan 31, 2006
  4. Linus TorvaldsJan 31, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.