[PATCH 5/8] hash-object: work within subdirectory.
From: Junio C Hamano <hidden>
Date: 2016-06-15 22:42:13
Subsystem:
the rest · Maintainer:
Linus Torvalds
When -w is given, it needs to find out where the .git directory is, so run the setup_git_directory() when we see a -w. Signed-off-by: Junio C Hamano <redacted> --- hash-object.c | 19 ++++++++++++++++--- 1 files changed, 16 insertions(+), 3 deletions(-) applies-to: b0041c758e0fc01e5ec05bd0543d04d1a9cb17f5 61fdef6a50c99c98feebd71f499450cf97a8c169
diff --git a/hash-object.c b/hash-object.c
index c8c9adb..3075328 100644
--- a/hash-object.c
+++ b/hash-object.c@@ -6,6 +6,9 @@ */ #include "cache.h" +static const char *prefix; +static int prefix_length = -1; + static void hash_object(const char *path, const char *type, int write_object) { int fd;
@@ -36,10 +39,20 @@ int main(int argc, char **argv) die(hash_object_usage); type = argv[i]; } - else if (!strcmp(argv[i], "-w")) + else if (!strcmp(argv[i], "-w")) { + if (prefix_length < 0) { + prefix = setup_git_directory(); + prefix_length = prefix ? strlen(prefix) : 0; + } write_object = 1; - else - hash_object(argv[i], type, write_object); + } + else { + char *arg = argv[i]; + if (0 <= prefix_length) + arg = prefix_filename(prefix, prefix_length, + arg); + hash_object(arg, type, write_object); + } } return 0; }
--- 0.99.9.GIT