/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python
"""\
Remove the last committed revision.
Does not modify the working tree, use 'bzr revert' for that.
"""

import bzrlib, bzrlib.commands

class cmd_uncommit(bzrlib.commands.Command):
    """Remove the last committed revision.

    By supplying the --remove flag, it will not only remove the entry 
    from revision_history, but also remove all of the entries in the
    stores.

    --verbose will print out what is being removed.
    --dry-run will go through all the motions, but not actually
    remove anything.
    
    In the future, uncommit will create a changeset, which can then
    be re-applied.
    """
    takes_options = ['remove', 'dry-run', 'verbose', 'revision']
    takes_args = ['location?']
    aliases = []

    def run(self, location=None, remove=False,
            dry_run=False, verbose=False,
            revision=None):
        from bzrlib.branch import Branch
        from bzrlib.log import log_formatter
        import uncommit, sys

        if location is None:
            location = '.'
        b = Branch.open_containing(location)

        if revision is None:
            revno = b.revno()
            rev_id = b.last_patch()
        else:
            revno, rev_id = revision[0].in_history(b)
        if rev_id is None:
            print 'No revisions to uncommit.'

        for r in range(revno, b.revno()+1):
            rev_id = b.get_rev_id(revno)
            lf = log_formatter('short', to_file=sys.stdout,show_timezone='original')
            lf.show(r, b.get_revision(rev_id), None)

        print 'The above revision(s) will be removed.'
        val = raw_input('Are you sure [y/N]? ')
        if val.lower() not in ('y', 'yes'):
            print 'Canceled'
            return 0

        uncommit.uncommit(b, remove_files=remove,
                dry_run=dry_run, verbose=verbose,
                revno=revno)

bzrlib.commands.register_command(cmd_uncommit)
bzrlib.commands.OPTIONS['remove'] = None
bzrlib.commands.OPTIONS['dry-run'] = None