From 1b9fbefbe08ff2bbcbb8a6089867b32fca603eac Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Sat, 30 Jun 2018 18:24:56 -0700 Subject: index_has_changes(): avoid assuming operating on the_index Modify index_has_changes() to take a struct istate* instead of just operating on the_index. This is only a partial conversion, though, because we call do_diff_cache() which implicitly assumes work is to be done on the_index. Ongoing work is being done elsewhere to do the remainder of the conversion, and thus is not duplicated here. Instead, a simple check is put in place until that work is complete. Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- read-cache.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'read-cache.c') diff --git a/read-cache.c b/read-cache.c index ba094fd485..f333a517f7 100644 --- a/read-cache.c +++ b/read-cache.c @@ -1986,11 +1986,14 @@ int unmerged_index(const struct index_state *istate) return 0; } -int index_has_changes(struct strbuf *sb) +int index_has_changes(const struct index_state *istate, struct strbuf *sb) { struct object_id head; int i; + if (istate != &the_index) { + BUG("index_has_changes cannot yet accept istate != &the_index; do_diff_cache needs updating first."); + } if (!get_oid_tree("HEAD", &head)) { struct diff_options opt; @@ -2008,12 +2011,12 @@ int index_has_changes(struct strbuf *sb) diff_flush(&opt); return opt.flags.has_changes != 0; } else { - for (i = 0; sb && i < the_index.cache_nr; i++) { + for (i = 0; sb && i < istate->cache_nr; i++) { if (i) strbuf_addch(sb, ' '); - strbuf_addstr(sb, the_index.cache[i]->name); + strbuf_addstr(sb, istate->cache[i]->name); } - return !!the_index.cache_nr; + return !!istate->cache_nr; } } -- cgit v1.3