~abentley/bzrtools/bzrtools.dev

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
#!/usr/bin/python
"""Shelf - temporarily set aside changes, then bring them back."""

import bzrlib.commands
import bzrlib.branch
from shelf import Shelf

class cmd_shelve(bzrlib.commands.Command):
    """Temporarily remove some changes from the current tree.
    Use 'unshelve' to restore these changes.

    If filenames are specified, only changes to those files will be unshelved.
    If a revision is specified, all changes since that revision will may be
    unshelved.
    """
    takes_args = ['file*']
    takes_options = ['message', 'revision']
    def run(self, file_list=None, message=None, revision=None):
        revision_list = None
        if revision is not None and revision:
            if file_list is not None and len(file_list) > 0:
                branchdir = file_list[0]
            else:
                branchdir = '.'
            b = bzrlib.branch.Branch.open_containing(branchdir)
            revision_list = ["revid:" + revision[0].in_history(b).rev_id]

        s = Shelf()
        return s.shelve(message=message, file_list=file_list,
                      revision=revision_list)

class cmd_unshelve(bzrlib.commands.Command):
    """Restore previously-shelved changes to the current tree.
    See also 'shelve'.
    """
    def run(self):
        s = Shelf()
        return s.unshelve()

bzrlib.commands.register_command(cmd_shelve)
bzrlib.commands.register_command(cmd_unshelve)