summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4ca0660)
raw | patch | inline | side by side (parent: 4ca0660)
author | Junio C Hamano <junkio@cox.net> | |
Sat, 26 Nov 2005 07:14:15 +0000 (23:14 -0800) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Tue, 29 Nov 2005 07:13:01 +0000 (23:13 -0800) |
When applying a patch to index file, we need to know where GIT_DIR is;
use setup_git_directory() to find it out. This also allows us to work
from a subdirectory if we wanted to.
When git-apply is run from a subdirectory, it applies the given patch
only to the files under the current directory and below.
Signed-off-by: Junio C Hamano <junkio@cox.net>
use setup_git_directory() to find it out. This also allows us to work
from a subdirectory if we wanted to.
When git-apply is run from a subdirectory, it applies the given patch
only to the files under the current directory and below.
Signed-off-by: Junio C Hamano <junkio@cox.net>
apply.c | patch | blob | history |
index 50be8f3e22d0906d09410b89ebc8d06f928ba631..1742ab28e95936eed52e910930a8a04869c5418b 100644 (file)
--- a/apply.c
+++ b/apply.c
// --numstat does numeric diffstat, and doesn't actually apply
// --index-info shows the old and new index info for paths if available.
//
+static const char *prefix;
+static int prefix_length = -1;
+
static int allow_binary_replacement = 0;
static int check_index = 0;
static int write_index = 0;
return 0;
x = x->next;
}
+ if (0 < prefix_length) {
+ int pathlen = strlen(pathname);
+ if (pathlen <= prefix_length ||
+ memcmp(prefix, pathname, prefix_length))
+ return 0;
+ }
return 1;
}
line_termination = 0;
continue;
}
+
+ if (check_index && prefix_length < 0) {
+ prefix = setup_git_directory();
+ prefix_length = prefix ? strlen(prefix) : 0;
+ git_config(git_default_config);
+ }
+ if (0 < prefix_length)
+ arg = prefix_filename(prefix, prefix_length, arg);
+
fd = open(arg, O_RDONLY);
if (fd < 0)
usage(apply_usage);