Skip to content

Commit 55dcc17

Browse files
committed
aggressive_tree_merge: fixed incorrect handling of one branch, it was just not implemented causing incorrect merge results. Added test to cover this issue
Diff: added NULL_BIN_SHA constant for completeness
1 parent 129f90a commit 55dcc17

File tree

6 files changed

+45
-7
lines changed

6 files changed

+45
-7
lines changed

CHANGES

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ CHANGES
66
* ConcurrentWriteOperation was removed, and replaced by LockedFD
77
* IndexFile.get_entries_key was renamed to entry_key
88
* IndexEntry instances contained in IndexFile.entries now use binary sha's. Use
9-
the .hexsha property to obtain the hexadecimal version
9+
the .hexsha property to obtain the hexadecimal version. The .sha property
10+
was removed to make the use of the respective sha more explicit.
1011
* IndexFile.write_tree: removed missing_ok keyword, its always True now
1112
Instead of raising GitCommandError it raises UnmergedEntriesError
1213
* diff.Diff.null_hex_sha renamed to NULL_HEX_SHA, to be conforming with

lib/git/diff.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ class Diff(object):
197197
""", re.VERBOSE | re.MULTILINE)
198198
# can be used for comparisons
199199
NULL_HEX_SHA = "0"*40
200+
NULL_BIN_SHA = "\0"*20
200201

201202
__slots__ = ("a_blob", "b_blob", "a_mode", "b_mode", "new_file", "deleted_file",
202203
"rename_from", "rename_to", "diff")

lib/git/ext/gitdb

Submodule gitdb updated from 9b53ab0 to d3a0037

lib/git/index/base.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -530,9 +530,7 @@ def write_tree(self):
530530
:raise ValueError: if there are no entries in the cache
531531
:raise UnmergedEntriesError: """
532532
# we obtain no lock as we just flush our contents to disk as tree
533-
if not self.entries:
534-
raise ValueError("Cannot write empty index")
535-
533+
# If we are a new index, the entries access will load our data accordingly
536534
mdb = MemoryDB()
537535
entries = self._entries_sorted()
538536
binsha, tree_items = write_tree_from_cache(entries, mdb, slice(0, len(entries)))
@@ -892,7 +890,6 @@ def move(self, items, skip_errors=False, **kwargs):
892890

893891
return out
894892

895-
@default_index
896893
def commit(self, message, parent_commits=None, head=True):
897894
"""
898895
Commit the current default index file, creating a commit object.

lib/git/index/fun.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,16 @@ def aggressive_tree_merge(odb, tree_shas):
283283
elif theirs is None:
284284
# added in our branch
285285
out_append(_tree_entry_to_baseindexentry(ours, 0))
286-
# END hanle heads
286+
else:
287+
# both have it, except for the base, see whether it changed
288+
if ours[0] != theirs[0] or ours[1] != theirs[1]:
289+
out_append(_tree_entry_to_baseindexentry(ours, 2))
290+
out_append(_tree_entry_to_baseindexentry(theirs, 3))
291+
else:
292+
# it was added the same in both
293+
out_append(_tree_entry_to_baseindexentry(ours, 0))
294+
# END handle two items
295+
# END handle heads
287296
# END handle base exists
288297
# END for each entries tuple
289298

test/git/test_fun.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,36 @@ def assert_entries(entries, num_entries, has_conflict=False):
114114
trees = [tb, th, tm]
115115
assert_entries(aggressive_tree_merge(odb, trees), 2)
116116

117+
# same file added in both, differently
118+
fa = mkfile('1', shab)
119+
th = mktree(odb, [fa])
120+
fb = mkfile('1', shac)
121+
tm = mktree(odb, [fb])
122+
123+
# expect conflict
124+
trees = [tb, th, tm]
125+
assert_entries(aggressive_tree_merge(odb, trees), 2, True)
126+
127+
# same file added, different mode
128+
fa = mkfile('1', shab)
129+
th = mktree(odb, [fa])
130+
fb = mkcommit('1', shab)
131+
tm = mktree(odb, [fb])
132+
133+
# expect conflict
134+
trees = [tb, th, tm]
135+
assert_entries(aggressive_tree_merge(odb, trees), 2, True)
136+
137+
# same file added in both
138+
fa = mkfile('1', shab)
139+
th = mktree(odb, [fa])
140+
fb = mkfile('1', shab)
141+
tm = mktree(odb, [fb])
142+
143+
# expect conflict
144+
trees = [tb, th, tm]
145+
assert_entries(aggressive_tree_merge(odb, trees), 1)
146+
117147
# modify same base file, differently
118148
fa = mkfile(bfn, shab)
119149
th = mktree(odb, [fa])

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy