Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit e636a7b

Browse files
pcloudsgitster
authored andcommitted
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>
1 parent ad837d9 commit e636a7b

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

builtin/update-index.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static int mark_ce_flags(const char *path, int flag, int mark)
5656
else
5757
active_cache[pos]->ce_flags &= ~flag;
5858
cache_tree_invalidate_path(active_cache_tree, path);
59-
active_cache_changed = 1;
59+
active_cache_changed = SOMETHING_CHANGED;
6060
return 0;
6161
}
6262
return -1;
@@ -268,7 +268,7 @@ static void chmod_path(int flip, const char *path)
268268
goto fail;
269269
}
270270
cache_tree_invalidate_path(active_cache_tree, path);
271-
active_cache_changed = 1;
271+
active_cache_changed = SOMETHING_CHANGED;
272272
report("chmod %cx '%s'", flip, path);
273273
return;
274274
fail:
@@ -889,7 +889,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
889889
INDEX_FORMAT_LB, INDEX_FORMAT_UB);
890890

891891
if (the_index.version != preferred_index_format)
892-
active_cache_changed = 1;
892+
active_cache_changed = SOMETHING_CHANGED;
893893
the_index.version = preferred_index_format;
894894
}
895895

cache.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,11 @@ static inline unsigned int canon_mode(unsigned int mode)
268268

269269
#define cache_entry_size(len) (offsetof(struct cache_entry,name) + (len) + 1)
270270

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+
271276
struct index_state {
272277
struct cache_entry **cache;
273278
unsigned int version;

read-cache.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static void replace_index_entry(struct index_state *istate, int nr, struct cache
5151
remove_name_hash(istate, old);
5252
free(old);
5353
set_index_entry(istate, nr, ce);
54-
istate->cache_changed = 1;
54+
istate->cache_changed |= CE_ENTRY_CHANGED;
5555
}
5656

5757
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)
482482
record_resolve_undo(istate, ce);
483483
remove_name_hash(istate, ce);
484484
free(ce);
485-
istate->cache_changed = 1;
485+
istate->cache_changed |= CE_ENTRY_REMOVED;
486486
istate->cache_nr--;
487487
if (pos >= istate->cache_nr)
488488
return 0;
@@ -512,7 +512,7 @@ void remove_marked_cache_entries(struct index_state *istate)
512512
}
513513
if (j == istate->cache_nr)
514514
return;
515-
istate->cache_changed = 1;
515+
istate->cache_changed |= CE_ENTRY_REMOVED;
516516
istate->cache_nr = j;
517517
}
518518

@@ -1002,7 +1002,7 @@ int add_index_entry(struct index_state *istate, struct cache_entry *ce, int opti
10021002
istate->cache + pos,
10031003
(istate->cache_nr - pos - 1) * sizeof(ce));
10041004
set_index_entry(istate, pos, ce);
1005-
istate->cache_changed = 1;
1005+
istate->cache_changed |= CE_ENTRY_ADDED;
10061006
return 0;
10071007
}
10081008

@@ -1101,6 +1101,7 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate,
11011101
!(ce->ce_flags & CE_VALID))
11021102
updated->ce_flags &= ~CE_VALID;
11031103

1104+
/* istate->cache_changed is updated in the caller */
11041105
return updated;
11051106
}
11061107

@@ -1182,7 +1183,7 @@ int refresh_index(struct index_state *istate, unsigned int flags,
11821183
* means the index is not valid anymore.
11831184
*/
11841185
ce->ce_flags &= ~CE_VALID;
1185-
istate->cache_changed = 1;
1186+
istate->cache_changed |= CE_ENTRY_CHANGED;
11861187
}
11871188
if (quiet)
11881189
continue;

resolve-undo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ void resolve_undo_clear_index(struct index_state *istate)
110110
string_list_clear(resolve_undo, 1);
111111
free(resolve_undo);
112112
istate->resolve_undo = NULL;
113-
istate->cache_changed = 1;
113+
istate->cache_changed = SOMETHING_CHANGED;
114114
}
115115

116116
int unmerge_index_entry_at(struct index_state *istate, int pos)

0 commit comments

Comments
 (0)