~bzr-pqm/bzr/bzr.dev

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
760 by Martin Pool
doc
17
    If a file is specified, only changes affecting that file are
18
    specified; this gives a changeset that is probably not useful.
19
757 by Martin Pool
- add john's changeset plugin
20
    Right now, rollup changesets, or working tree changesets are
21
    not supported. This will only generate a changeset that has been
22
    committed. You can use "--revision" to specify a certain change
23
    to display.
24
    """
25
    takes_options = ['revision', 'diff-options']
26
    takes_args = ['file*']
27
    aliases = ['cset']
28
29
    def run(self, revision=None, file_list=None, diff_options=None):
30
        from bzrlib import find_branch
31
        import gen_changeset
32
        import sys
33
34
        if isinstance(revision, (list, tuple)):
35
            if len(revision) > 1:
36
                raise BzrCommandError('We do not support rollup-changesets yet.')
37
            revision = revision[0]
38
        if file_list:
39
            b = find_branch(file_list[0])
40
            file_list = [b.relpath(f) for f in file_list]
41
            if file_list == ['']:
42
                # just pointing to top-of-tree
43
                file_list = None
44
        else:
45
            b = find_branch('.')
46
47
        gen_changeset.show_changeset(b, revision,
48
                specific_files=file_list,
49
                external_diff_options=diff_options,
50
                to_file=sys.stdout)
51
52
class cmd_verify_changeset(bzrlib.commands.Command):
53
    """Read a written changeset, and make sure it is valid.
54
55
    """
56
    takes_args = ['filename?']
57
58
    def run(self, filename=None):
59
        import sys, read_changeset
60
        if filename is None or filename == '-':
61
            f = sys.stdin
62
        else:
63
            f = open(filename, 'rb')
64
65
        cset_info = read_changeset.read_changeset(f)
66
        print cset_info
67
        cset = cset_info.get_changeset()
68
        print cset.entries
69
70
class cmd_apply_changeset(bzrlib.commands.Command):
71
    """Read in the given changeset, and apply it to the
72
    current tree.
73
74
    """
75
    takes_args = ['filename?']
76
    takes_options = []
77
78
    def run(self, filename=None, reverse=False, auto_commit=False):
79
        from bzrlib import find_branch
80
        import sys
81
        import apply_changeset
82
83
        b = find_branch('.') # Make sure we are in a branch
84
        if filename is None or filename == '-':
85
            f = sys.stdin
86
        else:
87
            f = open(filename, 'rb')
88
89
        apply_changeset.apply_changeset(b, f, reverse=reverse,
90
                auto_commit=auto_commit)
91
92
759 by Martin Pool
- fix up register_command() names
93
##if hasattr(bzrlib.commands, 'register_plugin_cmd'):
94
95
## print dir(bzrlib.commands)
96
97
bzrlib.commands.register_command(cmd_changeset)
98
bzrlib.commands.register_command(cmd_verify_changeset)
99
bzrlib.commands.register_command(cmd_apply_changeset)
100
101
bzrlib.commands.OPTIONS['reverse'] = None
102
bzrlib.commands.OPTIONS['auto-commit'] = None
103
cmd_apply_changeset.takes_options.append('reverse')
104
cmd_apply_changeset.takes_options.append('auto-commit')
757 by Martin Pool
- add john's changeset plugin
105