1939
return 0;
1940
}
1941
1942
+/**
1943
+ * Merges a tree into the index. The index's stat info will take precedence
1944
+ * over the merged tree's. Returns 0 on success, -1 on failure.
1945
+ */
1946
+static int merge_tree(struct tree *tree)
1947
+{
1948
+ struct lock_file *lock_file;
1949
+ struct unpack_trees_options opts;
1950
+ struct tree_desc t[1];
1951
+
1952
+ if (parse_tree(tree))
1953
+ return -1;
1954
+
1955
+ lock_file = xcalloc(1, sizeof(struct lock_file));
1956
+ hold_locked_index(lock_file, 1);
1957
+
1958
+ memset(&opts, 0, sizeof(opts));
1959
+ opts.head_idx = 1;
1960
+ opts.src_index = &the_index;
1961
+ opts.dst_index = &the_index;
1962
+ opts.merge = 1;
1963
+ opts.fn = oneway_merge;
1964
+ init_tree_desc(&t[0], tree->buffer, tree->size);
1965
+
1966
+ if (unpack_trees(1, t, &opts)) {
1967
+ rollback_lock_file(lock_file);
1968
+ return -1;
1969
+ }
1970
+
1971
+ if (write_locked_index(&the_index, lock_file, COMMIT_LOCK))
1972
+ die(_("unable to write new index file"));
1973
+
1974
+ return 0;
1975
+}
1976
+
1977
/**
1978
* Clean the index without touching entries that are not modified between
1979
* `head` and `remote`.
1980
*/
1981
static int clean_index(const unsigned char *head, const unsigned char *remote)
1982
{
1948
- struct lock_file *lock_file;
1983
struct tree *head_tree, *remote_tree, *index_tree;
1984
unsigned char index[GIT_SHA1_RAWSZ];
1951
- struct pathspec pathspec;
1985
1986
head_tree = parse_tree_indirect(head);
1987
if (!head_tree)
2006
if (fast_forward_to(index_tree, remote_tree, 0))
2007
return -1;
2008
1976
- memset(&pathspec, 0, sizeof(pathspec));
1977
-
1978
- lock_file = xcalloc(1, sizeof(struct lock_file));
1979
- hold_locked_index(lock_file, 1);
1980
-
1981
- if (read_tree(remote_tree, 0, &pathspec)) {
1982
- rollback_lock_file(lock_file);
2009
+ if (merge_tree(remote_tree))
2010
return -1;
1984
- }
1985
-
1986
- if (write_locked_index(&the_index, lock_file, COMMIT_LOCK))
1987
- die(_("unable to write new index file"));
2011
2012
remove_branch_state();
2013