/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
757 by Martin Pool
- add john's changeset plugin
1
#!/usr/bin/env python
2
"""\
3
This is an attempt to take the internal delta object, and represent
4
it as a single-file text-only changeset.
5
This should have commands for both generating a changeset,
6
and for applying a changeset.
7
"""
8
9
import bzrlib, bzrlib.commands
10
11
class cmd_changeset(bzrlib.commands.Command):
12
    """Generate a bundled up changeset.
13
14
    This changeset contains all of the meta-information of a
15
    diff, rather than just containing the patch information.
16
17
    Right now, rollup changesets, or working tree changesets are
18
    not supported. This will only generate a changeset that has been
19
    committed. You can use "--revision" to specify a certain change
20
    to display.
21
    """
22
    takes_options = ['revision', 'diff-options']
23
    takes_args = ['file*']
24
    aliases = ['cset']
25
26
    def run(self, revision=None, file_list=None, diff_options=None):
27
        from bzrlib import find_branch
28
        import gen_changeset
29
        import sys
30
31
        if isinstance(revision, (list, tuple)):
32
            if len(revision) > 1:
33
                raise BzrCommandError('We do not support rollup-changesets yet.')
34
            revision = revision[0]
35
        if file_list:
36
            b = find_branch(file_list[0])
37
            file_list = [b.relpath(f) for f in file_list]
38
            if file_list == ['']:
39
                # just pointing to top-of-tree
40
                file_list = None
41
        else:
42
            b = find_branch('.')
43
44
        gen_changeset.show_changeset(b, revision,
45
                specific_files=file_list,
46
                external_diff_options=diff_options,
47
                to_file=sys.stdout)
48
49
class cmd_verify_changeset(bzrlib.commands.Command):
50
    """Read a written changeset, and make sure it is valid.
51
52
    """
53
    takes_args = ['filename?']
54
55
    def run(self, filename=None):
56
        import sys, read_changeset
57
        if filename is None or filename == '-':
58
            f = sys.stdin
59
        else:
60
            f = open(filename, 'rb')
61
62
        cset_info = read_changeset.read_changeset(f)
63
        print cset_info
64
        cset = cset_info.get_changeset()
65
        print cset.entries
66
67
class cmd_apply_changeset(bzrlib.commands.Command):
68
    """Read in the given changeset, and apply it to the
69
    current tree.
70
71
    """
72
    takes_args = ['filename?']
73
    takes_options = []
74
75
    def run(self, filename=None, reverse=False, auto_commit=False):
76
        from bzrlib import find_branch
77
        import sys
78
        import apply_changeset
79
80
        b = find_branch('.') # Make sure we are in a branch
81
        if filename is None or filename == '-':
82
            f = sys.stdin
83
        else:
84
            f = open(filename, 'rb')
85
86
        apply_changeset.apply_changeset(b, f, reverse=reverse,
87
                auto_commit=auto_commit)
88
89
90
if hasattr(bzrlib.commands, 'register_plugin_cmd'):
91
    bzrlib.commands.register_plugin_cmd(cmd_changeset)
92
    bzrlib.commands.register_plugin_cmd(cmd_verify_changeset)
93
    bzrlib.commands.register_plugin_cmd(cmd_apply_changeset)
94
95
    bzrlib.commands.OPTIONS['reverse'] = None
96
    bzrlib.commands.OPTIONS['auto-commit'] = None
97
    cmd_apply_changeset.takes_options.append('reverse')
98
    cmd_apply_changeset.takes_options.append('auto-commit')
99