merge-tree: don't print entries that match "local"

The documentation says: the output from the command omits entries that match the <branch1> tree. But currently "added in branch1" and "removed in branch1" (both while unchanged in branch2) do print output. Change this so that the behaviour matches the documentation. Signed-off-by: John Keeping <john@keeping.me.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>

John Keeping committed Apr 7, 2013 at 22:07 UTC aacecc3b36a6cd4d2707e3f1cbd7bb4122477c64
2 files changed +13 -23
builtin/merge-tree.c
+13 -13
@@ -155,6 +155,11 @@ static int same_entry(struct name_entry *a, struct name_entry *b)
155 a->mode == b->mode;
156 }
157
158 +static int both_empty(struct name_entry *a, struct name_entry *b)
159 +{
160 + return !(a->sha1 || b->sha1);
161 +}
162 +
163 static struct merge_list *create_entry(unsigned stage, unsigned mode, const unsigned char *sha1, const char *path)
164 {
165 struct merge_list *res = xcalloc(1, sizeof(*res));
@@ -297,13 +302,10 @@ static void unresolved(const struct traverse_info *info, struct name_entry n[3])
302 static int threeway_callback(int n, unsigned long mask, unsigned long dirmask, struct name_entry *entry, struct traverse_info *info)
303 {
304 /* Same in both? */
300 - if (same_entry(entry+1, entry+2)) {
301 - if (entry[0].sha1) {
302 - /* Modified identically */
303 - resolve(info, NULL, entry+1);
304 - return mask;
305 - }
306 - /* "Both added the same" is left unresolved */
305 + if (same_entry(entry+1, entry+2) || both_empty(entry+0, entry+2)) {
306 + /* Modified, added or removed identically */
307 + resolve(info, NULL, entry+1);
308 + return mask;
309 }
310
311 if (same_entry(entry+0, entry+1)) {
@@ -319,12 +321,10 @@ static int threeway_callback(int n, unsigned long mask, unsigned long dirmask, s
321 */
322 }
323
322 - if (same_entry(entry+0, entry+2)) {
323 - if (entry[1].sha1 && !S_ISDIR(entry[1].mode)) {
324 - /* We modified, they did not touch -- take ours */
325 - resolve(info, NULL, entry+1);
326 - return mask;
327 - }
324 + if (same_entry(entry+0, entry+2) || both_empty(entry+0, entry+2)) {
325 + /* We added, modified or removed, they did not touch -- take ours */
326 + resolve(info, NULL, entry+1);
327 + return mask;
328 }
329
330 unresolved(info, entry);
t/t4300-merge-tree.sh
-10
@@ -26,8 +26,6 @@ EXPECTED
26
27 test_expect_success 'file add !A, B' '
28 cat >expected <<\EXPECTED &&
29 -added in local
30 - our 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
29 EXPECTED
30
31 git reset --hard initial &&
@@ -38,9 +36,6 @@ EXPECTED
36
37 test_expect_success 'file add A, B (same)' '
38 cat >expected <<\EXPECTED &&
41 -added in both
42 - our 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
43 - their 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
39 EXPECTED
40
41 git reset --hard initial &&
@@ -181,9 +176,6 @@ AAA" &&
176
177 test_expect_success 'file remove A, !B' '
178 cat >expected <<\EXPECTED &&
184 -removed in local
185 - base 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
186 - their 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
179 EXPECTED
180
181 git reset --hard initial &&
@@ -283,8 +275,6 @@ test_expect_success 'turn tree to file' '
275 test_commit "make-file" "dir" "CCC" &&
276 git merge-tree add-tree add-another-tree make-file >actual &&
277 cat >expect <<-\EOF &&
286 - added in local
287 - our 100644 ba629238ca89489f2b350e196ca445e09d8bb834 dir/another
278 removed in remote
279 base 100644 43d5a8ed6ef6c00ff775008633f95787d088285d dir/path
280 our 100644 43d5a8ed6ef6c00ff775008633f95787d088285d dir/path