/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

  • Committer: Michael Ellerman
  • Date: 2006-03-09 00:24:48 UTC
  • mto: (1610.1.8 bzr.mbp.integration)
  • mto: This revision was merged to the branch mainline in revision 1616.
  • Revision ID: michael@ellerman.id.au-20060309002448-70cce15e3d605130
Make the "ignore line" in the commit message editor the "right" width, so
that if you make your message that wide it won't wrap in bzr log output.
Just as a visual aid.

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