~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/uncommit.py

  • Committer: Robert Collins
  • Date: 2006-03-11 13:58:48 UTC
  • mto: (1615.1.2 bzr.mbp.integration)
  • mto: This revision was merged to the branch mainline in revision 1616.
  • Revision ID: robertc@robertcollins.net-20060311135848-789fa616b8da4662
Note potential improvements in knit adds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
16
def uncommit(branch, dry_run=False, verbose=False, revno=None, tree=None):
 
17
    """Remove the last revision from the supplied branch.
 
18
 
 
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
 
22
    """
 
23
    from bzrlib.atomicfile import AtomicFile
 
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()
 
41
        if tree is not None:
 
42
            tree.set_last_revision(branch.last_revision())
 
43
    else:
 
44
        new_rev_history.abort()
 
45
 
 
46