/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

Merge from bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""builtin bzr commands"""
18
18
 
19
19
import os
 
20
from StringIO import StringIO
20
21
 
21
22
from bzrlib.lazy_import import lazy_import
22
23
lazy_import(globals(), """
23
24
import codecs
24
25
import errno
 
26
import smtplib
25
27
import sys
26
28
import tempfile
 
29
import time
27
30
 
28
31
import bzrlib
29
32
from bzrlib import (
37
40
    ignores,
38
41
    log,
39
42
    merge as _mod_merge,
 
43
    merge_directive,
40
44
    osutils,
 
45
    registry,
41
46
    repository,
42
47
    symbol_versioning,
43
48
    transport,
1336
1341
            Difference between the working tree and revision 1
1337
1342
        bzr diff -r1..2
1338
1343
            Difference between revision 2 and revision 1
1339
 
        bzr diff --diff-prefix old/:new/
 
1344
        bzr diff --prefix old/:new/
1340
1345
            Same as 'bzr diff' but prefix paths with old/ and new/
1341
1346
        bzr diff bzr.mine bzr.dev
1342
1347
            Show the differences between the two working trees
1359
1364
        Option('prefix', type=str,
1360
1365
               short_name='p',
1361
1366
               help='Set prefixes to added to old and new filenames, as '
1362
 
                    'two values separated by a colon.'),
 
1367
                    'two values separated by a colon. (eg "old/:new/")'),
1363
1368
        ]
1364
1369
    aliases = ['di', 'dif']
1365
1370
    encoding_type = 'exact'
1379
1384
        elif ':' in prefix:
1380
1385
            old_label, new_label = prefix.split(":")
1381
1386
        else:
1382
 
            raise BzrCommandError(
1383
 
                "--prefix expects two values separated by a colon")
 
1387
            raise errors.BzrCommandError(
 
1388
                '--prefix expects two values separated by a colon'
 
1389
                ' (eg "old/:new/")')
1384
1390
 
1385
1391
        if revision and len(revision) > 2:
1386
1392
            raise errors.BzrCommandError('bzr diff --revision takes exactly'
1387
1393
                                         ' one or two revision specifiers')
1388
 
        
 
1394
 
1389
1395
        try:
1390
1396
            tree1, file_list = internal_tree_files(file_list)
1391
1397
            tree2 = None
3291
3297
 
3292
3298
 
3293
3299
 
 
3300
class cmd_merge_directive(Command):
 
3301
    """Generate a merge directive for auto-merge tools.
 
3302
 
 
3303
    A directive requests a merge to be performed, and also provides all the
 
3304
    information necessary to do so.  This means it must either include a
 
3305
    revision bundle, or the location of a branch containing the desired
 
3306
    revision.
 
3307
 
 
3308
    A submit branch (the location to merge into) must be supplied the first
 
3309
    time the command is issued.  After it has been supplied once, it will
 
3310
    be remembered as the default.
 
3311
 
 
3312
    A public branch is optional if a revision bundle is supplied, but required
 
3313
    if --diff or --plain is specified.  It will be remembered as the default
 
3314
    after the first use.
 
3315
    """
 
3316
 
 
3317
    takes_args = ['submit_branch?', 'public_branch?']
 
3318
 
 
3319
    takes_options = [
 
3320
        RegistryOption.from_kwargs('patch-type',
 
3321
            'The type of patch to include in the directive',
 
3322
            title='Patch type', value_switches=True, enum_switch=False,
 
3323
            bundle='Bazaar revision bundle (default)',
 
3324
            diff='Normal unified diff',
 
3325
            plain='No patch, just directive'),
 
3326
        Option('sign', help='GPG-sign the directive'), 'revision',
 
3327
        Option('mail-to', type=str,
 
3328
            help='Instead of printing the directive, email to this address'),
 
3329
        Option('message', type=str, short_name='m',
 
3330
            help='Message to use when committing this merge')
 
3331
        ]
 
3332
 
 
3333
    def run(self, submit_branch=None, public_branch=None, patch_type='bundle',
 
3334
            sign=False, revision=None, mail_to=None, message=None):
 
3335
        if patch_type == 'plain':
 
3336
            patch_type = None
 
3337
        branch = Branch.open('.')
 
3338
        stored_submit_branch = branch.get_submit_branch()
 
3339
        if submit_branch is None:
 
3340
            submit_branch = stored_submit_branch
 
3341
        else:
 
3342
            if stored_submit_branch is None:
 
3343
                branch.set_submit_branch(submit_branch)
 
3344
        if submit_branch is None:
 
3345
            submit_branch = branch.get_parent()
 
3346
        if submit_branch is None:
 
3347
            raise errors.BzrCommandError('No submit branch specified or known')
 
3348
 
 
3349
        stored_public_branch = branch.get_public_branch()
 
3350
        if public_branch is None:
 
3351
            public_branch = stored_public_branch
 
3352
        elif stored_public_branch is None:
 
3353
            branch.set_public_branch(public_branch)
 
3354
        if patch_type != "bundle" and public_branch is None:
 
3355
            raise errors.BzrCommandError('No public branch specified or'
 
3356
                                         ' known')
 
3357
        if revision is not None:
 
3358
            if len(revision) != 1:
 
3359
                raise errors.BzrCommandError('bzr merge-directive takes '
 
3360
                    'exactly one revision identifier')
 
3361
            else:
 
3362
                revision_id = revision[0].in_history(branch).rev_id
 
3363
        else:
 
3364
            revision_id = branch.last_revision()
 
3365
        directive = merge_directive.MergeDirective.from_objects(
 
3366
            branch.repository, revision_id, time.time(),
 
3367
            osutils.local_time_offset(), submit_branch,
 
3368
            public_branch=public_branch, patch_type=patch_type,
 
3369
            message=message)
 
3370
        if mail_to is None:
 
3371
            if sign:
 
3372
                self.outf.write(directive.to_signed(branch))
 
3373
            else:
 
3374
                self.outf.writelines(directive.to_lines())
 
3375
        else:
 
3376
            message = directive.to_email(mail_to, branch, sign)
 
3377
            s = smtplib.SMTP()
 
3378
            server = branch.get_config().get_user_option('smtp_server')
 
3379
            if not server:
 
3380
                server = 'localhost'
 
3381
            s.connect()
 
3382
            s.sendmail(message['From'], message['To'], message.as_string())
 
3383
 
 
3384
 
3294
3385
class cmd_tag(Command):
3295
3386
    """Create a tag naming a revision.
3296
3387