summaryrefslogtreecommitdiff
path: root/apply.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2005-11-26 07:14:15 (GMT)
committerJunio C Hamano <junkio@cox.net>2005-11-29 07:13:01 (GMT)
commitedf2e37002eeb30a2ccad5db3b3e1fe41cdc7eb0 (patch)
tree6e54580ff2c4e88ec68a7d22afe884544851382d /apply.c
parent4ca0660816671f65546626b6e2c2038b6a347a8b (diff)
downloadgit-edf2e37002eeb30a2ccad5db3b3e1fe41cdc7eb0.zip
git-edf2e37002eeb30a2ccad5db3b3e1fe41cdc7eb0.tar.gz
git-edf2e37002eeb30a2ccad5db3b3e1fe41cdc7eb0.tar.bz2
git-apply: work from subdirectory.
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>
Diffstat (limited to 'apply.c')
-rw-r--r--apply.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/apply.c b/apply.c
index 50be8f3..1742ab2 100644
--- a/apply.c
+++ b/apply.c
@@ -16,6 +16,9 @@
// --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;
@@ -1706,6 +1709,12 @@ static int use_patch(struct patch *p)
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;
}
@@ -1845,6 +1854,15 @@ int main(int argc, char **argv)
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);