~bzr-pqm/bzr/bzr.dev

757 by Martin Pool
- add john's changeset plugin
1
#!/usr/bin/env python
2
"""\
3
This contains the apply changset function for bzr
4
"""
5
6
import bzrlib
7
8
def apply_changeset(branch, from_file, reverse=False, auto_commit=False):
9
    from bzrlib.changeset import apply_changeset as _apply_changeset
10
    from bzrlib.merge import regen_inventory
11
    import sys, read_changeset
12
13
14
    cset_info = read_changeset.read_changeset(from_file)
15
    cset = cset_info.get_changeset()
16
    inv = {}
17
    for file_id in branch.inventory:
18
        inv[file_id] = branch.inventory.id2path(file_id)
19
    changes = _apply_changeset(cset, inv, branch.base,
20
            reverse=reverse)
21
22
    adjust_ids = []
23
    for id, path in changes.iteritems():
24
        if path is not None:
25
            if path == '.':
26
                path = ''
27
        adjust_ids.append((path, id))
28
29
    branch.set_inventory(regen_inventory(branch, branch.base, adjust_ids))
30
31
    if auto_commit:
32
        from bzrlib.commit import commit
33
        if branch.last_patch() == cset_info.precursor:
34
            # This patch can be applied directly
35
            commit(branch, message = cset_info.message,
36
                    timestamp=float(cset_info.timestamp),
37
                    timezone=float(cset_info.timezone),
38
                    committer=cset_info.committer,
39
                    rev_id=cset_info.revision)
40
41