From 22433ce4617b6ff30c9e9bf03b85d4bb244c3dec Mon Sep 17 00:00:00 2001 From: Thomas Gummerer Date: Wed, 14 Sep 2016 22:07:45 +0100 Subject: update-index: add test for chmod flags Currently there is no test checking the expected behaviour when multiple chmod flags with different arguments are passed. As argument handling is not in line with other git commands it's easy to miss and accidentally change the current behaviour. While there, fix the argument type of chmod_path, which takes an int, but had a char passed in. Signed-off-by: Thomas Gummerer Signed-off-by: Junio C Hamano --- builtin/update-index.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'builtin/update-index.c') diff --git a/builtin/update-index.c b/builtin/update-index.c index b8b8522249..57bd5af144 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -419,7 +419,7 @@ static int add_cacheinfo(unsigned int mode, const unsigned char *sha1, return 0; } -static void chmod_path(int flip, const char *path) +static void chmod_path(char flip, const char *path) { int pos; struct cache_entry *ce; -- cgit v1.2.1 From d9d7096662122f6b82ad6e4c08397b75906da78d Mon Sep 17 00:00:00 2001 From: Thomas Gummerer Date: Wed, 14 Sep 2016 22:07:46 +0100 Subject: read-cache: introduce chmod_index_entry As there are chmod options for both add and update-index, introduce a new chmod_index_entry function to do the work. Use it in update-index, while it will be used in add in the next patch. Signed-off-by: Thomas Gummerer Signed-off-by: Junio C Hamano --- builtin/update-index.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) (limited to 'builtin/update-index.c') diff --git a/builtin/update-index.c b/builtin/update-index.c index 57bd5af144..8ef21fedc8 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -423,26 +423,14 @@ static void chmod_path(char flip, const char *path) { int pos; struct cache_entry *ce; - unsigned int mode; pos = cache_name_pos(path, strlen(path)); if (pos < 0) goto fail; ce = active_cache[pos]; - mode = ce->ce_mode; - if (!S_ISREG(mode)) - goto fail; - switch (flip) { - case '+': - ce->ce_mode |= 0111; break; - case '-': - ce->ce_mode &= ~0111; break; - default: + if (chmod_cache_entry(ce, flip) < 0) goto fail; - } - cache_tree_invalidate_path(&the_index, path); - ce->ce_flags |= CE_UPDATE_IN_BASE; - active_cache_changed |= CE_ENTRY_CHANGED; + report("chmod %cx '%s'", flip, path); return; fail: -- cgit v1.2.1