~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Aaron Bentley
  • Date: 2006-03-31 02:39:09 UTC
  • mfrom: (1558.7.10 bzr.ab.integration)
  • mto: This revision was merged to the branch mainline in revision 1634.
  • Revision ID: aaron.bentley@utoronto.ca-20060331023909-957277c1233c6aff
Merge from bzr.ab.integration

Show diffs side-by-side

added added

removed removed

Lines of Context:
326
326
                print path
327
327
 
328
328
 
329
 
class cmd_move(Command):
330
 
    """Move files to a different directory.
331
 
 
332
 
    examples:
333
 
        bzr move *.txt doc
334
 
 
335
 
    The destination must be a versioned directory in the same branch.
336
 
    """
337
 
    takes_args = ['source$', 'dest']
338
 
    def run(self, source_list, dest):
339
 
        tree, source_list = tree_files(source_list)
340
 
        # TODO: glob expansion on windows?
341
 
        tree.move(source_list, tree.relpath(dest))
342
 
 
343
 
 
344
 
class cmd_rename(Command):
345
 
    """Change the name of an entry.
346
 
 
347
 
    examples:
348
 
      bzr rename frob.c frobber.c
349
 
      bzr rename src/frob.c lib/frob.c
350
 
 
351
 
    It is an error if the destination name exists.
352
 
 
353
 
    See also the 'move' command, which moves files into a different
354
 
    directory without changing their name.
355
 
    """
356
 
    # TODO: Some way to rename multiple files without invoking 
357
 
    # bzr for each one?"""
358
 
    takes_args = ['from_name', 'to_name']
359
 
    
360
 
    def run(self, from_name, to_name):
361
 
        tree, (from_name, to_name) = tree_files((from_name, to_name))
362
 
        tree.rename_one(from_name, to_name)
363
 
 
364
 
 
365
329
class cmd_mv(Command):
366
330
    """Move or rename a file.
367
331
 
376
340
    Files cannot be moved between branches.
377
341
    """
378
342
    takes_args = ['names*']
 
343
    aliases = ['move', 'rename']
 
344
 
379
345
    def run(self, names_list):
380
346
        if len(names_list) < 2:
381
347
            raise BzrCommandError("missing file argument")
415
381
    takes_args = ['location?']
416
382
 
417
383
    def run(self, location=None, remember=False, overwrite=False, revision=None, verbose=False):
418
 
        # FIXME: too much stuff is in the command class        
419
 
        tree_to = WorkingTree.open_containing(u'.')[0]
420
 
        stored_loc = tree_to.branch.get_parent()
 
384
        # FIXME: too much stuff is in the command class
 
385
        try:
 
386
            tree_to = WorkingTree.open_containing(u'.')[0]
 
387
            branch_to = tree_to.branch
 
388
        except NoWorkingTree:
 
389
            tree_to = None
 
390
            branch_to = Branch.open_containing(u'.')[0] 
 
391
        stored_loc = branch_to.get_parent()
421
392
        if location is None:
422
393
            if stored_loc is None:
423
394
                raise BzrCommandError("No pull location known or specified.")
426
397
                location = stored_loc
427
398
 
428
399
        br_from = Branch.open(location)
429
 
        br_to = tree_to.branch
430
400
 
431
401
        if revision is None:
432
402
            rev_id = None
435
405
        else:
436
406
            raise BzrCommandError('bzr pull --revision takes one value.')
437
407
 
438
 
        old_rh = br_to.revision_history()
439
 
        count = tree_to.pull(br_from, overwrite, rev_id)
 
408
        old_rh = branch_to.revision_history()
 
409
        if tree_to is not None:
 
410
            count = tree_to.pull(br_from, overwrite, rev_id)
 
411
        else:
 
412
            count = branch_to.pull(br_from, overwrite, rev_id)
440
413
 
441
 
        if br_to.get_parent() is None or remember:
442
 
            br_to.set_parent(location)
 
414
        if branch_to.get_parent() is None or remember:
 
415
            branch_to.set_parent(location)
443
416
        note('%d revision(s) pulled.' % (count,))
444
417
 
445
418
        if verbose:
446
 
            new_rh = tree_to.branch.revision_history()
 
419
            new_rh = branch_to.revision_history()
447
420
            if old_rh != new_rh:
448
421
                # Something changed
449
422
                from bzrlib.log import show_changed_revisions
450
 
                show_changed_revisions(tree_to.branch, old_rh, new_rh)
 
423
                show_changed_revisions(branch_to, old_rh, new_rh)
451
424
 
452
425
 
453
426
class cmd_push(Command):
519
492
                        needed.append((new_transport,
520
493
                                       new_transport.relpath(transport.base)))
521
494
                        if new_transport.base == transport.base:
522
 
                            raise BzrCommandError("Could not creeate "
 
495
                            raise BzrCommandError("Could not create "
523
496
                                                  "path prefix.")
524
497
            dir_to = br_from.bzrdir.clone(location)
525
498
            br_to = dir_to.open_branch()
531
504
                # TODO: This should be updated for branches which don't have a
532
505
                # working tree, as opposed to ones where we just couldn't 
533
506
                # update the tree.
534
 
                warning('Unable to update the working tree of: %s' % (br_to.base,))
 
507
                warning('This transport does not update the working '
 
508
                        'tree of: %s' % (br_to.base,))
535
509
                count = br_to.pull(br_from, overwrite)
536
510
            except NoWorkingTree:
537
511
                count = br_to.pull(br_from, overwrite)
898
872
            # locations if the user supplies an extended path
899
873
            if not os.path.exists(location):
900
874
                os.mkdir(location)
 
875
        bzrdir.BzrDir.create_branch_convenience(location, format=format)
 
876
 
 
877
 
 
878
class cmd_init_repository(Command):
 
879
    """Create a shared repository to keep branches in."""
 
880
    takes_args = ["location"] 
 
881
    takes_options = [Option('format', 
 
882
                            help='Use a specific format rather than the'
 
883
                            ' current default format. Currently this'
 
884
                            ' option only accepts "metadir" and "knit"'
 
885
                            ' WARNING: the knit format is currently unstable'
 
886
                            ' and only for experimental use.',
 
887
                            type=get_format_type)]
 
888
    aliases = ["init-repo"]
 
889
    def run(self, location, format=None):
 
890
        from bzrlib.bzrdir import BzrDirMetaFormat1
 
891
        from bzrlib.transport import get_transport
901
892
        if format is None:
902
 
            # create default
903
 
            bzrdir.BzrDir.create_standalone_workingtree(location)
904
 
        else:
905
 
            new_dir = format.initialize(location)
906
 
            new_dir.create_repository()
907
 
            new_dir.create_branch()
908
 
            # TODO: ask the bzrdir format for the right classs
909
 
            import bzrlib.workingtree
910
 
            bzrlib.workingtree.WorkingTreeFormat3().initialize(new_dir)
 
893
            format = BzrDirMetaFormat1()
 
894
        get_transport(location).mkdir('')
 
895
        newdir = format.initialize(location)
 
896
        repo = newdir.create_repository(shared=True)
 
897
        repo.set_make_working_trees(False)
911
898
 
912
899
 
913
900
class cmd_diff(Command):
1459
1446
 
1460
1447
    def run(self, message=None, file=None, verbose=True, selected_list=None,
1461
1448
            unchanged=False, strict=False, local=False):
 
1449
        from bzrlib.commit import (NullCommitReporter, ReportCommitToLog)
1462
1450
        from bzrlib.errors import (PointlessCommit, ConflictsInTree,
1463
1451
                StrictCommitFailed)
1464
1452
        from bzrlib.msgeditor import edit_commit_message, \
1492
1480
 
1493
1481
        if message == "":
1494
1482
                raise BzrCommandError("empty commit message specified")
1495
 
            
 
1483
        
 
1484
        if verbose:
 
1485
            reporter = ReportCommitToLog()
 
1486
        else:
 
1487
            reporter = NullCommitReporter()
 
1488
        
1496
1489
        try:
1497
1490
            tree.commit(message, specific_files=selected_list,
1498
 
                        allow_pointless=unchanged, strict=strict, local=local)
 
1491
                        allow_pointless=unchanged, strict=strict, local=local,
 
1492
                        reporter=reporter)
1499
1493
        except PointlessCommit:
1500
1494
            # FIXME: This should really happen before the file is read in;
1501
1495
            # perhaps prepare the commit; get the message; then actually commit
1512
1506
                                  + ' Either unbind, update, or'
1513
1507
                                    ' pass --local to commit.')
1514
1508
 
1515
 
        note('Committed revision %d.' % (tree.branch.revno(),))
1516
 
 
1517
1509
 
1518
1510
class cmd_check(Command):
1519
1511
    """Validate consistency of branch history.
1564
1556
    takes_options = [
1565
1557
                     Option('format', 
1566
1558
                            help='Upgrade to a specific format rather than the'
1567
 
                                 ' current default format. Currently this '
1568
 
                                 ' option only accepts =metadir',
 
1559
                                 ' current default format. Currently this'
 
1560
                                 ' option only accepts -metadir and -knit'
 
1561
                                 ' WARNING: the knit format is currently'
 
1562
                                 ' unstable and only for experimental use.',
1569
1563
                            type=get_format_type),
1570
1564
                    ]
1571
1565
 
1980
1974
    For a list of all available commands, say 'bzr help commands'."""
1981
1975
    takes_options = [Option('long', 'show help on all commands')]
1982
1976
    takes_args = ['topic?']
1983
 
    aliases = ['?']
 
1977
    aliases = ['?', '--help', '-?', '-h']
1984
1978
    
1985
1979
    @display_command
1986
1980
    def run(self, topic=None, long=False):
2049
2043
                raise BzrCommandError("No missing location known or specified.")
2050
2044
            print "Using last location: " + local_branch.get_parent()
2051
2045
        remote_branch = bzrlib.branch.Branch.open(other_branch)
2052
 
        remote_branch.lock_read()
 
2046
        local_branch.lock_write()
 
2047
        if remote_branch.base == local_branch.base:
 
2048
            remote_branch = local_branch
2053
2049
        try:
2054
 
            local_branch.lock_write()
 
2050
            remote_branch.lock_read()
2055
2051
            try:
2056
2052
                local_extra, remote_extra = find_unmerged(local_branch, remote_branch)
2057
2053
                if (log_format == None):
2281
2277
        if location is None:
2282
2278
            location = u'.'
2283
2279
        control, relpath = bzrdir.BzrDir.open_containing(location)
2284
 
        b = control.open_branch()
2285
2280
        try:
2286
2281
            tree = control.open_workingtree()
 
2282
            b = tree.branch
2287
2283
        except (errors.NoWorkingTree, errors.NotLocalUrl):
2288
2284
            tree = None
 
2285
            b = control.open_branch()
2289
2286
 
2290
2287
        if revision is None:
2291
2288
            revno = b.revno()
2331
2328
                                 "don't break it"),
2332
2329
                    ]
2333
2330
    def run(self, location, show=False):
2334
 
        d = bzrdir.BzrDir.open(location)
2335
 
        repo = d.open_repository()
2336
 
        if not repo.is_locked():
2337
 
            raise errors.ObjectNotLocked(repo)
 
2331
        raise NotImplementedError("sorry, break-lock is not complete yet; "
 
2332
                "you can remove the 'held' directory manually to break the lock")
2338
2333
 
2339
2334
 
2340
2335
# command-line interpretation helper for merge-related commands
2408
2403
# these get imported and then picked up by the scan for cmd_*
2409
2404
# TODO: Some more consistent way to split command definitions across files;
2410
2405
# we do need to load at least some information about them to know of 
2411
 
# aliases.
 
2406
# aliases.  ideally we would avoid loading the implementation until the
 
2407
# details were needed.
2412
2408
from bzrlib.conflicts import cmd_resolve, cmd_conflicts, restore
2413
2409
from bzrlib.sign_my_commits import cmd_sign_my_commits
 
2410
from bzrlib.weave_commands import cmd_weave_list, cmd_weave_join, \
 
2411
        cmd_weave_plan_merge, cmd_weave_merge_text