/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.5.1 by John Arbash Meinel
Just an initial working step.
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
0.5.24 by John Arbash Meinel
Adding send-changeset from Johan Rydberg
11
class cmd_send_changeset(bzrlib.commands.Command):
12
    """Send a bundled up changset via mail.
13
14
    If no revision has been specified, the last commited change will
15
    be sent.
16
0.5.30 by John Arbash Meinel
Merging send-changeset updates from jrydberg
17
    Subject of the mail can be specified by the --message option,
0.5.24 by John Arbash Meinel
Adding send-changeset from Johan Rydberg
18
    otherwise information from the changeset log will be used.
0.5.30 by John Arbash Meinel
Merging send-changeset updates from jrydberg
19
20
    A editor will be spawned where the user may enter a description
21
    of the changeset.  The description can be read from a file with
22
    the --file FILE option.
0.5.24 by John Arbash Meinel
Adding send-changeset from Johan Rydberg
23
    """
0.5.31 by John Arbash Meinel
Some cleanup to the send_changeset work.
24
    takes_options = ['revision', 'message', 'file']
0.5.24 by John Arbash Meinel
Adding send-changeset from Johan Rydberg
25
    takes_args = ['to?']
26
0.5.31 by John Arbash Meinel
Some cleanup to the send_changeset work.
27
    def run(self, to=None, message=None, revision=None, file=None):
0.5.24 by John Arbash Meinel
Adding send-changeset from Johan Rydberg
28
        from bzrlib import find_branch
0.5.68 by John Arbash Meinel
(broken), starting to change the syntax of the command to allow cset to take a base and a target.
29
        from bzrlib.errors import BzrCommandError
0.5.31 by John Arbash Meinel
Some cleanup to the send_changeset work.
30
        from send_changeset import send_changeset
0.5.30 by John Arbash Meinel
Merging send-changeset updates from jrydberg
31
        
0.5.24 by John Arbash Meinel
Adding send-changeset from Johan Rydberg
32
        if isinstance(revision, (list, tuple)):
33
            if len(revision) > 1:
34
                raise BzrCommandError('We do not support rollup-changesets yet.')
35
            revision = revision[0]
36
37
        b = find_branch('.')
38
39
        if not to:
40
            try:
41
                to = b.controlfile('x-send-address', 'rb').read().strip('\n')
42
            except:
43
                raise BzrCommandError('destination address is not known')
44
0.5.31 by John Arbash Meinel
Some cleanup to the send_changeset work.
45
        if not isinstance(revision, (list, tuple)):
46
            revision = [revision]
0.5.24 by John Arbash Meinel
Adding send-changeset from Johan Rydberg
47
0.5.31 by John Arbash Meinel
Some cleanup to the send_changeset work.
48
        send_changeset(b, revision, to, message, file)
0.5.24 by John Arbash Meinel
Adding send-changeset from Johan Rydberg
49
0.5.1 by John Arbash Meinel
Just an initial working step.
50
class cmd_changeset(bzrlib.commands.Command):
51
    """Generate a bundled up changeset.
52
53
    This changeset contains all of the meta-information of a
54
    diff, rather than just containing the patch information.
0.5.7 by John Arbash Meinel
Added a bunch more information about changesets. Can now read back in all of the meta information.
55
0.5.68 by John Arbash Meinel
(broken), starting to change the syntax of the command to allow cset to take a base and a target.
56
    BASE - This is the target tree with which you want to merge.
57
           It will be used as the base for all patches. Anyone
58
           wanting to merge the changeset will be required to have BASE
59
    TARGET - This is the final revision which is desired to be in the
60
             changeset. It defaults to the last committed revision. './@'
61
    STARTING-REV-ID - All revisions between STARTING-REV and TARGET will
62
                      be bundled up in the changeset. By default this is
63
                      chosen as the merge root.
64
                      (NOT Implemented yet)
65
66
67
    If --verbose, renames will be given as an 'add + delete' style patch.
0.5.1 by John Arbash Meinel
Just an initial working step.
68
    """
0.5.68 by John Arbash Meinel
(broken), starting to change the syntax of the command to allow cset to take a base and a target.
69
    takes_options = ['verbose']
70
    takes_args = ['base', 'target?', 'starting-rev-id?']
0.5.1 by John Arbash Meinel
Just an initial working step.
71
    aliases = ['cset']
72
0.5.68 by John Arbash Meinel
(broken), starting to change the syntax of the command to allow cset to take a base and a target.
73
    def run(self, base=None, target=None, starting_rev_id=None, verbose=False):
0.5.1 by John Arbash Meinel
Just an initial working step.
74
        from bzrlib import find_branch
0.5.68 by John Arbash Meinel
(broken), starting to change the syntax of the command to allow cset to take a base and a target.
75
        from bzrlib.commands import parse_spec
76
        from bzrlib.errors import BzrCommandError
0.5.1 by John Arbash Meinel
Just an initial working step.
77
        import gen_changeset
78
        import sys
0.5.29 by John Arbash Meinel
Added a file to put the changeset into.
79
        import codecs
80
0.5.68 by John Arbash Meinel
(broken), starting to change the syntax of the command to allow cset to take a base and a target.
81
        base_path, base_revno = parse_spec(base)
82
        b_base = find_branch(base_path)
83
        if base_revno is None or base_revno == -1:
84
            base_rev_id = base_branch.last_patch()
85
        else:
86
            base_rev_id = base_branch.last_patch()
87
88
        if target is None:
89
            target = './@'
90
        b_target_path, target_revno = parse_spec(target)
91
        b_target = find_branch(b_target_path)
92
        if target_revno is None or target_revno == -1:
93
            target_rev_id = b_target.last_patch()
94
        else:
95
            target_rev_id = b_target.lookup_revision(target_revno)
96
97
        outf = codecs.getwriter(bzrlib.user_encoding)(sys.stdout,
98
                errors='replace')
99
100
        if starting_rev_id is not None:
101
            raise BzrCommandError('Specifying the STARTING-REV-ID'
102
                    ' not yet supported')
103
104
        gen_changeset.show_changeset(base_branch, base_rev_id,
105
                target_branch, target_rev_id,
106
                starting_rev_id,
107
                to_file=outf, include_full_diff=verbose)
0.5.1 by John Arbash Meinel
Just an initial working step.
108
0.5.7 by John Arbash Meinel
Added a bunch more information about changesets. Can now read back in all of the meta information.
109
class cmd_verify_changeset(bzrlib.commands.Command):
110
    """Read a written changeset, and make sure it is valid.
111
112
    """
113
    takes_args = ['filename?']
114
115
    def run(self, filename=None):
116
        import sys, read_changeset
0.5.61 by John Arbash Meinel
verify-changeset now validates that revision hashes match the expected value.
117
        from cStringIO import StringIO
0.5.37 by John Arbash Meinel
Made read_changeset able to spit out 'Revision' entities.
118
        from bzrlib.xml import pack_xml
0.5.56 by John Arbash Meinel
A couple more fixups, it seems actually capable now of writing out a changeset, and reading it back.
119
        from bzrlib.branch import find_branch
0.5.61 by John Arbash Meinel
verify-changeset now validates that revision hashes match the expected value.
120
        from bzrlib.osutils import sha_file, pumpfile
0.5.56 by John Arbash Meinel
A couple more fixups, it seems actually capable now of writing out a changeset, and reading it back.
121
122
        b = find_branch('.')
123
0.5.7 by John Arbash Meinel
Added a bunch more information about changesets. Can now read back in all of the meta information.
124
        if filename is None or filename == '-':
125
            f = sys.stdin
126
        else:
0.5.33 by John Arbash Meinel
Use universal newlines wherever appropriate.
127
            f = open(filename, 'U')
0.5.7 by John Arbash Meinel
Added a bunch more information about changesets. Can now read back in all of the meta information.
128
0.5.64 by John Arbash Meinel
SUCCESS, we now are able to validate the inventory XML.
129
        cset_info, cset_tree, cset_inv = read_changeset.read_changeset(f, b)
0.5.63 by John Arbash Meinel
Moving the validation into part of the reading.
130
        print cset_info
131
        print cset_tree
0.5.65 by John Arbash Meinel
SUCCESS, we now are able to validate the inventory XML.
132
        pack_xml(cset_inv, sys.stdout)
0.5.63 by John Arbash Meinel
Moving the validation into part of the reading.
133
0.5.61 by John Arbash Meinel
verify-changeset now validates that revision hashes match the expected value.
134
0.5.7 by John Arbash Meinel
Added a bunch more information about changesets. Can now read back in all of the meta information.
135
0.5.15 by John Arbash Meinel
Created an apply-changeset function, and modified output for better parsing.
136
class cmd_apply_changeset(bzrlib.commands.Command):
137
    """Read in the given changeset, and apply it to the
138
    current tree.
139
140
    """
141
    takes_args = ['filename?']
142
    takes_options = []
143
0.5.18 by John Arbash Meinel
Some minor fixups
144
    def run(self, filename=None, reverse=False, auto_commit=False):
0.5.15 by John Arbash Meinel
Created an apply-changeset function, and modified output for better parsing.
145
        from bzrlib import find_branch
0.5.17 by John Arbash Meinel
adding apply-changset, plus more meta information.
146
        import sys
147
        import apply_changeset
0.5.15 by John Arbash Meinel
Created an apply-changeset function, and modified output for better parsing.
148
149
        b = find_branch('.') # Make sure we are in a branch
150
        if filename is None or filename == '-':
151
            f = sys.stdin
152
        else:
0.5.29 by John Arbash Meinel
Added a file to put the changeset into.
153
            f = open(filename, 'U') # Universal newlines
0.5.15 by John Arbash Meinel
Created an apply-changeset function, and modified output for better parsing.
154
0.5.17 by John Arbash Meinel
adding apply-changset, plus more meta information.
155
        apply_changeset.apply_changeset(b, f, reverse=reverse,
156
                auto_commit=auto_commit)
0.5.15 by John Arbash Meinel
Created an apply-changeset function, and modified output for better parsing.
157
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
158
class cmd_test_plugins(bzrlib.commands.Command):
159
    """Test every plugin that supports tests.
160
161
    """
162
    takes_args = []
163
    takes_options = []
164
165
    def run(self):
166
        import test
167
        test.test()
0.5.7 by John Arbash Meinel
Added a bunch more information about changesets. Can now read back in all of the meta information.
168
0.5.24 by John Arbash Meinel
Adding send-changeset from Johan Rydberg
169
bzrlib.commands.register_command(cmd_changeset)
170
bzrlib.commands.register_command(cmd_verify_changeset)
171
bzrlib.commands.register_command(cmd_apply_changeset)
172
bzrlib.commands.register_command(cmd_send_changeset)
0.5.41 by aaron.bentley at utoronto
Added non-working ChangesetTree
173
bzrlib.commands.register_command(cmd_test_plugins)
174
0.5.24 by John Arbash Meinel
Adding send-changeset from Johan Rydberg
175
bzrlib.commands.OPTIONS['reverse'] = None
176
bzrlib.commands.OPTIONS['auto-commit'] = None
177
cmd_apply_changeset.takes_options.append('reverse')
178
cmd_apply_changeset.takes_options.append('auto-commit')