[PATCH 5/8] hash-object: work within subdirectory.
- From
Junio C Hamano <junkio@cox.net>
- Date
- Nov 26, 2005, 09:57 UTC
- Message-ID
- <7vveyf4tqr.fsf@assigned-by-dhcp.cox.net>
- In-Reply-To
- <7vmzjtn3h1.fsf@assigned-by-dhcp.cox.net>
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 <junkio@cox.net>
---
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