~bzr-pqm/bzr/bzr.dev

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.81 by John Arbash Meinel
Cleaning up from pychecker.
9
from bzrlib.commands import Command, register_command, OPTIONS
0.5.1 by John Arbash Meinel
Just an initial working step.
10
0.5.81 by John Arbash Meinel
Cleaning up from pychecker.
11
class cmd_send_changeset(Command):
0.5.24 by John Arbash Meinel
Adding send-changeset from Johan Rydberg
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.81 by John Arbash Meinel
Cleaning up from pychecker.
50
class cmd_changeset(Command):
0.5.1 by John Arbash Meinel
Just an initial working step.
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']
0.5.70 by John Arbash Meinel
Making BASE optional, defaulting to TARGET.parents[0]
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.81 by John Arbash Meinel
Cleaning up from pychecker.
74
        from bzrlib.branch 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.81 by John Arbash Meinel
Cleaning up from pychecker.
77
        from bzrlib import user_encoding
0.5.1 by John Arbash Meinel
Just an initial working step.
78
        import gen_changeset
79
        import sys
0.5.29 by John Arbash Meinel
Added a file to put the changeset into.
80
        import codecs
81
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.
82
        if target is None:
83
            target = './@'
84
        b_target_path, target_revno = parse_spec(target)
0.5.71 by John Arbash Meinel
Cleaning up code for latest bzr.
85
        target_branch = find_branch(b_target_path)
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.
86
        if target_revno is None or target_revno == -1:
0.5.71 by John Arbash Meinel
Cleaning up code for latest bzr.
87
            target_rev_id = target_branch.last_patch()
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.
88
        else:
0.5.71 by John Arbash Meinel
Cleaning up code for latest bzr.
89
            target_rev_id = target_branch.lookup_revision(target_revno)
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.
90
0.5.70 by John Arbash Meinel
Making BASE optional, defaulting to TARGET.parents[0]
91
        if base is None:
0.5.71 by John Arbash Meinel
Cleaning up code for latest bzr.
92
            base_branch = target_branch
93
            target_rev = target_branch.get_revision(target_rev_id)
94
            base_rev_id = target_rev.parents[0].revision_id
0.5.70 by John Arbash Meinel
Making BASE optional, defaulting to TARGET.parents[0]
95
        else:
96
            base_path, base_revno = parse_spec(base)
0.5.71 by John Arbash Meinel
Cleaning up code for latest bzr.
97
            base_branch = find_branch(base_path)
0.5.70 by John Arbash Meinel
Making BASE optional, defaulting to TARGET.parents[0]
98
            if base_revno is None or base_revno == -1:
99
                base_rev_id = base_branch.last_patch()
100
            else:
0.5.73 by John Arbash Meinel
Some fixups for gen_changeset.
101
                base_rev_id = base_branch.lookup_revision(base_revno)
0.5.70 by John Arbash Meinel
Making BASE optional, defaulting to TARGET.parents[0]
102
0.5.87 by John Arbash Meinel
Handling international characters, added more test cases.
103
        # outf = codecs.getwriter(user_encoding)(sys.stdout,
104
        #         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.
105
106
        if starting_rev_id is not None:
107
            raise BzrCommandError('Specifying the STARTING-REV-ID'
108
                    ' not yet supported')
109
110
        gen_changeset.show_changeset(base_branch, base_rev_id,
111
                target_branch, target_rev_id,
112
                starting_rev_id,
0.5.87 by John Arbash Meinel
Handling international characters, added more test cases.
113
                to_file=sys.stdout, include_full_diff=verbose)
0.5.1 by John Arbash Meinel
Just an initial working step.
114
0.5.81 by John Arbash Meinel
Cleaning up from pychecker.
115
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.
116
    """Read a written changeset, and make sure it is valid.
117
118
    """
119
    takes_args = ['filename?']
120
121
    def run(self, filename=None):
0.5.81 by John Arbash Meinel
Cleaning up from pychecker.
122
        import sys
123
        from read_changeset import read_changeset
124
        from bzrlib.branch import find_branch
0.5.37 by John Arbash Meinel
Made read_changeset able to spit out 'Revision' entities.
125
        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.
126
127
        b = find_branch('.')
128
0.5.7 by John Arbash Meinel
Added a bunch more information about changesets. Can now read back in all of the meta information.
129
        if filename is None or filename == '-':
130
            f = sys.stdin
131
        else:
0.5.33 by John Arbash Meinel
Use universal newlines wherever appropriate.
132
            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.
133
0.5.88 by John Arbash Meinel
Fixed a bug in the rename code, added more tests.
134
        cset_info, cset_tree = read_changeset(f, b)
0.5.63 by John Arbash Meinel
Moving the validation into part of the reading.
135
        print cset_info
136
        print cset_tree
0.5.88 by John Arbash Meinel
Fixed a bug in the rename code, added more tests.
137
        pack_xml(cset_tree.inventory, sys.stdout)
0.5.63 by John Arbash Meinel
Moving the validation into part of the reading.
138
0.5.61 by John Arbash Meinel
verify-changeset now validates that revision hashes match the expected value.
139
0.5.7 by John Arbash Meinel
Added a bunch more information about changesets. Can now read back in all of the meta information.
140
0.5.81 by John Arbash Meinel
Cleaning up from pychecker.
141
class cmd_apply_changeset(Command):
0.5.15 by John Arbash Meinel
Created an apply-changeset function, and modified output for better parsing.
142
    """Read in the given changeset, and apply it to the
143
    current tree.
144
145
    """
146
    takes_args = ['filename?']
0.5.71 by John Arbash Meinel
Cleaning up code for latest bzr.
147
    takes_options = ['reverse', 'auto-commit']
0.5.15 by John Arbash Meinel
Created an apply-changeset function, and modified output for better parsing.
148
0.5.18 by John Arbash Meinel
Some minor fixups
149
    def run(self, filename=None, reverse=False, auto_commit=False):
0.5.81 by John Arbash Meinel
Cleaning up from pychecker.
150
        from bzrlib.branch import find_branch
0.5.17 by John Arbash Meinel
adding apply-changset, plus more meta information.
151
        import sys
152
        import apply_changeset
0.5.15 by John Arbash Meinel
Created an apply-changeset function, and modified output for better parsing.
153
154
        b = find_branch('.') # Make sure we are in a branch
155
        if filename is None or filename == '-':
156
            f = sys.stdin
157
        else:
0.5.72 by John Arbash Meinel
Switching away from universal newlines,
158
            # Actually, we should not use Universal newlines
159
            # as this potentially modifies the patch.
160
            # though it seems mailers save attachments with their
161
            # own format of the files.
162
            f = open(filename, 'rb')
0.5.15 by John Arbash Meinel
Created an apply-changeset function, and modified output for better parsing.
163
0.5.17 by John Arbash Meinel
adding apply-changset, plus more meta information.
164
        apply_changeset.apply_changeset(b, f, reverse=reverse,
165
                auto_commit=auto_commit)
0.5.15 by John Arbash Meinel
Created an apply-changeset function, and modified output for better parsing.
166
0.5.81 by John Arbash Meinel
Cleaning up from pychecker.
167
register_command(cmd_changeset)
168
register_command(cmd_verify_changeset)
169
register_command(cmd_apply_changeset)
170
register_command(cmd_send_changeset)
0.5.41 by aaron.bentley at utoronto
Added non-working ChangesetTree
171
0.5.81 by John Arbash Meinel
Cleaning up from pychecker.
172
OPTIONS['reverse'] = None
173
OPTIONS['auto-commit'] = None
0.5.78 by John Arbash Meinel
Working on test cases, starting with the empty project issues.
174
175
def test_suite():
0.5.79 by John Arbash Meinel
Added common to the set of tests, fixed a problem with time conversions.
176
    from doctest import DocTestSuite
177
    from unittest import TestSuite, TestLoader
0.5.78 by John Arbash Meinel
Working on test cases, starting with the empty project issues.
178
    import testchangeset
0.5.79 by John Arbash Meinel
Added common to the set of tests, fixed a problem with time conversions.
179
    import common
0.5.93 by Aaron Bentley
Added patches.py
180
    import patches
0.5.79 by John Arbash Meinel
Added common to the set of tests, fixed a problem with time conversions.
181
182
    suite = TestSuite()
183
184
    suite.addTest(TestLoader().loadTestsFromModule(testchangeset))
0.5.93 by Aaron Bentley
Added patches.py
185
    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.
186
    suite.addTest(DocTestSuite(common))
187
188
    return suite
189
0.5.78 by John Arbash Meinel
Working on test cases, starting with the empty project issues.
190