read-cache: be specific what part of the index has changed

cache entry additions, removals and modifications are separated out. The rest of changes are still in the catch-all flag SOMETHING_CHANGED, which would be more specific later. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Jun 13, 2014 at 19:19 UTC e636a7b4d0304608fe063ffcbbaf99e46f23dbea
4 files changed +15 -9
builtin/update-index.c
+3 -3
@@ -56,7 +56,7 @@ static int mark_ce_flags(const char *path, int flag, int mark)
56 else
57 active_cache[pos]->ce_flags &= ~flag;
58 cache_tree_invalidate_path(active_cache_tree, path);
59 - active_cache_changed = 1;
59 + active_cache_changed = SOMETHING_CHANGED;
60 return 0;
61 }
62 return -1;
@@ -268,7 +268,7 @@ static void chmod_path(int flip, const char *path)
268 goto fail;
269 }
270 cache_tree_invalidate_path(active_cache_tree, path);
271 - active_cache_changed = 1;
271 + active_cache_changed = SOMETHING_CHANGED;
272 report("chmod %cx '%s'", flip, path);
273 return;
274 fail:
@@ -889,7 +889,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
889 INDEX_FORMAT_LB, INDEX_FORMAT_UB);
890
891 if (the_index.version != preferred_index_format)
892 - active_cache_changed = 1;
892 + active_cache_changed = SOMETHING_CHANGED;
893 the_index.version = preferred_index_format;
894 }
895
cache.h
+5
@@ -268,6 +268,11 @@ static inline unsigned int canon_mode(unsigned int mode)
268
269 #define cache_entry_size(len) (offsetof(struct cache_entry,name) + (len) + 1)
270
271 +#define SOMETHING_CHANGED (1 << 0) /* unclassified changes go here */
272 +#define CE_ENTRY_CHANGED (1 << 1)
273 +#define CE_ENTRY_REMOVED (1 << 2)
274 +#define CE_ENTRY_ADDED (1 << 3)
275 +
276 struct index_state {
277 struct cache_entry **cache;
278 unsigned int version;
read-cache.c
+6 -5
@@ -51,7 +51,7 @@ static void replace_index_entry(struct index_state *istate, int nr, struct cache
51 remove_name_hash(istate, old);
52 free(old);
53 set_index_entry(istate, nr, ce);
54 - istate->cache_changed = 1;
54 + istate->cache_changed |= CE_ENTRY_CHANGED;
55 }
56
57 void rename_index_entry_at(struct index_state *istate, int nr, const char *new_name)
@@ -482,7 +482,7 @@ int remove_index_entry_at(struct index_state *istate, int pos)
482 record_resolve_undo(istate, ce);
483 remove_name_hash(istate, ce);
484 free(ce);
485 - istate->cache_changed = 1;
485 + istate->cache_changed |= CE_ENTRY_REMOVED;
486 istate->cache_nr--;
487 if (pos >= istate->cache_nr)
488 return 0;
@@ -512,7 +512,7 @@ void remove_marked_cache_entries(struct index_state *istate)
512 }
513 if (j == istate->cache_nr)
514 return;
515 - istate->cache_changed = 1;
515 + istate->cache_changed |= CE_ENTRY_REMOVED;
516 istate->cache_nr = j;
517 }
518
@@ -1002,7 +1002,7 @@ int add_index_entry(struct index_state *istate, struct cache_entry *ce, int opti
1002 istate->cache + pos,
1003 (istate->cache_nr - pos - 1) * sizeof(ce));
1004 set_index_entry(istate, pos, ce);
1005 - istate->cache_changed = 1;
1005 + istate->cache_changed |= CE_ENTRY_ADDED;
1006 return 0;
1007 }
1008
@@ -1101,6 +1101,7 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate,
1101 !(ce->ce_flags & CE_VALID))
1102 updated->ce_flags &= ~CE_VALID;
1103
1104 + /* istate->cache_changed is updated in the caller */
1105 return updated;
1106 }
1107
@@ -1182,7 +1183,7 @@ int refresh_index(struct index_state *istate, unsigned int flags,
1183 * means the index is not valid anymore.
1184 */
1185 ce->ce_flags &= ~CE_VALID;
1185 - istate->cache_changed = 1;
1186 + istate->cache_changed |= CE_ENTRY_CHANGED;
1187 }
1188 if (quiet)
1189 continue;
resolve-undo.c
+1 -1
@@ -110,7 +110,7 @@ void resolve_undo_clear_index(struct index_state *istate)
110 string_list_clear(resolve_undo, 1);
111 free(resolve_undo);
112 istate->resolve_undo = NULL;
113 - istate->cache_changed = 1;
113 + istate->cache_changed = SOMETHING_CHANGED;
114 }
115
116 int unmerge_index_entry_at(struct index_state *istate, int pos)