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>
This commit is contained in:

committed by
Junio C Hamano

parent
22433ce461
commit
d9d7096662
29
read-cache.c
29
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);
|
||||
|
Reference in New Issue
Block a user