/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
29
        from bzrlib.commands 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.29 by John Arbash Meinel
Added a file to put the changeset into.
56
    It will store it into FILENAME if supplied, otherwise it writes
57
    to stdout
58
0.5.7 by John Arbash Meinel
Added a bunch more information about changesets. Can now read back in all of the meta information.
59
    Right now, rollup changesets, or working tree changesets are
60
    not supported. This will only generate a changeset that has been
61
    committed. You can use "--revision" to specify a certain change
62
    to display.
0.5.1 by John Arbash Meinel
Just an initial working step.
63
    """
0.5.27 by John Arbash Meinel
Now capable of generating rollup changesets.
64
    takes_options = ['revision']
0.5.29 by John Arbash Meinel
Added a file to put the changeset into.
65
    takes_args = ['filename?']
0.5.1 by John Arbash Meinel
Just an initial working step.
66
    aliases = ['cset']
67
0.5.29 by John Arbash Meinel
Added a file to put the changeset into.
68
    def run(self, revision=None, filename=None):
0.5.1 by John Arbash Meinel
Just an initial working step.
69
        from bzrlib import find_branch
70
        import gen_changeset
71
        import sys
0.5.29 by John Arbash Meinel
Added a file to put the changeset into.
72
        import codecs
73
74
        if filename is None or filename == '-':
75
            outf = codecs.getwriter(bzrlib.user_encoding)(sys.stdout, errors='replace')
76
        else:
77
            f = open(filename, 'wb')
78
            outf = codecs.getwriter(bzrlib.user_encoding)(f, errors='replace')
0.5.1 by John Arbash Meinel
Just an initial working step.
79
0.5.27 by John Arbash Meinel
Now capable of generating rollup changesets.
80
        if not isinstance(revision, (list, tuple)):
81
            revision = [revision]
82
        b = find_branch('.')
0.5.1 by John Arbash Meinel
Just an initial working step.
83
0.5.29 by John Arbash Meinel
Added a file to put the changeset into.
84
        gen_changeset.show_changeset(b, revision, to_file=outf)
0.5.1 by John Arbash Meinel
Just an initial working step.
85
0.5.7 by John Arbash Meinel
Added a bunch more information about changesets. Can now read back in all of the meta information.
86
class cmd_verify_changeset(bzrlib.commands.Command):
87
    """Read a written changeset, and make sure it is valid.
88
89
    """
90
    takes_args = ['filename?']
91
92
    def run(self, filename=None):
93
        import sys, read_changeset
0.5.61 by John Arbash Meinel
verify-changeset now validates that revision hashes match the expected value.
94
        from cStringIO import StringIO
0.5.37 by John Arbash Meinel
Made read_changeset able to spit out 'Revision' entities.
95
        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.
96
        from bzrlib.branch import find_branch
0.5.61 by John Arbash Meinel
verify-changeset now validates that revision hashes match the expected value.
97
        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.
98
99
        b = find_branch('.')
100
0.5.7 by John Arbash Meinel
Added a bunch more information about changesets. Can now read back in all of the meta information.
101
        if filename is None or filename == '-':
102
            f = sys.stdin
103
        else:
0.5.33 by John Arbash Meinel
Use universal newlines wherever appropriate.
104
            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.
105
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.
106
        cset_info, cset_tree = read_changeset.read_changeset(f, b)
0.5.62 by John Arbash Meinel
Doing some internal validation before allowing processing to continue, additional checks at the command level.
107
        #print cset_info
108
        #print cset_tree
109
110
        failed = False
111
        rev_to_sha = {}
112
        def add_sha(rev_id, sha1):
113
            if rev_id in rev_to_sha:
114
                # This really should have been validated as part
115
                # of read_changeset, but lets do it again
116
                if sha1 != rev_to_sha[rev_id]:
117
                    print ('** Revision %r referenced with 2 different'
118
                            ' sha hashes %s != %s' % (rev_id,
119
                                sha1, rev_to_sha[rev_id]))
120
                    failed = True
121
            else:
122
                rev_to_sha[rev_id] = sha1
123
124
        for rev_info in cset_info.revisions:
125
            add_sha(rev_info.rev_id, rev_info.sha1)
126
                
127
        for rev in cset_info.real_revisions:
128
            for parent in rev.parents:
129
                add_sha(parent.revision_id, parent.revision_sha1)
130
131
        missing = {}
132
        for rev_id, sha1 in rev_to_sha.iteritems():
133
            if rev_id in b.revision_store:
134
                local_sha1 = b.get_revision_sha1(rev_id)
135
                if sha1 != local_sha1:
136
                    print '** sha1 mismatch. For revision_id {%s}' % rev_id
137
                    print '**     local: %s' % local_sha1
138
                    print '** changeset: %s' % sha1
139
                    failed = True
140
            else:
141
                missing[rev_id] = sha1
142
        
143
        # Entries in missing do not exist in the local branch,
144
        # so we cannot validate them.
145
        if len(missing) > 0:
146
            print '** Unable to verify %d checksums' % len(missing)
147
148
        if failed:
149
            print '** Changeset did not validate.'
150
        else:
151
            print 'Changeset is valid'
152
            print 'validated %d revision sha hashes.' % (len(rev_to_sha) - len(missing))
0.5.61 by John Arbash Meinel
verify-changeset now validates that revision hashes match the expected value.
153
0.5.7 by John Arbash Meinel
Added a bunch more information about changesets. Can now read back in all of the meta information.
154
0.5.15 by John Arbash Meinel
Created an apply-changeset function, and modified output for better parsing.
155
class cmd_apply_changeset(bzrlib.commands.Command):
156
    """Read in the given changeset, and apply it to the
157
    current tree.
158
159
    """
160
    takes_args = ['filename?']
161
    takes_options = []
162
0.5.18 by John Arbash Meinel
Some minor fixups
163
    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.
164
        from bzrlib import find_branch
0.5.17 by John Arbash Meinel
adding apply-changset, plus more meta information.
165
        import sys
166
        import apply_changeset
0.5.15 by John Arbash Meinel
Created an apply-changeset function, and modified output for better parsing.
167
168
        b = find_branch('.') # Make sure we are in a branch
169
        if filename is None or filename == '-':
170
            f = sys.stdin
171
        else:
0.5.29 by John Arbash Meinel
Added a file to put the changeset into.
172
            f = open(filename, 'U') # Universal newlines
0.5.15 by John Arbash Meinel
Created an apply-changeset function, and modified output for better parsing.
173
0.5.17 by John Arbash Meinel
adding apply-changset, plus more meta information.
174
        apply_changeset.apply_changeset(b, f, reverse=reverse,
175
                auto_commit=auto_commit)
0.5.15 by John Arbash Meinel
Created an apply-changeset function, and modified output for better parsing.
176
0.5.7 by John Arbash Meinel
Added a bunch more information about changesets. Can now read back in all of the meta information.
177
0.5.24 by John Arbash Meinel
Adding send-changeset from Johan Rydberg
178
bzrlib.commands.register_command(cmd_changeset)
179
bzrlib.commands.register_command(cmd_verify_changeset)
180
bzrlib.commands.register_command(cmd_apply_changeset)
181
bzrlib.commands.register_command(cmd_send_changeset)
182
0.5.41 by aaron.bentley at utoronto
Added non-working ChangesetTree
183
from test import cmd_test_plugins
184
bzrlib.commands.register_command(cmd_test_plugins)
185
0.5.24 by John Arbash Meinel
Adding send-changeset from Johan Rydberg
186
bzrlib.commands.OPTIONS['reverse'] = None
187
bzrlib.commands.OPTIONS['auto-commit'] = None
188
cmd_apply_changeset.takes_options.append('reverse')
189
cmd_apply_changeset.takes_options.append('auto-commit')