@matheusbsbs / matheus-bagliano / commits / 706fe6ae03
Fork 0

hash-object: work within subdirectory.

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>

Junio C Hamano committed Nov 26, 2005 at 00:30 UTC 706fe6ae03e2c1452d59892944701c56237b903f
1 file changed +15 -3
hash-object.c
+15 -3
@@ -29,6 +29,8 @@ int main(int argc, char **argv)
29 int i;
30 const char *type = "blob";
31 int write_object = 0;
32 + const char *prefix;
33 + int prefix_length = -1;
34
35 for (i = 1 ; i < argc; i++) {
36 if (!strcmp(argv[i], "-t")) {
@@ -36,10 +38,20 @@ int main(int argc, char **argv)
38 die(hash_object_usage);
39 type = argv[i];
40 }
39 - else if (!strcmp(argv[i], "-w"))
41 + else if (!strcmp(argv[i], "-w")) {
42 + if (prefix_length < 0) {
43 + prefix = setup_git_directory();
44 + prefix_length = prefix ? strlen(prefix) : 0;
45 + }
46 write_object = 1;
41 - else
42 - hash_object(argv[i], type, write_object);
47 + }
48 + else {
49 + char *arg = argv[i];
50 + if (0 <= prefix_length)
51 + arg = prefix_filename(prefix, prefix_length,
52 + arg);
53 + hash_object(arg, type, write_object);
54 + }
55 }
56 return 0;
57 }