~bzr-pqm/bzr/bzr.dev

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python
"""\
This contains the apply changset function for bzr
"""

import bzrlib

def apply_changeset(branch, from_file, reverse=False, auto_commit=False):
    from bzrlib.changeset import apply_changeset as _apply_changeset
    from bzrlib.merge import regen_inventory
    import sys, read_changeset


    cset_info = read_changeset.read_changeset(from_file)
    cset = cset_info.get_changeset()
    inv = {}
    for file_id in branch.inventory:
        inv[file_id] = branch.inventory.id2path(file_id)
    changes = _apply_changeset(cset, inv, branch.base,
            reverse=reverse)

    adjust_ids = []
    for id, path in changes.iteritems():
        if path is not None:
            if path == '.':
                path = ''
        adjust_ids.append((path, id))

    branch.set_inventory(regen_inventory(branch, branch.base, adjust_ids))

    if auto_commit:
        from bzrlib.commit import commit
        if branch.last_patch() == cset_info.precursor:
            # This patch can be applied directly
            commit(branch, message = cset_info.message,
                    timestamp=float(cset_info.timestamp),
                    timezone=float(cset_info.timezone),
                    committer=cset_info.committer,
                    rev_id=cset_info.revision)