merge: fix misleading pre-merge check documentation
[gitweb.git] / read-cache.c
index ba094fd48553efdad083b83df11fa30ac6c282cf..639c1fffa0635e8829ad76d74407b06447e42b1f 100644 (file)
@@ -1986,19 +1986,26 @@ 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 tree *tree,
+                     struct strbuf *sb)
 {
-       struct object_id head;
+       struct object_id cmp;
        int i;
 
-       if (!get_oid_tree("HEAD", &head)) {
+       if (istate != &the_index) {
+               BUG("index_has_changes cannot yet accept istate != &the_index; do_diff_cache needs updating first.");
+       }
+       if (tree)
+               cmp = tree->object.oid;
+       if (tree || !get_oid_tree("HEAD", &cmp)) {
                struct diff_options opt;
 
                diff_setup(&opt);
                opt.flags.exit_with_status = 1;
                if (!sb)
                        opt.flags.quick = 1;
-               do_diff_cache(&head, &opt);
+               do_diff_cache(&cmp, &opt);
                diffcore_std(&opt);
                for (i = 0; sb && i < diff_queued_diff.nr; i++) {
                        if (i)
@@ -2008,12 +2015,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;
        }
 }