@matheusbsbs / matheus-bagliano / commits / e36f8b6034
Fork 0

Make apply accept the -pNUM option like patch does.

This only applies to traditional diffs, not to git diffs. Signed-off-by: Daniel Barkalow <barkalow@iabervon.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Daniel Barkalow committed Jan 31, 2006 at 00:36 UTC e36f8b6034f9df7e7b0aea912d1c8e850503623e
2 files changed +11 -3
Documentation/git-apply.txt
+5 -1
@@ -10,7 +10,7 @@ SYNOPSIS
10 --------
11 [verse]
12 'git-apply' [--stat] [--numstat] [--summary] [--check] [--index] [--apply]
13 - [--no-add] [--index-info] [--allow-binary-replacement] [-z]
13 + [--no-add] [--index-info] [--allow-binary-replacement] [-z] [-pNUM]
14 [<patch>...]
15
16 DESCRIPTION
@@ -68,6 +68,10 @@ OPTIONS
68 backslash characters replaced with `\t`, `\n`, and `\\`,
69 respectively.
70
71 +-p<n>::
72 + Remove <n> leading slashes from traditional diff paths. The
73 + default is 1.
74 +
75 --apply::
76 If you use any of the options marked ``Turns off
77 "apply"'' above, git-apply reads and outputs the
apply.c
+6 -2
@@ -19,6 +19,7 @@
19 static const char *prefix;
20 static int prefix_length = -1;
21
22 +static int p_value = 1;
23 static int allow_binary_replacement = 0;
24 static int check_index = 0;
25 static int write_index = 0;
@@ -31,7 +32,7 @@ static int no_add = 0;
32 static int show_index_info = 0;
33 static int line_termination = '\n';
34 static const char apply_usage[] =
34 -"git-apply [--stat] [--numstat] [--summary] [--check] [--index] [--apply] [--no-add] [--index-info] [--allow-binary-replacement] [-z] <patch>...";
35 +"git-apply [--stat] [--numstat] [--summary] [--check] [--index] [--apply] [--no-add] [--index-info] [--allow-binary-replacement] [-z] [-pNUM] <patch>...";
36
37 /*
38 * For "diff-stat" like behaviour, we keep track of the biggest change
@@ -217,7 +218,6 @@ static char * find_name(const char *line, char *def, int p_value, int terminate)
218 */
219 static void parse_traditional_patch(const char *first, const char *second, struct patch *patch)
220 {
220 - int p_value = 1;
221 char *name;
222
223 first += 4; // skip "--- "
@@ -1799,6 +1799,10 @@ int main(int argc, char **argv)
1799 excludes = x;
1800 continue;
1801 }
1802 + if (!strncmp(arg, "-p", 2)) {
1803 + p_value = atoi(arg + 2);
1804 + continue;
1805 + }
1806 if (!strcmp(arg, "--no-add")) {
1807 no_add = 1;
1808 continue;