/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/uncommit.py

Add finished() notifications to transactions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
import os
7
7
import bzrlib
8
 
from bzrlib.errors import BoundBranchOutOfDate
9
8
 
10
9
def test_remove(filename):
11
10
    if os.path.exists(filename):
22
21
    :param revno: Remove back to this revision
23
22
    """
24
23
    from bzrlib.atomicfile import AtomicFile
25
 
    unlockable = []
26
 
    try:
 
24
    rh = branch.revision_history()
 
25
    if revno is None:
 
26
        revno = len(rh)
 
27
 
 
28
    files_to_remove = []
 
29
    new_rev_history = AtomicFile(branch.control_files.controlfilename('revision-history'))
 
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
 
 
35
    new_rev_history.write('\n'.join(rh))
 
36
 
 
37
    # Committing before we start removing files, because
 
38
    # once we have removed at least one, all the rest are invalid.
 
39
    if not dry_run:
 
40
        new_rev_history.commit()
27
41
        if tree is not None:
28
 
            tree.lock_write()
29
 
            unlockable.append(tree)
30
 
        
31
 
        branch.lock_write()
32
 
        unlockable.append(branch)
33
 
 
34
 
        master = branch.get_master_branch()
35
 
        if master is not None:
36
 
            master.lock_write()
37
 
            unlockable.append(master)
38
 
        rh = branch.revision_history()
39
 
        if master is not None and rh[-1] != master.last_revision():
40
 
            raise BoundBranchOutOfDate(branch, master)
41
 
        if revno is None:
42
 
            revno = len(rh)
43
 
 
44
 
        files_to_remove = []
45
 
        for r in range(revno-1, len(rh)):
46
 
            rev_id = rh.pop()
47
 
            if verbose:
48
 
                print 'Removing revno %d: %s' % (len(rh)+1, rev_id)
49
 
 
50
 
 
51
 
        # Committing before we start removing files, because
52
 
        # once we have removed at least one, all the rest are invalid.
53
 
        if not dry_run:
54
 
            if master is not None:
55
 
                master.set_revision_history(rh)
56
 
            branch.set_revision_history(rh)
57
 
            if tree is not None:
58
 
                tree.set_last_revision(branch.last_revision())
59
 
    finally:
60
 
        for item in reversed(unlockable):
61
 
            item.unlock()
 
42
            tree.set_last_revision(branch.last_revision())
 
43
    else:
 
44
        new_rev_history.abort()
 
45
 
 
46