diff options
author | Elijah Newren <newren@gmail.com> | 2018-07-01 04:24:56 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2018-07-03 23:13:18 +0300 |
commit | 1b9fbefbe08ff2bbcbb8a6089867b32fca603eac (patch) | |
tree | 34cb866304417116c47b1ec2a34b8421d331323f /read-cache.c | |
parent | cffbfad50d1f37aea03520dd8d8ea983bc57da02 (diff) |
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 <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'read-cache.c')
-rw-r--r-- | read-cache.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/read-cache.c b/read-cache.c index ba094fd4855..f333a517f7d 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; } } |