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:
parent
22433ce461
commit
d9d7096662
@ -423,26 +423,14 @@ static void chmod_path(char flip, const char *path)
|
|||||||
{
|
{
|
||||||
int pos;
|
int pos;
|
||||||
struct cache_entry *ce;
|
struct cache_entry *ce;
|
||||||
unsigned int mode;
|
|
||||||
|
|
||||||
pos = cache_name_pos(path, strlen(path));
|
pos = cache_name_pos(path, strlen(path));
|
||||||
if (pos < 0)
|
if (pos < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
ce = active_cache[pos];
|
ce = active_cache[pos];
|
||||||
mode = ce->ce_mode;
|
if (chmod_cache_entry(ce, flip) < 0)
|
||||||
if (!S_ISREG(mode))
|
|
||||||
goto fail;
|
goto fail;
|
||||||
switch (flip) {
|
|
||||||
case '+':
|
|
||||||
ce->ce_mode |= 0111; break;
|
|
||||||
case '-':
|
|
||||||
ce->ce_mode &= ~0111; break;
|
|
||||||
default:
|
|
||||||
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);
|
report("chmod %cx '%s'", flip, path);
|
||||||
return;
|
return;
|
||||||
fail:
|
fail:
|
||||||
|
2
cache.h
2
cache.h
@ -369,6 +369,7 @@ extern void free_name_hash(struct index_state *istate);
|
|||||||
#define remove_file_from_cache(path) remove_file_from_index(&the_index, (path))
|
#define remove_file_from_cache(path) remove_file_from_index(&the_index, (path))
|
||||||
#define add_to_cache(path, st, flags) add_to_index(&the_index, (path), (st), (flags), 0)
|
#define add_to_cache(path, st, flags) add_to_index(&the_index, (path), (st), (flags), 0)
|
||||||
#define add_file_to_cache(path, flags) add_file_to_index(&the_index, (path), (flags), 0)
|
#define add_file_to_cache(path, flags) add_file_to_index(&the_index, (path), (flags), 0)
|
||||||
|
#define chmod_cache_entry(ce, flip) chmod_index_entry(&the_index, (ce), (flip))
|
||||||
#define refresh_cache(flags) refresh_index(&the_index, (flags), NULL, NULL, NULL)
|
#define refresh_cache(flags) refresh_index(&the_index, (flags), NULL, NULL, NULL)
|
||||||
#define ce_match_stat(ce, st, options) ie_match_stat(&the_index, (ce), (st), (options))
|
#define ce_match_stat(ce, st, options) ie_match_stat(&the_index, (ce), (st), (options))
|
||||||
#define ce_modified(ce, st, options) ie_modified(&the_index, (ce), (st), (options))
|
#define ce_modified(ce, st, options) ie_modified(&the_index, (ce), (st), (options))
|
||||||
@ -584,6 +585,7 @@ extern int remove_file_from_index(struct index_state *, const char *path);
|
|||||||
extern int add_to_index(struct index_state *, const char *path, struct stat *, int flags, int force_mode);
|
extern int add_to_index(struct index_state *, const char *path, struct stat *, int flags, int force_mode);
|
||||||
extern int add_file_to_index(struct index_state *, const char *path, int flags, int force_mode);
|
extern int add_file_to_index(struct index_state *, const char *path, int flags, int force_mode);
|
||||||
extern struct cache_entry *make_cache_entry(unsigned int mode, const unsigned char *sha1, const char *path, int stage, unsigned int refresh_options);
|
extern struct cache_entry *make_cache_entry(unsigned int mode, const unsigned char *sha1, const char *path, int stage, unsigned int refresh_options);
|
||||||
|
extern int chmod_index_entry(struct index_state *, struct cache_entry *ce, char flip);
|
||||||
extern int ce_same_name(const struct cache_entry *a, const struct cache_entry *b);
|
extern int ce_same_name(const struct cache_entry *a, const struct cache_entry *b);
|
||||||
extern void set_object_name_for_intent_to_add_entry(struct cache_entry *ce);
|
extern void set_object_name_for_intent_to_add_entry(struct cache_entry *ce);
|
||||||
extern int index_name_is_other(const struct index_state *, const char *, int);
|
extern int index_name_is_other(const struct index_state *, const char *, int);
|
||||||
|
29
read-cache.c
29
read-cache.c
@ -759,6 +759,35 @@ struct cache_entry *make_cache_entry(unsigned int mode,
|
|||||||
return ret;
|
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 ce_same_name(const struct cache_entry *a, const struct cache_entry *b)
|
||||||
{
|
{
|
||||||
int len = ce_namelen(a);
|
int len = ce_namelen(a);
|
||||||
|
Loading…
Reference in New Issue
Block a user