~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to apply_changeset.py

  • Committer: John Arbash Meinel
  • Date: 2005-06-20 05:06:06 UTC
  • mto: (0.5.85) (1185.82.1 bzr-w-changeset)
  • mto: This revision was merged to the branch mainline in revision 1738.
  • Revision ID: john@arbash-meinel.com-20050620050606-75e09678cc5ea0aa
adding apply-changset, plus more meta information.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
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