merge-tree: provide a list of which files have conflicts
Callers of `git merge-tree --write-tree` will often want to know which files had conflicts. While they could potentially attempt to parse the CONFLICT notices printed, those messages are not meant to be machine readable. Provide a simpler mechanism of just printing the files (in the same format as `git ls-files` with quoting, but restricted to unmerged files) in the output before the free-form messages. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
a4040cfa35
commit
7fa3338870
@ -11,6 +11,9 @@
|
||||
#include "blob.h"
|
||||
#include "exec-cmd.h"
|
||||
#include "merge-blobs.h"
|
||||
#include "quote.h"
|
||||
|
||||
static int line_termination = '\n';
|
||||
|
||||
struct merge_list {
|
||||
struct merge_list *next;
|
||||
@ -400,7 +403,8 @@ struct merge_tree_options {
|
||||
};
|
||||
|
||||
static int real_merge(struct merge_tree_options *o,
|
||||
const char *branch1, const char *branch2)
|
||||
const char *branch1, const char *branch2,
|
||||
const char *prefix)
|
||||
{
|
||||
struct commit *parent1, *parent2;
|
||||
struct commit_list *merge_bases = NULL;
|
||||
@ -441,8 +445,24 @@ static int real_merge(struct merge_tree_options *o,
|
||||
o->show_messages = !result.clean;
|
||||
|
||||
puts(oid_to_hex(&result.tree->object.oid));
|
||||
if (!result.clean) {
|
||||
struct string_list conflicted_files = STRING_LIST_INIT_NODUP;
|
||||
const char *last = NULL;
|
||||
int i;
|
||||
|
||||
merge_get_conflicted_files(&result, &conflicted_files);
|
||||
for (i = 0; i < conflicted_files.nr; i++) {
|
||||
const char *name = conflicted_files.items[i].string;
|
||||
if (last && !strcmp(last, name))
|
||||
continue;
|
||||
write_name_quoted_relative(
|
||||
name, prefix, stdout, line_termination);
|
||||
last = name;
|
||||
}
|
||||
string_list_clear(&conflicted_files, 1);
|
||||
}
|
||||
if (o->show_messages) {
|
||||
printf("\n");
|
||||
putchar(line_termination);
|
||||
merge_display_update_messages(&opt, &result);
|
||||
}
|
||||
merge_finalize(&opt, &result);
|
||||
@ -508,7 +528,7 @@ int cmd_merge_tree(int argc, const char **argv, const char *prefix)
|
||||
|
||||
/* Do the relevant type of merge */
|
||||
if (o.mode == MODE_REAL)
|
||||
return real_merge(&o, argv[0], argv[1]);
|
||||
return real_merge(&o, argv[0], argv[1], prefix);
|
||||
else
|
||||
return trivial_merge(argv[0], argv[1], argv[2]);
|
||||
}
|
||||
|
Reference in New Issue
Block a user