819
821
# two loops so that we do not change ourselves before verifying it
821
823
# work through in index order to make sure we get all dependencies
822
826
for other_idx, name in enumerate(other._names):
823
827
self._check_version_consistent(other, other_idx, name)
828
sha1 = other._sha1s[other_idx]
832
if name in self._name_map:
833
idx = self.lookup(name)
834
n1 = set(map(other.idx_to_name, other._parents[other_idx]))
835
n2 = set(map(self.idx_to_name, self._parents[idx]))
836
if sha1 == self._sha1s[idx] and n1 == n2:
839
names_to_join.append((other_idx, name))
825
841
if pb and not msg:
826
842
msg = 'weave join'
830
845
time0 = time.time( )
831
for other_idx, name in enumerate(other._names):
846
for other_idx, name in names_to_join:
832
847
# TODO: If all the parents of the other version are already
833
848
# present then we can avoid some work by just taking the delta
834
849
# and adjusting the offsets.
835
850
new_parents = self._imported_parents(other, other_idx)
836
851
sha1 = other._sha1s[other_idx]
840
if name in self._name_map:
841
idx = self.lookup(name)
842
n1 = set(map(other.idx_to_name, other._parents[other_idx]))
843
n2 = set(map(self.idx_to_name, self._parents[idx]))
844
if sha1 == self._sha1s[idx] and n1 == n2:
848
pb.update(msg, other_idx, len(other._names))
856
pb.update(msg, merged, len(names_to_join))
851
858
lines = other.get_lines(other_idx)
852
859
self.add(name, new_parents, lines, sha1)
854
861
mutter("merged = %d, processed = %d, file_id=%s; deltat=%d"%(
855
merged,processed,self._weave_name, time.time( )-time0))
862
merged, processed, self._weave_name, time.time( )-time0))
860
864
def _imported_parents(self, other, other_idx):
861
865
"""Return list of parents in self corresponding to indexes in other."""