summaryrefslogtreecommitdiff
path: root/read-cache.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2018-08-02 22:30:44 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-08-02 22:30:45 (GMT)
commitc18ac30e9ebcf7b7e2fbd992744e63c71089a12a (patch)
tree5eb5c1185b0d8bce39356abd801f0a9d7bf802ab /read-cache.c
parent2b9afea37207323d629953c639542c0e4c87e484 (diff)
parent55f39cf7551bd468065306328efdb78933b36b69 (diff)
downloadgit-c18ac30e9ebcf7b7e2fbd992744e63c71089a12a.zip
git-c18ac30e9ebcf7b7e2fbd992744e63c71089a12a.tar.gz
git-c18ac30e9ebcf7b7e2fbd992744e63c71089a12a.tar.bz2
Merge branch 'en/dirty-merge-fixes'
The recursive merge strategy did not properly ensure there was no change between HEAD and the index before performing its operation, which has been corrected. * en/dirty-merge-fixes: merge: fix misleading pre-merge check documentation merge-recursive: enforce rule that index matches head before merging t6044: add more testcases with staged changes before a merge is invoked merge-recursive: fix assumption that head tree being merged is HEAD merge-recursive: make sure when we say we abort that we actually abort t6044: add a testcase for index matching head, when head doesn't match HEAD t6044: verify that merges expected to abort actually abort index_has_changes(): avoid assuming operating on the_index read-cache.c: move index_has_changes() from merge.c
Diffstat (limited to 'read-cache.c')
-rw-r--r--read-cache.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/read-cache.c b/read-cache.c
index 56eac50..880849f 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -6,6 +6,8 @@
#define NO_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "config.h"
+#include "diff.h"
+#include "diffcore.h"
#include "tempfile.h"
#include "lockfile.h"
#include "cache-tree.h"
@@ -2120,6 +2122,44 @@ int unmerged_index(const struct index_state *istate)
return 0;
}
+int index_has_changes(const struct index_state *istate,
+ struct tree *tree,
+ struct strbuf *sb)
+{
+ struct object_id cmp;
+ int i;
+
+ 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(&cmp, &opt);
+ diffcore_std(&opt);
+ for (i = 0; sb && i < diff_queued_diff.nr; i++) {
+ if (i)
+ strbuf_addch(sb, ' ');
+ strbuf_addstr(sb, diff_queued_diff.queue[i]->two->path);
+ }
+ diff_flush(&opt);
+ return opt.flags.has_changes != 0;
+ } else {
+ for (i = 0; sb && i < istate->cache_nr; i++) {
+ if (i)
+ strbuf_addch(sb, ' ');
+ strbuf_addstr(sb, istate->cache[i]->name);
+ }
+ return !!istate->cache_nr;
+ }
+}
+
#define WRITE_BUFFER_SIZE 8192
static unsigned char write_buffer[WRITE_BUFFER_SIZE];
static unsigned long write_buffer_len;