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