/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
17
    Subject of the mail can be specified by the --subject option,
18
    otherwise information from the changeset log will be used.
19
    """
20
    takes_options = ['revision', 'subject', 'diff-options']
21
    takes_args = ['to?']
22
23
    def run(self, to=None, subject=None, revision=None, diff_options=None):
24
        from tempfile import TemporaryFile
25
        from bzrlib import find_branch
26
        from bzrlib.commands import BzrCommandError
27
        import gen_changeset
28
        import send_changeset
29
        import sys
30
31
        if isinstance(revision, (list, tuple)):
32
            if len(revision) > 1:
33
                raise BzrCommandError('We do not support rollup-changesets yet.')
34
            revision = revision[0]
35
36
        b = find_branch('.')
37
38
        if not to:
39
            try:
40
                to = b.controlfile('x-send-address', 'rb').read().strip('\n')
41
            except:
42
                raise BzrCommandError('destination address is not known')
43
44
        if not revision:
45
            revision = b.revno()
46
47
        rev = b.get_revision(b.lookup_revision(revision))
48
        if not subject:
49
            subject = rev.message.split('\n')[0]
50
51
        info = "Changset for revision %d by %s\n" % (revision, rev.committer)
52
        info += "with the following message:\n"
53
        for line in rev.message.split('\n'):
54
            info += "  " + line + "\n"
55
56
        message = bzrlib.osutils.get_text_message(info)
57
58
        # FIXME: StringIO instead of temporary file
59
        changeset_fp = TemporaryFile()
60
        gen_changeset.show_changeset(b, revision,
61
                                     external_diff_options=diff_options,
62
                                     to_file=changeset_fp)
63
        
64
        changeset_fp.seek(0)
65
        send_changeset.send_changeset(to, bzrlib.osutils._get_user_id(),
66
                                      subject, changeset_fp, message)
67
68
0.5.1 by John Arbash Meinel
Just an initial working step.
69
class cmd_changeset(bzrlib.commands.Command):
70
    """Generate a bundled up changeset.
71
72
    This changeset contains all of the meta-information of a
73
    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.
74
0.5.29 by John Arbash Meinel
Added a file to put the changeset into.
75
    It will store it into FILENAME if supplied, otherwise it writes
76
    to stdout
77
0.5.7 by John Arbash Meinel
Added a bunch more information about changesets. Can now read back in all of the meta information.
78
    Right now, rollup changesets, or working tree changesets are
79
    not supported. This will only generate a changeset that has been
80
    committed. You can use "--revision" to specify a certain change
81
    to display.
0.5.1 by John Arbash Meinel
Just an initial working step.
82
    """
0.5.27 by John Arbash Meinel
Now capable of generating rollup changesets.
83
    takes_options = ['revision']
0.5.29 by John Arbash Meinel
Added a file to put the changeset into.
84
    takes_args = ['filename?']
0.5.1 by John Arbash Meinel
Just an initial working step.
85
    aliases = ['cset']
86
0.5.29 by John Arbash Meinel
Added a file to put the changeset into.
87
    def run(self, revision=None, filename=None):
0.5.1 by John Arbash Meinel
Just an initial working step.
88
        from bzrlib import find_branch
89
        import gen_changeset
90
        import sys
0.5.29 by John Arbash Meinel
Added a file to put the changeset into.
91
        import codecs
92
93
        if filename is None or filename == '-':
94
            outf = codecs.getwriter(bzrlib.user_encoding)(sys.stdout, errors='replace')
95
        else:
96
            f = open(filename, 'wb')
97
            outf = codecs.getwriter(bzrlib.user_encoding)(f, errors='replace')
0.5.1 by John Arbash Meinel
Just an initial working step.
98
0.5.27 by John Arbash Meinel
Now capable of generating rollup changesets.
99
        if not isinstance(revision, (list, tuple)):
100
            revision = [revision]
101
        b = find_branch('.')
0.5.1 by John Arbash Meinel
Just an initial working step.
102
0.5.29 by John Arbash Meinel
Added a file to put the changeset into.
103
        gen_changeset.show_changeset(b, revision, to_file=outf)
0.5.1 by John Arbash Meinel
Just an initial working step.
104
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
class cmd_verify_changeset(bzrlib.commands.Command):
106
    """Read a written changeset, and make sure it is valid.
107
108
    """
109
    takes_args = ['filename?']
110
111
    def run(self, filename=None):
112
        import sys, read_changeset
113
        if filename is None or filename == '-':
114
            f = sys.stdin
115
        else:
116
            f = open(filename, 'rb')
117
0.5.17 by John Arbash Meinel
adding apply-changset, plus more meta information.
118
        cset_info = read_changeset.read_changeset(f)
119
        print cset_info
120
        cset = cset_info.get_changeset()
121
        print cset.entries
0.5.7 by John Arbash Meinel
Added a bunch more information about changesets. Can now read back in all of the meta information.
122
0.5.15 by John Arbash Meinel
Created an apply-changeset function, and modified output for better parsing.
123
class cmd_apply_changeset(bzrlib.commands.Command):
124
    """Read in the given changeset, and apply it to the
125
    current tree.
126
127
    """
128
    takes_args = ['filename?']
129
    takes_options = []
130
0.5.18 by John Arbash Meinel
Some minor fixups
131
    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.
132
        from bzrlib import find_branch
0.5.17 by John Arbash Meinel
adding apply-changset, plus more meta information.
133
        import sys
134
        import apply_changeset
0.5.15 by John Arbash Meinel
Created an apply-changeset function, and modified output for better parsing.
135
136
        b = find_branch('.') # Make sure we are in a branch
137
        if filename is None or filename == '-':
138
            f = sys.stdin
139
        else:
0.5.29 by John Arbash Meinel
Added a file to put the changeset into.
140
            f = open(filename, 'U') # Universal newlines
0.5.15 by John Arbash Meinel
Created an apply-changeset function, and modified output for better parsing.
141
0.5.17 by John Arbash Meinel
adding apply-changset, plus more meta information.
142
        apply_changeset.apply_changeset(b, f, reverse=reverse,
143
                auto_commit=auto_commit)
0.5.15 by John Arbash Meinel
Created an apply-changeset function, and modified output for better parsing.
144
0.5.7 by John Arbash Meinel
Added a bunch more information about changesets. Can now read back in all of the meta information.
145
0.5.24 by John Arbash Meinel
Adding send-changeset from Johan Rydberg
146
bzrlib.commands.register_command(cmd_changeset)
147
bzrlib.commands.register_command(cmd_verify_changeset)
148
bzrlib.commands.register_command(cmd_apply_changeset)
149
bzrlib.commands.register_command(cmd_send_changeset)
150
151
bzrlib.commands.OPTIONS['subject'] = str
152
bzrlib.commands.OPTIONS['reverse'] = None
153
bzrlib.commands.OPTIONS['auto-commit'] = None
154
cmd_apply_changeset.takes_options.append('reverse')
155
cmd_apply_changeset.takes_options.append('auto-commit')