@matheusbsbs / matheus-bagliano / commits / 227bdb186f
Fork 0

make update-index --chmod work with multiple files and --stdin

The patch makes "--chmod=-x" and "--chmod=+x" act like "--add" and "--remove" to affect the behaviour of the command for the rest of the path parameters, not just the following one. Signed-off-by: Junio C Hamano <junkio@cox.net>

Alex Riesen committed Apr 23, 2006 at 09:01 UTC 227bdb186f06fa65afb1a0e091b2b191132c29ba
1 file changed +16 -7
update-index.c
+16 -7
@@ -328,7 +328,7 @@ static int add_cacheinfo(unsigned int mode, const unsigned char *sha1,
328 return 0;
329 }
330
331 -static int chmod_path(int flip, const char *path)
331 +static void chmod_path(int flip, const char *path)
332 {
333 int pos;
334 struct cache_entry *ce;
@@ -336,21 +336,24 @@ static int chmod_path(int flip, const char *path)
336
337 pos = cache_name_pos(path, strlen(path));
338 if (pos < 0)
339 - return -1;
339 + goto fail;
340 ce = active_cache[pos];
341 mode = ntohl(ce->ce_mode);
342 if (!S_ISREG(mode))
343 - return -1;
343 + goto fail;
344 switch (flip) {
345 case '+':
346 ce->ce_mode |= htonl(0111); break;
347 case '-':
348 ce->ce_mode &= htonl(~0111); break;
349 default:
350 - return -1;
350 + goto fail;
351 }
352 active_cache_changed = 1;
353 - return 0;
353 + report("chmod %cx '%s'", flip, path);
354 + return;
355 + fail:
356 + die("git-update-index: cannot chmod %cx '%s'", flip, path);
357 }
358
359 static struct cache_file cache_file;
@@ -478,6 +481,7 @@ int main(int argc, const char **argv)
481 int read_from_stdin = 0;
482 const char *prefix = setup_git_directory();
483 int prefix_length = prefix ? strlen(prefix) : 0;
484 + char set_executable_bit = 0;
485
486 git_config(git_default_config);
487
@@ -544,8 +548,7 @@ int main(int argc, const char **argv)
548 !strcmp(path, "--chmod=+x")) {
549 if (argc <= i+1)
550 die("git-update-index: %s <path>", path);
547 - if (chmod_path(path[8], argv[++i]))
548 - die("git-update-index: %s cannot chmod %s", path, argv[i]);
551 + set_executable_bit = path[8];
552 continue;
553 }
554 if (!strcmp(path, "--assume-unchanged")) {
@@ -594,6 +597,8 @@ int main(int argc, const char **argv)
597 die("unknown option %s", path);
598 }
599 update_one(path, prefix, prefix_length);
600 + if (set_executable_bit)
601 + chmod_path(set_executable_bit, path);
602 }
603 if (read_from_stdin) {
604 struct strbuf buf;
@@ -608,6 +613,10 @@ int main(int argc, const char **argv)
613 else
614 path_name = buf.buf;
615 update_one(path_name, prefix, prefix_length);
616 + if (set_executable_bit) {
617 + const char *p = prefix_path(prefix, prefix_length, path_name);
618 + chmod_path(set_executable_bit, p);
619 + }
620 if (path_name != buf.buf)
621 free(path_name);
622 }