/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.3.1 by John Arbash Meinel
Creating a plugin for uncommitting the last revision.
1
#!/usr/bin/env python
2
"""\
3
Remove the last revision from the history of the current branch.
4
"""
5
6
import os
7
import bzrlib
8
9
def test_remove(filename):
10
    if os.path.exists(filename):
11
        os.remove(filename)
12
    else:
13
        print '* file does not exist: %r' % filename
14
15
1185.62.10 by John Arbash Meinel
Removed --all from bzr uncommit, it was broken anyway.
16
def uncommit(branch, dry_run=False, verbose=False, revno=None):
0.3.1 by John Arbash Meinel
Creating a plugin for uncommitting the last revision.
17
    """Remove the last revision from the supplied branch.
18
1185.62.10 by John Arbash Meinel
Removed --all from bzr uncommit, it was broken anyway.
19
    :param dry_run: Don't actually change anything
20
    :param verbose: Print each step as you do it
21
    :param revno: Remove back to this revision
0.3.1 by John Arbash Meinel
Creating a plugin for uncommitting the last revision.
22
    """
23
    from bzrlib.atomicfile import AtomicFile
24
    rh = branch.revision_history()
0.3.6 by John Arbash Meinel
Adding ability to revert back to earlier revisions.
25
    if revno is None:
26
        revno = len(rh)
0.3.1 by John Arbash Meinel
Creating a plugin for uncommitting the last revision.
27
0.3.6 by John Arbash Meinel
Adding ability to revert back to earlier revisions.
28
    files_to_remove = []
0.3.1 by John Arbash Meinel
Creating a plugin for uncommitting the last revision.
29
    new_rev_history = AtomicFile(branch.controlfilename('revision-history'))
0.3.6 by John Arbash Meinel
Adding ability to revert back to earlier revisions.
30
    for r in range(revno-1, len(rh)):
31
        rev_id = rh.pop()
32
        if verbose:
33
            print 'Removing revno %d: %s' % (len(rh)+1, rev_id)
34
        rev = branch.get_revision(rev_id)
0.3.9 by John Arbash Meinel
Upgrading plugin for v5
35
        inv = branch.get_revision_inventory(rev_id)
0.3.6 by John Arbash Meinel
Adding ability to revert back to earlier revisions.
36
        inv_prev = []
0.3.9 by John Arbash Meinel
Upgrading plugin for v5
37
        for p in rev.parent_ids:
38
            inv_prev.append(branch.get_revision_inventory(p))
0.3.6 by John Arbash Meinel
Adding ability to revert back to earlier revisions.
39
0.3.1 by John Arbash Meinel
Creating a plugin for uncommitting the last revision.
40
    new_rev_history.write('\n'.join(rh))
0.3.6 by John Arbash Meinel
Adding ability to revert back to earlier revisions.
41
42
    # Committing before we start removing files, because
0.3.1 by John Arbash Meinel
Creating a plugin for uncommitting the last revision.
43
    # once we have removed at least one, all the rest are invalid.
44
    if not dry_run:
45
        new_rev_history.commit()
0.3.6 by John Arbash Meinel
Adding ability to revert back to earlier revisions.
46
    else:
47
        new_rev_history.abort()
48
49