+static int remove_lock = 0;
+
+static void remove_lock_file(void)
+{
+ if (remove_lock)
+ unlink(".git/index.lock");
+}
+
+/*
+ * This removes all identical entries and collapses them to state 0.
+ *
+ * _Any_ other merge (even a trivial one, like both ) is left to user policy.
+ * That includes "both created the same file", and "both removed the same
+ * file" - which are trivial, but the user might still want to _note_ it.
+ */
+static int same_entry(struct cache_entry *a,
+ struct cache_entry *b,
+ struct cache_entry *c)
+{
+ int len = ce_namelen(a);
+ return a->ce_mode == b->ce_mode &&
+ a->ce_mode == c->ce_mode &&
+ ce_namelen(b) == len &&
+ ce_namelen(c) == len &&
+ !memcmp(a->name, b->name, len) &&
+ !memcmp(a->name, c->name, len) &&
+ !memcmp(a->sha1, b->sha1, 20) &&
+ !memcmp(a->sha1, c->sha1, 20);
+}
+
+static void trivially_merge_cache(struct cache_entry **src, int nr)
+{
+ struct cache_entry **dst = src;
+
+ while (nr) {
+ struct cache_entry *ce;
+
+ ce = src[0];
+ if (nr > 2 && same_entry(ce, src[1], src[2])) {
+ ce->ce_flags &= ~htons(CE_STAGEMASK);
+ src += 2;
+ nr -= 2;
+ active_nr -= 2;
+ }
+ *dst = ce;
+ src++;
+ dst++;
+ nr--;
+ }
+}
+