Merge branch 'jk/merge-tree-added-identically'

The resolution of some corner cases by "git merge-tree" were
inconsistent between top-of-the-tree and in a subdirectory.

* jk/merge-tree-added-identically:
  merge-tree: don't print entries that match "local"
This commit is contained in:
Junio C Hamano
2013-04-18 11:49:31 -07:00
2 changed files with 13 additions and 23 deletions

View File

@ -155,6 +155,11 @@ static int same_entry(struct name_entry *a, struct name_entry *b)
a->mode == b->mode; a->mode == b->mode;
} }
static int both_empty(struct name_entry *a, struct name_entry *b)
{
return !(a->sha1 || b->sha1);
}
static struct merge_list *create_entry(unsigned stage, unsigned mode, const unsigned char *sha1, const char *path) static struct merge_list *create_entry(unsigned stage, unsigned mode, const unsigned char *sha1, const char *path)
{ {
struct merge_list *res = xcalloc(1, sizeof(*res)); struct merge_list *res = xcalloc(1, sizeof(*res));
@ -297,14 +302,11 @@ static void unresolved(const struct traverse_info *info, struct name_entry n[3])
static int threeway_callback(int n, unsigned long mask, unsigned long dirmask, struct name_entry *entry, struct traverse_info *info) static int threeway_callback(int n, unsigned long mask, unsigned long dirmask, struct name_entry *entry, struct traverse_info *info)
{ {
/* Same in both? */ /* Same in both? */
if (same_entry(entry+1, entry+2)) { if (same_entry(entry+1, entry+2) || both_empty(entry+0, entry+2)) {
if (entry[0].sha1) { /* Modified, added or removed identically */
/* Modified identically */
resolve(info, NULL, entry+1); resolve(info, NULL, entry+1);
return mask; return mask;
} }
/* "Both added the same" is left unresolved */
}
if (same_entry(entry+0, entry+1)) { if (same_entry(entry+0, entry+1)) {
if (entry[2].sha1 && !S_ISDIR(entry[2].mode)) { if (entry[2].sha1 && !S_ISDIR(entry[2].mode)) {
@ -319,13 +321,11 @@ static int threeway_callback(int n, unsigned long mask, unsigned long dirmask, s
*/ */
} }
if (same_entry(entry+0, entry+2)) { if (same_entry(entry+0, entry+2) || both_empty(entry+0, entry+2)) {
if (entry[1].sha1 && !S_ISDIR(entry[1].mode)) { /* We added, modified or removed, they did not touch -- take ours */
/* We modified, they did not touch -- take ours */
resolve(info, NULL, entry+1); resolve(info, NULL, entry+1);
return mask; return mask;
} }
}
unresolved(info, entry); unresolved(info, entry);
return mask; return mask;

View File

@ -26,8 +26,6 @@ EXPECTED
test_expect_success 'file add !A, B' ' test_expect_success 'file add !A, B' '
cat >expected <<\EXPECTED && cat >expected <<\EXPECTED &&
added in local
our 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
EXPECTED EXPECTED
git reset --hard initial && git reset --hard initial &&
@ -38,9 +36,6 @@ EXPECTED
test_expect_success 'file add A, B (same)' ' test_expect_success 'file add A, B (same)' '
cat >expected <<\EXPECTED && cat >expected <<\EXPECTED &&
added in both
our 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
their 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
EXPECTED EXPECTED
git reset --hard initial && git reset --hard initial &&
@ -181,9 +176,6 @@ AAA" &&
test_expect_success 'file remove A, !B' ' test_expect_success 'file remove A, !B' '
cat >expected <<\EXPECTED && cat >expected <<\EXPECTED &&
removed in local
base 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
their 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
EXPECTED EXPECTED
git reset --hard initial && git reset --hard initial &&
@ -283,8 +275,6 @@ test_expect_success 'turn tree to file' '
test_commit "make-file" "dir" "CCC" && test_commit "make-file" "dir" "CCC" &&
git merge-tree add-tree add-another-tree make-file >actual && git merge-tree add-tree add-another-tree make-file >actual &&
cat >expect <<-\EOF && cat >expect <<-\EOF &&
added in local
our 100644 ba629238ca89489f2b350e196ca445e09d8bb834 dir/another
removed in remote removed in remote
base 100644 43d5a8ed6ef6c00ff775008633f95787d088285d dir/path base 100644 43d5a8ed6ef6c00ff775008633f95787d088285d dir/path
our 100644 43d5a8ed6ef6c00ff775008633f95787d088285d dir/path our 100644 43d5a8ed6ef6c00ff775008633f95787d088285d dir/path