18
18
"""Merge strategies."""
19
19
20
20
import os
21
+ import shutil
21
22
from json import JSONDecodeError
22
23
from pathlib import Path
23
24
from tempfile import mkdtemp
24
25
from typing import List , NamedTuple , Optional , Union , cast
25
26
26
- from BTrees .OOBTree import BTree , TreeSet
27
+ from BTrees .OOBTree import BTree , Bucket , TreeSet
27
28
from deepdiff import DeepDiff
28
29
from persistent import Persistent
29
30
from persistent .list import PersistentList
@@ -86,6 +87,7 @@ def merge(self, local: Path, remote: Path, base: Path) -> None:
86
87
# NOTE: cleanup worktrees
87
88
for entry in self .remote_entries :
88
89
client .repository .remove_worktree (entry .path )
90
+ shutil .rmtree (entry .path , ignore_errors = True )
89
91
90
92
if not merged :
91
93
raise errors .MetadataMergeError ("Couldn't merge metadata: remote object not found in merge branches." )
@@ -128,7 +130,7 @@ def merge_objects(self, local: Persistent, remote: Persistent, base: Optional[Pe
128
130
"""Merge two database objects."""
129
131
if type (local ) != type (remote ):
130
132
raise errors .MetadataMergeError (f"Cannot merge { local } and { remote } : disparate types." )
131
- if isinstance (local , (BTree , Index )):
133
+ if isinstance (local , (BTree , Index , Bucket )):
132
134
return self .merge_btrees (local , remote )
133
135
elif isinstance (local , TreeSet ):
134
136
return self .merge_treesets (local , remote )
@@ -141,7 +143,9 @@ def merge_objects(self, local: Persistent, remote: Persistent, base: Optional[Pe
141
143
f"Cannot merge { local } and { remote } : type not supported for automated merge."
142
144
)
143
145
144
- def merge_btrees (self , local : Union [BTree , Index ], remote : Union [BTree , Index ]) -> Union [BTree , Index ]:
146
+ def merge_btrees (
147
+ self , local : Union [BTree , Index , Bucket ], remote : Union [BTree , Index , Bucket ]
148
+ ) -> Union [BTree , Index , Bucket ]:
145
149
"""Merge two BTrees."""
146
150
local_key_ids = {k : getattr (v , "_p_oid" , None ) for k , v in local .items ()}
147
151
remote_key_ids = {k : getattr (v , "_p_oid" , None ) for k , v in remote .items ()}
0 commit comments