~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: John Arbash Meinel
  • Date: 2005-06-28 20:02:52 UTC
  • mto: (0.5.85) (1185.82.1 bzr-w-changeset)
  • mto: This revision was merged to the branch mainline in revision 1738.
  • Revision ID: john@arbash-meinel.com-20050628200252-eac0d9db2e52cb16
Adding send-changeset from Johan Rydberg

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 
9
9
import bzrlib, bzrlib.commands
10
10
 
 
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
 
11
69
class cmd_changeset(bzrlib.commands.Command):
12
70
    """Generate a bundled up changeset.
13
71
 
87
145
                auto_commit=auto_commit)
88
146
 
89
147
 
90
 
if hasattr(bzrlib.commands, 'register_plugin_command'):
91
 
    bzrlib.commands.register_plugin_command(cmd_changeset)
92
 
    bzrlib.commands.register_plugin_command(cmd_verify_changeset)
93
 
    bzrlib.commands.register_plugin_command(cmd_apply_changeset)
94
 
 
95
 
    bzrlib.commands.OPTIONS['reverse'] = None
96
 
    bzrlib.commands.OPTIONS['auto-commit'] = None
97
 
    cmd_apply_changeset.takes_options.append('reverse')
98
 
    cmd_apply_changeset.takes_options.append('auto-commit')
99
 
elif hasattr(bzrlib.commands, 'register_command'):
100
 
    bzrlib.commands.register_command(cmd_changeset)
101
 
    bzrlib.commands.register_command(cmd_verify_changeset)
102
 
    bzrlib.commands.register_command(cmd_apply_changeset)
103
 
 
104
 
    bzrlib.commands.OPTIONS['reverse'] = None
105
 
    bzrlib.commands.OPTIONS['auto-commit'] = None
106
 
    cmd_apply_changeset.takes_options.append('reverse')
107
 
    cmd_apply_changeset.takes_options.append('auto-commit')
108
 
 
 
148
bzrlib.commands.register_command(cmd_changeset)
 
149
bzrlib.commands.register_command(cmd_verify_changeset)
 
150
bzrlib.commands.register_command(cmd_apply_changeset)
 
151
bzrlib.commands.register_command(cmd_send_changeset)
 
152
 
 
153
bzrlib.commands.OPTIONS['subject'] = str
 
154
bzrlib.commands.OPTIONS['reverse'] = None
 
155
bzrlib.commands.OPTIONS['auto-commit'] = None
 
156
cmd_apply_changeset.takes_options.append('reverse')
 
157
cmd_apply_changeset.takes_options.append('auto-commit')