Skip to content

Commit aacecc3

Browse files
johnkeepinggitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 187c00c commit aacecc3

File tree

2 files changed

+13
-23
lines changed

2 files changed

+13
-23
lines changed

builtin/merge-tree.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ static int same_entry(struct name_entry *a, struct name_entry *b)
155155
a->mode == b->mode;
156156
}
157157

158+
static int both_empty(struct name_entry *a, struct name_entry *b)
159+
{
160+
return !(a->sha1 || b->sha1);
161+
}
162+
158163
static struct merge_list *create_entry(unsigned stage, unsigned mode, const unsigned char *sha1, const char *path)
159164
{
160165
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])
297302
static int threeway_callback(int n, unsigned long mask, unsigned long dirmask, struct name_entry *entry, struct traverse_info *info)
298303
{
299304
/* 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;
307309
}
308310

309311
if (same_entry(entry+0, entry+1)) {
@@ -319,12 +321,10 @@ static int threeway_callback(int n, unsigned long mask, unsigned long dirmask, s
319321
*/
320322
}
321323

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;
328328
}
329329

330330
unresolved(info, entry);

t/t4300-merge-tree.sh

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ EXPECTED
2626

2727
test_expect_success 'file add !A, B' '
2828
cat >expected <<\EXPECTED &&
29-
added in local
30-
our 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
3129
EXPECTED
3230
3331
git reset --hard initial &&
@@ -38,9 +36,6 @@ EXPECTED
3836

3937
test_expect_success 'file add A, B (same)' '
4038
cat >expected <<\EXPECTED &&
41-
added in both
42-
our 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
43-
their 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
4439
EXPECTED
4540
4641
git reset --hard initial &&
@@ -181,9 +176,6 @@ AAA" &&
181176

182177
test_expect_success 'file remove A, !B' '
183178
cat >expected <<\EXPECTED &&
184-
removed in local
185-
base 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
186-
their 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
187179
EXPECTED
188180
189181
git reset --hard initial &&
@@ -283,8 +275,6 @@ test_expect_success 'turn tree to file' '
283275
test_commit "make-file" "dir" "CCC" &&
284276
git merge-tree add-tree add-another-tree make-file >actual &&
285277
cat >expect <<-\EOF &&
286-
added in local
287-
our 100644 ba629238ca89489f2b350e196ca445e09d8bb834 dir/another
288278
removed in remote
289279
base 100644 43d5a8ed6ef6c00ff775008633f95787d088285d dir/path
290280
our 100644 43d5a8ed6ef6c00ff775008633f95787d088285d dir/path

0 commit comments

Comments
 (0)