diff options
author | Thomas Gummerer <t.gummerer@gmail.com> | 2016-09-14 22:07:46 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-09-15 12:13:54 -0700 |
commit | d9d7096662122f6b82ad6e4c08397b75906da78d (patch) | |
tree | 16d6fb77cdde3c6b2ca94be67436221767f40726 /read-cache.c | |
parent | 22433ce4617b6ff30c9e9bf03b85d4bb244c3dec (diff) | |
download | git-d9d7096662122f6b82ad6e4c08397b75906da78d.tar.gz |
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 <t.gummerer@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'read-cache.c')
-rw-r--r-- | read-cache.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/read-cache.c b/read-cache.c index db27766055..d11a43beb6 100644 --- a/read-cache.c +++ b/read-cache.c @@ -759,6 +759,35 @@ struct cache_entry *make_cache_entry(unsigned int mode, return ret; } +/* + * Chmod an index entry with either +x or -x. + * + * Returns -1 if the chmod for the particular cache entry failed (if it's + * not a regular file), -2 if an invalid flip argument is passed in, 0 + * otherwise. + */ +int chmod_index_entry(struct index_state *istate, struct cache_entry *ce, + char flip) +{ + if (!S_ISREG(ce->ce_mode)) + return -1; + switch (flip) { + case '+': + ce->ce_mode |= 0111; + break; + case '-': + ce->ce_mode &= ~0111; + break; + default: + return -2; + } + cache_tree_invalidate_path(istate, ce->name); + ce->ce_flags |= CE_UPDATE_IN_BASE; + istate->cache_changed |= CE_ENTRY_CHANGED; + + return 0; +} + int ce_same_name(const struct cache_entry *a, const struct cache_entry *b) { int len = ce_namelen(a); |