/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

  • Committer: Alexander Belchenko
  • Date: 2007-03-13 02:16:17 UTC
  • mfrom: (2346 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2356.
  • Revision ID: bialix@ukr.net-20070313021617-azd5lv30b23gyu48
merge 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,
610
615
        old_rh = branch_to.revision_history()
611
616
        if tree_to is not None:
612
617
            result = tree_to.pull(branch_from, overwrite, rev_id,
613
 
                delta.ChangeReporter(unversioned_filter=tree_to.is_ignored))
 
618
                delta._ChangeReporter(unversioned_filter=tree_to.is_ignored))
614
619
        else:
615
620
            result = branch_to.pull(branch_from, overwrite, rev_id)
616
621
 
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
2290
2296
    takes_args = ['testspecs*']
2291
2297
    takes_options = ['verbose',
2292
2298
                     Option('one', help='stop when one test fails'),
2293
 
                     Option('keep-output', 
 
2299
                     Option('keep-output',
2294
2300
                            help='keep output directories when tests fail'),
2295
 
                     Option('transport', 
 
2301
                     Option('transport',
2296
2302
                            help='Use a different transport by default '
2297
2303
                                 'throughout the test suite.',
2298
2304
                            type=get_transport_type),
2299
 
                     Option('benchmark', help='run the bzr bencharks.'),
 
2305
                     Option('benchmark', help='run the bzr benchmarks.'),
2300
2306
                     Option('lsprof-timed',
2301
2307
                            help='generate lsprof output for benchmarked'
2302
2308
                                 ' sections of code.'),
2307
2313
                            help='clean temporary tests directories'
2308
2314
                                 ' without running tests'),
2309
2315
                     Option('first',
2310
 
                            help='run all tests, but run specified tests first',
 
2316
                            help='run all tests, but run specified tests first'
2311
2317
                            ),
2312
2318
                     Option('numbered-dirs',
2313
2319
                            help='use numbered dirs for TestCaseInTempDir'),
2498
2504
        #      Either the merge helper code should be updated to take a tree,
2499
2505
        #      (What about tree.merge_from_branch?)
2500
2506
        tree = WorkingTree.open_containing(directory)[0]
2501
 
        change_reporter = delta.ChangeReporter(
 
2507
        change_reporter = delta._ChangeReporter(
2502
2508
            unversioned_filter=tree.is_ignored)
2503
2509
 
2504
2510
        if branch is not None:
3240
3246
class cmd_join(Command):
3241
3247
    """Combine a subtree into its containing tree.
3242
3248
    
3243
 
    This is marked as a merge of the subtree into the containing tree, and all
3244
 
    history is preserved.
 
3249
    This command is for experimental use only.  It requires the target tree
 
3250
    to be in dirstate-with-subtree format, which cannot be converted into
 
3251
    earlier formats.
 
3252
 
 
3253
    The TREE argument should be an independent tree, inside another tree, but
 
3254
    not part of it.  (Such trees can be produced by "bzr split", but also by
 
3255
    running "bzr branch" with the target inside a tree.)
 
3256
 
 
3257
    The result is a combined tree, with the subtree no longer an independant
 
3258
    part.  This is marked as a merge of the subtree into the containing tree,
 
3259
    and all history is preserved.
 
3260
 
 
3261
    If --reference is specified, the subtree retains its independence.  It can
 
3262
    be branched by itself, and can be part of multiple projects at the same
 
3263
    time.  But operations performed in the containing tree, such as commit
 
3264
    and merge, will recurse into the subtree.
3245
3265
    """
3246
3266
 
3247
3267
    takes_args = ['tree']
3248
3268
    takes_options = [Option('reference', 'join by reference')]
 
3269
    hidden = True
3249
3270
 
3250
3271
    def run(self, tree, reference=False):
3251
3272
        sub_tree = WorkingTree.open(tree)
3275
3296
 
3276
3297
class cmd_split(Command):
3277
3298
    """Split a tree into two trees.
 
3299
 
 
3300
    This command is for experimental use only.  It requires the target tree
 
3301
    to be in dirstate-with-subtree format, which cannot be converted into
 
3302
    earlier formats.
 
3303
 
 
3304
    The TREE argument should be a subdirectory of a working tree.  That
 
3305
    subdirectory will be converted into an independent tree, with its own
 
3306
    branch.  Commits in the top-level tree will not apply to the new subtree.
 
3307
    If you want that behavior, do "bzr join --reference TREE".
 
3308
 
 
3309
    To undo this operation, do "bzr join TREE".
3278
3310
    """
3279
3311
 
3280
3312
    takes_args = ['tree']
3281
3313
 
 
3314
    hidden = True
 
3315
 
3282
3316
    def run(self, tree):
3283
3317
        containing_tree, subdir = WorkingTree.open_containing(tree)
3284
3318
        sub_id = containing_tree.path2id(subdir)
3291
3325
 
3292
3326
 
3293
3327
 
 
3328
class cmd_merge_directive(Command):
 
3329
    """Generate a merge directive for auto-merge tools.
 
3330
 
 
3331
    A directive requests a merge to be performed, and also provides all the
 
3332
    information necessary to do so.  This means it must either include a
 
3333
    revision bundle, or the location of a branch containing the desired
 
3334
    revision.
 
3335
 
 
3336
    A submit branch (the location to merge into) must be supplied the first
 
3337
    time the command is issued.  After it has been supplied once, it will
 
3338
    be remembered as the default.
 
3339
 
 
3340
    A public branch is optional if a revision bundle is supplied, but required
 
3341
    if --diff or --plain is specified.  It will be remembered as the default
 
3342
    after the first use.
 
3343
    """
 
3344
 
 
3345
    takes_args = ['submit_branch?', 'public_branch?']
 
3346
 
 
3347
    takes_options = [
 
3348
        RegistryOption.from_kwargs('patch-type',
 
3349
            'The type of patch to include in the directive',
 
3350
            title='Patch type', value_switches=True, enum_switch=False,
 
3351
            bundle='Bazaar revision bundle (default)',
 
3352
            diff='Normal unified diff',
 
3353
            plain='No patch, just directive'),
 
3354
        Option('sign', help='GPG-sign the directive'), 'revision',
 
3355
        Option('mail-to', type=str,
 
3356
            help='Instead of printing the directive, email to this address'),
 
3357
        Option('message', type=str, short_name='m',
 
3358
            help='Message to use when committing this merge')
 
3359
        ]
 
3360
 
 
3361
    def run(self, submit_branch=None, public_branch=None, patch_type='bundle',
 
3362
            sign=False, revision=None, mail_to=None, message=None):
 
3363
        if patch_type == 'plain':
 
3364
            patch_type = None
 
3365
        branch = Branch.open('.')
 
3366
        stored_submit_branch = branch.get_submit_branch()
 
3367
        if submit_branch is None:
 
3368
            submit_branch = stored_submit_branch
 
3369
        else:
 
3370
            if stored_submit_branch is None:
 
3371
                branch.set_submit_branch(submit_branch)
 
3372
        if submit_branch is None:
 
3373
            submit_branch = branch.get_parent()
 
3374
        if submit_branch is None:
 
3375
            raise errors.BzrCommandError('No submit branch specified or known')
 
3376
 
 
3377
        stored_public_branch = branch.get_public_branch()
 
3378
        if public_branch is None:
 
3379
            public_branch = stored_public_branch
 
3380
        elif stored_public_branch is None:
 
3381
            branch.set_public_branch(public_branch)
 
3382
        if patch_type != "bundle" and public_branch is None:
 
3383
            raise errors.BzrCommandError('No public branch specified or'
 
3384
                                         ' known')
 
3385
        if revision is not None:
 
3386
            if len(revision) != 1:
 
3387
                raise errors.BzrCommandError('bzr merge-directive takes '
 
3388
                    'exactly one revision identifier')
 
3389
            else:
 
3390
                revision_id = revision[0].in_history(branch).rev_id
 
3391
        else:
 
3392
            revision_id = branch.last_revision()
 
3393
        directive = merge_directive.MergeDirective.from_objects(
 
3394
            branch.repository, revision_id, time.time(),
 
3395
            osutils.local_time_offset(), submit_branch,
 
3396
            public_branch=public_branch, patch_type=patch_type,
 
3397
            message=message)
 
3398
        if mail_to is None:
 
3399
            if sign:
 
3400
                self.outf.write(directive.to_signed(branch))
 
3401
            else:
 
3402
                self.outf.writelines(directive.to_lines())
 
3403
        else:
 
3404
            message = directive.to_email(mail_to, branch, sign)
 
3405
            s = smtplib.SMTP()
 
3406
            server = branch.get_config().get_user_option('smtp_server')
 
3407
            if not server:
 
3408
                server = 'localhost'
 
3409
            s.connect()
 
3410
            s.sendmail(message['From'], message['To'], message.as_string())
 
3411
 
 
3412
 
3294
3413
class cmd_tag(Command):
3295
3414
    """Create a tag naming a revision.
3296
3415