- if (strcmp(type, "tree"))
- return -1;
- while (size) {
- int len = strlen(buffer)+1;
- unsigned char *sha1 = buffer + len;
- char *path = strchr(buffer, ' ')+1;
- unsigned int mode;
+ ret = read_tree(buffer, size, stage);
+ free(buffer);
+ return ret;
+}
+
+static char *lockfile_name;
+
+static void remove_lock_file(void)
+{
+ if (lockfile_name)
+ unlink(lockfile_name);
+}
+
+static int path_matches(struct cache_entry *a, struct cache_entry *b)
+{
+ int len = ce_namelen(a);
+ return ce_namelen(b) == len &&
+ !memcmp(a->name, b->name, len);
+}
+
+static int same(struct cache_entry *a, struct cache_entry *b)
+{
+ return a->ce_mode == b->ce_mode &&
+ !memcmp(a->sha1, b->sha1, 20);
+}
+
+
+/*
+ * This removes all trivial merges that don't change the tree
+ * and collapses them to state 0.
+ *
+ * _Any_ other merge 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 struct cache_entry *merge_entries(struct cache_entry *a,
+ struct cache_entry *b,
+ struct cache_entry *c)
+{
+ int len = ce_namelen(a);