X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=apply.c;h=2ad47fbbb37b245a78abd8e8255d39b39a52f9a9;hb=04fe2a1706b4bd71b604bfe7d7295064440872cf;hp=c471a82e83691b152c2b80ea25310afef9b0db95;hpb=d9e08be9d5b632aed84d4ee870543babafe6614b;p=git.git diff --git a/apply.c b/apply.c index c471a82e..2ad47fbb 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] ..."; +"git-apply [--stat] [--numstat] [--summary] [--check] [--index] [--apply] [--no-add] [--index-info] [--allow-binary-replacement] [-z] [-pNUM] ..."; /* * 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) */ static void parse_traditional_patch(const char *first, const char *second, struct patch *patch) { - int p_value = 1; char *name; first += 4; // skip "--- " @@ -1564,24 +1564,6 @@ static void add_index_file(const char *path, unsigned mode, void *buf, unsigned die("unable to add cache entry for %s", path); } -static void create_subdirectories(const char *path) -{ - int len = strlen(path); - char *buf = xmalloc(len + 1); - const char *slash = path; - - while ((slash = strchr(slash+1, '/')) != NULL) { - len = slash - path; - memcpy(buf, path, len); - buf[len] = 0; - if (mkdir(buf, 0777) < 0) { - if (errno != EEXIST) - break; - } - } - free(buf); -} - static int try_create_file(const char *path, unsigned int mode, const char *buf, unsigned long size) { int fd; @@ -1610,13 +1592,14 @@ static int try_create_file(const char *path, unsigned int mode, const char *buf, * which is true 99% of the time anyway. If they don't, * we create them and try again. */ -static void create_one_file(const char *path, unsigned mode, const char *buf, unsigned long size) +static void create_one_file(char *path, unsigned mode, const char *buf, unsigned long size) { if (!try_create_file(path, mode, buf, size)) return; if (errno == ENOENT) { - create_subdirectories(path); + if (safe_create_leading_directories(path)) + return; if (!try_create_file(path, mode, buf, size)) return; } @@ -1643,7 +1626,7 @@ static void create_one_file(const char *path, unsigned mode, const char *buf, un static void create_file(struct patch *patch) { - const char *path = patch->new_name; + char *path = patch->new_name; unsigned mode = patch->new_mode; unsigned long size = patch->resultsize; char *buf = patch->result; @@ -1799,6 +1782,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;