3 #include "run-command.h"
4 #include "resolve-undo.h"
6 #include "unpack-trees.h"
9 static const char *merge_argument(struct commit
*commit
)
12 return sha1_to_hex(commit
->object
.sha1
);
14 return EMPTY_TREE_SHA1_HEX
;
17 int try_merge_command(const char *strategy
, size_t xopts_nr
,
18 const char **xopts
, struct commit_list
*common
,
19 const char *head_arg
, struct commit_list
*remotes
)
22 int i
= 0, x
= 0, ret
;
23 struct commit_list
*j
;
24 struct strbuf buf
= STRBUF_INIT
;
26 args
= xmalloc((4 + xopts_nr
+ commit_list_count(common
) +
27 commit_list_count(remotes
)) * sizeof(char *));
28 strbuf_addf(&buf
, "merge-%s", strategy
);
30 for (x
= 0; x
< xopts_nr
; x
++) {
31 char *s
= xmalloc(strlen(xopts
[x
])+2+1);
33 strcpy(s
+2, xopts
[x
]);
36 for (j
= common
; j
; j
= j
->next
)
37 args
[i
++] = xstrdup(merge_argument(j
->item
));
40 for (j
= remotes
; j
; j
= j
->next
)
41 args
[i
++] = xstrdup(merge_argument(j
->item
));
43 ret
= run_command_v_opt(args
, RUN_GIT_CMD
);
46 for (x
= 0; x
< xopts_nr
; x
++)
47 free((void *)args
[i
++]);
48 for (j
= common
; j
; j
= j
->next
)
49 free((void *)args
[i
++]);
51 for (j
= remotes
; j
; j
= j
->next
)
52 free((void *)args
[i
++]);
56 die(_("failed to read the cache"));
62 int checkout_fast_forward(const unsigned char *head
,
63 const unsigned char *remote
,
66 struct tree
*trees
[MAX_UNPACK_TREES
];
67 struct unpack_trees_options opts
;
68 struct tree_desc t
[MAX_UNPACK_TREES
];
70 struct dir_struct dir
;
71 struct lock_file
*lock_file
= xcalloc(1, sizeof(struct lock_file
));
73 refresh_cache(REFRESH_QUIET
);
75 hold_locked_index(lock_file
, 1);
77 memset(&trees
, 0, sizeof(trees
));
78 memset(&opts
, 0, sizeof(opts
));
79 memset(&t
, 0, sizeof(t
));
80 if (overwrite_ignore
) {
81 memset(&dir
, 0, sizeof(dir
));
82 dir
.flags
|= DIR_SHOW_IGNORED
;
83 setup_standard_excludes(&dir
);
88 opts
.src_index
= &the_index
;
89 opts
.dst_index
= &the_index
;
91 opts
.verbose_update
= 1;
93 opts
.fn
= twoway_merge
;
94 setup_unpack_trees_porcelain(&opts
, "merge");
96 trees
[nr_trees
] = parse_tree_indirect(head
);
97 if (!trees
[nr_trees
++])
99 trees
[nr_trees
] = parse_tree_indirect(remote
);
100 if (!trees
[nr_trees
++])
102 for (i
= 0; i
< nr_trees
; i
++) {
103 parse_tree(trees
[i
]);
104 init_tree_desc(t
+i
, trees
[i
]->buffer
, trees
[i
]->size
);
106 if (unpack_trees(nr_trees
, t
, &opts
))
108 if (write_locked_index(&the_index
, lock_file
, COMMIT_LOCK
))
109 die(_("unable to write new index file"));