/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
0.5.99 by John Arbash Meinel
Updating to current Branch.open() and RevisionSpec changes.
9
import sys
0.5.114 by John Arbash Meinel
Hiding OPTIONS since it has been removed. Updating for the new Branch.open_containing()
10
from bzrlib.commands import Command, register_command
0.5.99 by John Arbash Meinel
Updating to current Branch.open() and RevisionSpec changes.
11
from bzrlib.branch import Branch
12
from bzrlib.revisionspec import RevisionSpec
0.5.121 by John Arbash Meinel
Fixing options to apply-changeset
13
from bzrlib.option import Option
0.5.1 by John Arbash Meinel
Just an initial working step.
14
0.5.81 by John Arbash Meinel
Cleaning up from pychecker.
15
class cmd_send_changeset(Command):
0.5.24 by John Arbash Meinel
Adding send-changeset from Johan Rydberg
16
    """Send a bundled up changset via mail.
17
18
    If no revision has been specified, the last commited change will
19
    be sent.
20
0.5.30 by John Arbash Meinel
Merging send-changeset updates from jrydberg
21
    Subject of the mail can be specified by the --message option,
0.5.24 by John Arbash Meinel
Adding send-changeset from Johan Rydberg
22
    otherwise information from the changeset log will be used.
0.5.30 by John Arbash Meinel
Merging send-changeset updates from jrydberg
23
24
    A editor will be spawned where the user may enter a description
25
    of the changeset.  The description can be read from a file with
26
    the --file FILE option.
0.5.24 by John Arbash Meinel
Adding send-changeset from Johan Rydberg
27
    """
0.5.31 by John Arbash Meinel
Some cleanup to the send_changeset work.
28
    takes_options = ['revision', 'message', 'file']
0.5.24 by John Arbash Meinel
Adding send-changeset from Johan Rydberg
29
    takes_args = ['to?']
30
0.5.31 by John Arbash Meinel
Some cleanup to the send_changeset work.
31
    def run(self, to=None, message=None, revision=None, file=None):
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.
32
        from bzrlib.errors import BzrCommandError
0.5.31 by John Arbash Meinel
Some cleanup to the send_changeset work.
33
        from send_changeset import send_changeset
0.5.30 by John Arbash Meinel
Merging send-changeset updates from jrydberg
34
        
0.5.24 by John Arbash Meinel
Adding send-changeset from Johan Rydberg
35
        if isinstance(revision, (list, tuple)):
36
            if len(revision) > 1:
37
                raise BzrCommandError('We do not support rollup-changesets yet.')
38
            revision = revision[0]
39
0.5.99 by John Arbash Meinel
Updating to current Branch.open() and RevisionSpec changes.
40
        b = Branch.open_containing('.')
0.5.24 by John Arbash Meinel
Adding send-changeset from Johan Rydberg
41
42
        if not to:
43
            try:
44
                to = b.controlfile('x-send-address', 'rb').read().strip('\n')
45
            except:
46
                raise BzrCommandError('destination address is not known')
47
0.5.31 by John Arbash Meinel
Some cleanup to the send_changeset work.
48
        if not isinstance(revision, (list, tuple)):
49
            revision = [revision]
0.5.24 by John Arbash Meinel
Adding send-changeset from Johan Rydberg
50
0.5.31 by John Arbash Meinel
Some cleanup to the send_changeset work.
51
        send_changeset(b, revision, to, message, file)
0.5.24 by John Arbash Meinel
Adding send-changeset from Johan Rydberg
52
0.5.81 by John Arbash Meinel
Cleaning up from pychecker.
53
class cmd_changeset(Command):
0.5.1 by John Arbash Meinel
Just an initial working step.
54
    """Generate a bundled up changeset.
55
56
    This changeset contains all of the meta-information of a
57
    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.
58
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.
59
    BASE - This is the target tree with which you want to merge.
60
           It will be used as the base for all patches. Anyone
61
           wanting to merge the changeset will be required to have BASE
62
    TARGET - This is the final revision which is desired to be in the
63
             changeset. It defaults to the last committed revision. './@'
64
    STARTING-REV-ID - All revisions between STARTING-REV and TARGET will
65
                      be bundled up in the changeset. By default this is
66
                      chosen as the merge root.
67
                      (NOT Implemented yet)
68
69
70
    If --verbose, renames will be given as an 'add + delete' style patch.
0.7.2 by John Arbash Meinel
Re-adding the --revision flag to make inspecting changes easier.
71
    If --revision is given, it has several states:
72
        --revision A..B A is chosen as the base and B is chosen as the target
73
        --revision A    A is chosen as the target, and the base is it's primary parent
74
        --revision ..B  B is chosen as the target, and the base is it's primary parent
75
        --revision A..  ???
0.5.103 by John Arbash Meinel
Updated to having a changeset specific message.
76
    --message will replace the global message with the one supplied. Though this
77
        will not be saved in the final revision messages.
0.5.1 by John Arbash Meinel
Just an initial working step.
78
    """
0.5.103 by John Arbash Meinel
Updated to having a changeset specific message.
79
    takes_options = ['verbose', 'revision', 'message']
0.5.70 by John Arbash Meinel
Making BASE optional, defaulting to TARGET.parents[0]
80
    takes_args = ['base?', 'target?', 'starting-rev-id?']
0.5.1 by John Arbash Meinel
Just an initial working step.
81
    aliases = ['cset']
82
0.5.103 by John Arbash Meinel
Updated to having a changeset specific message.
83
    def run(self, base=None, target=None, starting_rev_id=None,
84
            verbose=False, revision=None, message=None):
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.
85
        from bzrlib.commands import parse_spec
86
        from bzrlib.errors import BzrCommandError
0.5.81 by John Arbash Meinel
Cleaning up from pychecker.
87
        from bzrlib import user_encoding
0.5.1 by John Arbash Meinel
Just an initial working step.
88
        import gen_changeset
0.5.29 by John Arbash Meinel
Added a file to put the changeset into.
89
        import codecs
90
0.7.2 by John Arbash Meinel
Re-adding the --revision flag to make inspecting changes easier.
91
        if revision is not None:
92
            if (target is not None or base is not None):
93
                raise BzrCommandError('--revision superceeds base and target')
94
            if len(revision) == 1:
95
                target_info = revision[0]
96
                base_info = None
97
            elif len(revision) == 2:
98
                target_info = revision[1]
99
                base_info = revision[0]
100
            else:
101
                raise BzrCommandError('--revision can take at most 2 arguments')
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.
102
0.5.114 by John Arbash Meinel
Hiding OPTIONS since it has been removed. Updating for the new Branch.open_containing()
103
            target_branch, relpath = Branch.open_containing('.')
0.5.99 by John Arbash Meinel
Updating to current Branch.open() and RevisionSpec changes.
104
            target_revno, target_rev_id = target_info.in_history(target_branch)
0.5.71 by John Arbash Meinel
Cleaning up code for latest bzr.
105
            base_branch = target_branch
0.7.2 by John Arbash Meinel
Re-adding the --revision flag to make inspecting changes easier.
106
            if base_info is not None:
0.5.99 by John Arbash Meinel
Updating to current Branch.open() and RevisionSpec changes.
107
                base_revno, base_rev_id = base_info.in_history(target_branch)
0.7.2 by John Arbash Meinel
Re-adding the --revision flag to make inspecting changes easier.
108
            else:
109
                target_rev = target_branch.get_revision(target_rev_id)
0.5.111 by John Arbash Meinel
Working on v4,v5 compatibility
110
                if hasattr(target_rev, 'parent_ids'):
111
                    base_rev_id = target_rev.parent_ids[0]
112
                else:
113
                    base_rev_id = target_rev.parents[0].revision_id
0.5.70 by John Arbash Meinel
Making BASE optional, defaulting to TARGET.parents[0]
114
        else:
0.7.2 by John Arbash Meinel
Re-adding the --revision flag to make inspecting changes easier.
115
            if target is None:
116
                target = './@'
117
            b_target_path, target_revno = parse_spec(target)
0.5.114 by John Arbash Meinel
Hiding OPTIONS since it has been removed. Updating for the new Branch.open_containing()
118
            target_branch, relpath = Branch.open_containing(b_target_path)
0.7.2 by John Arbash Meinel
Re-adding the --revision flag to make inspecting changes easier.
119
            if target_revno is None or target_revno == -1:
0.5.112 by John Arbash Meinel
Upgrading to v5 (ignoring compatibility)
120
                if hasattr(target_branch, 'last_patch'):
121
                    target_rev_id = target_branch.last_patch()
122
                else:
123
                    target_rev_id = target_branch.last_revision()
0.7.2 by John Arbash Meinel
Re-adding the --revision flag to make inspecting changes easier.
124
            else:
0.5.99 by John Arbash Meinel
Updating to current Branch.open() and RevisionSpec changes.
125
                target_rev_id = target_branch.get_rev_id(target_revno)
0.7.2 by John Arbash Meinel
Re-adding the --revision flag to make inspecting changes easier.
126
127
            if base is None:
128
                base_branch = target_branch
129
                target_rev = target_branch.get_revision(target_rev_id)
0.5.111 by John Arbash Meinel
Working on v4,v5 compatibility
130
                if hasattr(target_rev, 'parent_ids'):
131
                    base_rev_id = target_rev.parent_ids[0]
132
                else:
133
                    base_rev_id = target_rev.parents[0].revision_id
0.7.2 by John Arbash Meinel
Re-adding the --revision flag to make inspecting changes easier.
134
            else:
135
                base_path, base_revno = parse_spec(base)
0.5.114 by John Arbash Meinel
Hiding OPTIONS since it has been removed. Updating for the new Branch.open_containing()
136
                base_branch, relpath = Branch.open_containing(base_path)
0.7.2 by John Arbash Meinel
Re-adding the --revision flag to make inspecting changes easier.
137
                if base_revno is None or base_revno == -1:
0.5.112 by John Arbash Meinel
Upgrading to v5 (ignoring compatibility)
138
                    if hasattr(target_branch, 'last_patch'):
139
                        base_rev_id = target_branch.last_patch()
140
                    else:
141
                        base_rev_id = target_branch.last_revision()
0.7.2 by John Arbash Meinel
Re-adding the --revision flag to make inspecting changes easier.
142
                else:
0.5.99 by John Arbash Meinel
Updating to current Branch.open() and RevisionSpec changes.
143
                    base_rev_id = base_branch.get_rev_id(base_revno)
0.5.70 by John Arbash Meinel
Making BASE optional, defaulting to TARGET.parents[0]
144
0.5.87 by John Arbash Meinel
Handling international characters, added more test cases.
145
        # outf = codecs.getwriter(user_encoding)(sys.stdout,
146
        #         errors='replace')
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.
147
148
        if starting_rev_id is not None:
149
            raise BzrCommandError('Specifying the STARTING-REV-ID'
150
                    ' not yet supported')
151
152
        gen_changeset.show_changeset(base_branch, base_rev_id,
153
                target_branch, target_rev_id,
154
                starting_rev_id,
0.5.103 by John Arbash Meinel
Updated to having a changeset specific message.
155
                to_file=sys.stdout, include_full_diff=verbose,
156
                message=message)
0.5.1 by John Arbash Meinel
Just an initial working step.
157
0.5.81 by John Arbash Meinel
Cleaning up from pychecker.
158
class cmd_verify_changeset(Command):
0.5.7 by John Arbash Meinel
Added a bunch more information about changesets. Can now read back in all of the meta information.
159
    """Read a written changeset, and make sure it is valid.
160
161
    """
162
    takes_args = ['filename?']
163
164
    def run(self, filename=None):
0.5.81 by John Arbash Meinel
Cleaning up from pychecker.
165
        from read_changeset import read_changeset
0.5.103 by John Arbash Meinel
Updated to having a changeset specific message.
166
        #from bzrlib.xml import serializer_v4
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.
167
0.5.114 by John Arbash Meinel
Hiding OPTIONS since it has been removed. Updating for the new Branch.open_containing()
168
        b, relpath = Branch.open_containing('.')
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.
169
0.5.7 by John Arbash Meinel
Added a bunch more information about changesets. Can now read back in all of the meta information.
170
        if filename is None or filename == '-':
171
            f = sys.stdin
172
        else:
0.5.33 by John Arbash Meinel
Use universal newlines wherever appropriate.
173
            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.
174
0.5.88 by John Arbash Meinel
Fixed a bug in the rename code, added more tests.
175
        cset_info, cset_tree = read_changeset(f, b)
0.5.103 by John Arbash Meinel
Updated to having a changeset specific message.
176
        # print cset_info
177
        # print cset_tree
178
        #serializer_v4.write(cset_tree.inventory, sys.stdout)
0.5.63 by John Arbash Meinel
Moving the validation into part of the reading.
179
0.5.61 by John Arbash Meinel
verify-changeset now validates that revision hashes match the expected value.
180
0.5.7 by John Arbash Meinel
Added a bunch more information about changesets. Can now read back in all of the meta information.
181
0.5.81 by John Arbash Meinel
Cleaning up from pychecker.
182
class cmd_apply_changeset(Command):
0.5.15 by John Arbash Meinel
Created an apply-changeset function, and modified output for better parsing.
183
    """Read in the given changeset, and apply it to the
184
    current tree.
185
186
    """
187
    takes_args = ['filename?']
0.5.121 by John Arbash Meinel
Fixing options to apply-changeset
188
    takes_options = [Option('reverse'), Option('auto-commit')]
0.5.15 by John Arbash Meinel
Created an apply-changeset function, and modified output for better parsing.
189
0.5.18 by John Arbash Meinel
Some minor fixups
190
    def run(self, filename=None, reverse=False, auto_commit=False):
0.5.17 by John Arbash Meinel
adding apply-changset, plus more meta information.
191
        import apply_changeset
0.5.15 by John Arbash Meinel
Created an apply-changeset function, and modified output for better parsing.
192
0.5.114 by John Arbash Meinel
Hiding OPTIONS since it has been removed. Updating for the new Branch.open_containing()
193
        b, relpath = Branch.open_containing('.') # Make sure we are in a branch
0.5.15 by John Arbash Meinel
Created an apply-changeset function, and modified output for better parsing.
194
        if filename is None or filename == '-':
195
            f = sys.stdin
196
        else:
0.5.72 by John Arbash Meinel
Switching away from universal newlines,
197
            # Actually, we should not use Universal newlines
198
            # as this potentially modifies the patch.
199
            # though it seems mailers save attachments with their
200
            # own format of the files.
201
            f = open(filename, 'rb')
0.5.15 by John Arbash Meinel
Created an apply-changeset function, and modified output for better parsing.
202
0.5.17 by John Arbash Meinel
adding apply-changset, plus more meta information.
203
        apply_changeset.apply_changeset(b, f, reverse=reverse,
204
                auto_commit=auto_commit)
0.5.15 by John Arbash Meinel
Created an apply-changeset function, and modified output for better parsing.
205
0.5.81 by John Arbash Meinel
Cleaning up from pychecker.
206
register_command(cmd_changeset)
207
register_command(cmd_verify_changeset)
208
register_command(cmd_apply_changeset)
209
register_command(cmd_send_changeset)
0.5.41 by aaron.bentley at utoronto
Added non-working ChangesetTree
210
0.5.114 by John Arbash Meinel
Hiding OPTIONS since it has been removed. Updating for the new Branch.open_containing()
211
#OPTIONS['reverse'] = None
212
#OPTIONS['auto-commit'] = None
0.5.78 by John Arbash Meinel
Working on test cases, starting with the empty project issues.
213
214
def test_suite():
0.5.79 by John Arbash Meinel
Added common to the set of tests, fixed a problem with time conversions.
215
    from doctest import DocTestSuite
216
    from unittest import TestSuite, TestLoader
0.5.115 by John Arbash Meinel
Getting closer to being able to read back the changesets, still broken, though.
217
    import test_changeset
0.5.79 by John Arbash Meinel
Added common to the set of tests, fixed a problem with time conversions.
218
    import common
0.5.93 by Aaron Bentley
Added patches.py
219
    import patches
0.5.79 by John Arbash Meinel
Added common to the set of tests, fixed a problem with time conversions.
220
221
    suite = TestSuite()
222
0.5.115 by John Arbash Meinel
Getting closer to being able to read back the changesets, still broken, though.
223
    suite.addTest(TestLoader().loadTestsFromModule(test_changeset))
0.5.93 by Aaron Bentley
Added patches.py
224
    suite.addTest(TestLoader().loadTestsFromModule(patches))
0.5.79 by John Arbash Meinel
Added common to the set of tests, fixed a problem with time conversions.
225
    suite.addTest(DocTestSuite(common))
226
227
    return suite
228
0.5.78 by John Arbash Meinel
Working on test cases, starting with the empty project issues.
229