/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
75
    Right now, rollup changesets, or working tree changesets are
76
    not supported. This will only generate a changeset that has been
77
    committed. You can use "--revision" to specify a certain change
78
    to display.
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
    takes_options = ['revision']
81
    takes_args = []
0.5.1 by John Arbash Meinel
Just an initial working step.
82
    aliases = ['cset']
83
0.5.27 by John Arbash Meinel
Now capable of generating rollup changesets.
84
    def run(self, revision=None):
0.5.1 by John Arbash Meinel
Just an initial working step.
85
        from bzrlib import find_branch
86
        import gen_changeset
87
        import sys
88
0.5.27 by John Arbash Meinel
Now capable of generating rollup changesets.
89
        if not isinstance(revision, (list, tuple)):
90
            revision = [revision]
91
        b = find_branch('.')
0.5.1 by John Arbash Meinel
Just an initial working step.
92
93
        gen_changeset.show_changeset(b, revision,
94
                to_file=sys.stdout)
95
0.5.7 by John Arbash Meinel
Added a bunch more information about changesets. Can now read back in all of the meta information.
96
class cmd_verify_changeset(bzrlib.commands.Command):
97
    """Read a written changeset, and make sure it is valid.
98
99
    """
100
    takes_args = ['filename?']
101
102
    def run(self, filename=None):
103
        import sys, read_changeset
104
        if filename is None or filename == '-':
105
            f = sys.stdin
106
        else:
107
            f = open(filename, 'rb')
108
0.5.17 by John Arbash Meinel
adding apply-changset, plus more meta information.
109
        cset_info = read_changeset.read_changeset(f)
110
        print cset_info
111
        cset = cset_info.get_changeset()
112
        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.
113
0.5.15 by John Arbash Meinel
Created an apply-changeset function, and modified output for better parsing.
114
class cmd_apply_changeset(bzrlib.commands.Command):
115
    """Read in the given changeset, and apply it to the
116
    current tree.
117
118
    """
119
    takes_args = ['filename?']
120
    takes_options = []
121
0.5.18 by John Arbash Meinel
Some minor fixups
122
    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.
123
        from bzrlib import find_branch
0.5.17 by John Arbash Meinel
adding apply-changset, plus more meta information.
124
        import sys
125
        import apply_changeset
0.5.15 by John Arbash Meinel
Created an apply-changeset function, and modified output for better parsing.
126
127
        b = find_branch('.') # Make sure we are in a branch
128
        if filename is None or filename == '-':
129
            f = sys.stdin
130
        else:
131
            f = open(filename, 'rb')
132
0.5.17 by John Arbash Meinel
adding apply-changset, plus more meta information.
133
        apply_changeset.apply_changeset(b, f, reverse=reverse,
134
                auto_commit=auto_commit)
0.5.15 by John Arbash Meinel
Created an apply-changeset function, and modified output for better parsing.
135
0.5.7 by John Arbash Meinel
Added a bunch more information about changesets. Can now read back in all of the meta information.
136
0.5.24 by John Arbash Meinel
Adding send-changeset from Johan Rydberg
137
bzrlib.commands.register_command(cmd_changeset)
138
bzrlib.commands.register_command(cmd_verify_changeset)
139
bzrlib.commands.register_command(cmd_apply_changeset)
140
bzrlib.commands.register_command(cmd_send_changeset)
141
142
bzrlib.commands.OPTIONS['subject'] = str
143
bzrlib.commands.OPTIONS['reverse'] = None
144
bzrlib.commands.OPTIONS['auto-commit'] = None
145
cmd_apply_changeset.takes_options.append('reverse')
146
cmd_apply_changeset.takes_options.append('auto-commit')