tree-less merges

Michael Hudson michael.hudson at canonical.com
Tue Nov 20 10:25:55 GMT 2007


I have a need (for a submission script/pending reviews page; I guess
send/bundle buggy could conceivably use something like this) to
compute the 'diff as merged' between two branches, i.e. given branches
A and B, the output of bzr diff in A after merging B into it.  This
function gives me that:

def get_diff_as_merged(target_branch, merge_source_branch, to_file):
    """Compute the diff that would result from merging one branch into another.
    """
    tmpdir = tempfile.mkdtemp()
    try:
        branchdir = os.path.join(tmpdir, 'target')
        target_branch.create_checkout(branchdir, lightweight=True)
        tree = WorkingTree.open(branchdir)
        merger = Merger.from_revision_ids(
            DummyProgress(), tree,
            merge_source_branch.last_revision(),
            None, merge_source_branch, merge_source_branch)
        merger.merge_type = Merge3Merger
        merger.ignore_zero = True
        conflict_count = merger.do_merge()
        show_diff_trees(tree.basis_tree(), tree, to_file)
    finally:
        shutil.rmtree(tmpdir)

This works (though I really shouldn't ignore the conflict_count...)
but it is disproportionately slow with small changes to large trees
because of the checkout.  So I'd like a way to do it that only did
work proportional to the changes, not proportional to the tree, and
not requiring a tree at all seems like a good way of getting there.  I
don't particularly care about not hitting the disk at all or not
keeping the full texts of all changed files in RAM, but these would be
nice things of course.

I talked to John and Robert a bit about this in #bzr.  John suggested
creating a LazyWorkingTree type (which had been my first thought too),
but Robert (and Aaron overnight) suggested that subclassing Merger or
TreeTransform might work better instead.  This makes sense to me, but
both transform.py and merge.py make my head hurt[1], so I'd really
appreciate a few hints as to where to start with this.

It looks a bit to me that it will probably require changes to core
bzr, afaict.

Cheers,
mwh

[1] For something very simple, the fact that there's no subclass
    relationship between Merger and Merge3Merger is pretty confusing.
    Should one of them be renamed?  Merger could become MergeDirector,
    perhaps?



More information about the bazaar mailing list