~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

[merge] robert

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
from bzrlib.commands import Command, display_command
28
28
from bzrlib.branch import Branch
29
29
from bzrlib.errors import BzrError, BzrCheckError, BzrCommandError, NotBranchError
30
 
from bzrlib.errors import DivergedBranches
 
30
from bzrlib.errors import DivergedBranches, NoSuchFile, NoWorkingTree
31
31
from bzrlib.option import Option
32
32
from bzrlib.revisionspec import RevisionSpec
33
33
import bzrlib.trace
262
262
    def run(self, revision=None, show_ids=False):
263
263
        b = Branch.open_containing('.')[0]
264
264
        if revision is None:
265
 
            inv = b.read_working_inventory()
 
265
            inv = b.working_tree().read_working_inventory()
266
266
        else:
267
267
            if len(revision) > 1:
268
268
                raise BzrCommandError('bzr inventory --revision takes'
345
345
            print "%s => %s" % (rel_names[0], rel_names[1])
346
346
            
347
347
    
348
 
 
349
 
 
350
348
class cmd_pull(Command):
351
349
    """Pull any changes from another branch into the current one.
352
350
 
383
381
                location = stored_loc
384
382
        br_from = Branch.open(location)
385
383
        try:
386
 
            br_to.working_tree().pull(br_from, remember, overwrite)
 
384
            br_to.working_tree().pull(br_from, overwrite)
387
385
        except DivergedBranches:
388
386
            raise BzrCommandError("These branches have diverged."
389
387
                                  "  Try merge.")
 
388
        if br_to.get_parent() is None or remember:
 
389
            br_to.set_parent(location)
 
390
 
 
391
 
 
392
class cmd_push(Command):
 
393
    """Push this branch into another branch.
 
394
    
 
395
    The remote branch will not have its working tree populated because this
 
396
    is both expensive, and may not be supported on the remote file system.
 
397
    
 
398
    Some smart servers or protocols *may* put the working tree in place.
 
399
 
 
400
    If there is no default push location set, the first push will set it.
 
401
    After that, you can omit the location to use the default.  To change the
 
402
    default, use --remember.
 
403
 
 
404
    This command only works on branches that have not diverged.  Branches are
 
405
    considered diverged if the branch being pushed to is not an older version
 
406
    of this branch.
 
407
 
 
408
    If branches have diverged, you can use 'bzr push --overwrite' to replace
 
409
    the other branch completely.
 
410
    
 
411
    If you want to ensure you have the different changes in the other branch,
 
412
    do a merge (see bzr help merge) from the other branch, and commit that
 
413
    before doing a 'push --overwrite'.
 
414
    """
 
415
    takes_options = ['remember', 'overwrite', 
 
416
                     Option('create-prefix', 
 
417
                            help='Create the path leading up to the branch '
 
418
                                 'if it does not already exist')]
 
419
    takes_args = ['location?']
 
420
 
 
421
    def run(self, location=None, remember=False, overwrite=False,
 
422
            create_prefix=False):
 
423
        import errno
 
424
        from shutil import rmtree
 
425
        from bzrlib.transport import get_transport
 
426
        
 
427
        br_from = Branch.open_containing('.')[0]
 
428
        stored_loc = br_from.get_push_location()
 
429
        if location is None:
 
430
            if stored_loc is None:
 
431
                raise BzrCommandError("No push location known or specified.")
 
432
            else:
 
433
                print "Using saved location: %s" % stored_loc
 
434
                location = stored_loc
 
435
        try:
 
436
            br_to = Branch.open(location)
 
437
        except NotBranchError:
 
438
            # create a branch.
 
439
            transport = get_transport(location).clone('..')
 
440
            if not create_prefix:
 
441
                try:
 
442
                    transport.mkdir(transport.relpath(location))
 
443
                except NoSuchFile:
 
444
                    raise BzrCommandError("Parent directory of %s "
 
445
                                          "does not exist." % location)
 
446
            else:
 
447
                current = transport.base
 
448
                needed = [(transport, transport.relpath(location))]
 
449
                while needed:
 
450
                    try:
 
451
                        transport, relpath = needed[-1]
 
452
                        transport.mkdir(relpath)
 
453
                        needed.pop()
 
454
                    except NoSuchFile:
 
455
                        new_transport = transport.clone('..')
 
456
                        needed.append((new_transport,
 
457
                                       new_transport.relpath(transport.base)))
 
458
                        if new_transport.base == transport.base:
 
459
                            raise BzrCommandError("Could not creeate "
 
460
                                                  "path prefix.")
 
461
                        
 
462
            NoSuchFile
 
463
            br_to = Branch.initialize(location)
 
464
        try:
 
465
            br_to.pull(br_from, overwrite)
 
466
        except DivergedBranches:
 
467
            raise BzrCommandError("These branches have diverged."
 
468
                                  "  Try a merge then push with overwrite.")
 
469
        if br_from.get_push_location() is None or remember:
 
470
            br_from.set_push_location(location)
390
471
 
391
472
 
392
473
class cmd_branch(Command):
479
560
    def run(self, dir='.'):
480
561
        b = Branch.open_containing(dir)[0]
481
562
        old_inv = b.basis_tree().inventory
482
 
        new_inv = b.read_working_inventory()
 
563
        new_inv = b.working_tree().read_working_inventory()
483
564
 
484
565
        renames = list(bzrlib.tree.find_renames(old_inv, new_inv))
485
566
        renames.sort()
574
655
    """Display list of versioned directories in this branch."""
575
656
    @display_command
576
657
    def run(self):
577
 
        for name, ie in Branch.open_containing('.')[0].read_working_inventory().directories():
 
658
        for name, ie in (Branch.open_containing('.')[0].working_tree().
 
659
                         read_working_inventory().directories()):
578
660
            if name == '':
579
661
                print '.'
580
662
            else:
646
728
        b, file_list = branch_files(file_list)
647
729
        if revision is not None:
648
730
            if len(revision) == 1:
649
 
                show_diff(b, revision[0], specific_files=file_list,
650
 
                          external_diff_options=diff_options)
 
731
                return show_diff(b, revision[0], specific_files=file_list,
 
732
                                 external_diff_options=diff_options)
651
733
            elif len(revision) == 2:
652
 
                show_diff(b, revision[0], specific_files=file_list,
653
 
                          external_diff_options=diff_options,
654
 
                          revision2=revision[1])
 
734
                return show_diff(b, revision[0], specific_files=file_list,
 
735
                                 external_diff_options=diff_options,
 
736
                                 revision2=revision[1])
655
737
            else:
656
738
                raise BzrCommandError('bzr diff --revision takes exactly one or two revision identifiers')
657
739
        else:
658
 
            show_diff(b, None, specific_files=file_list,
659
 
                      external_diff_options=diff_options)
660
 
 
661
 
        
 
740
            return show_diff(b, None, specific_files=file_list,
 
741
                             external_diff_options=diff_options)
662
742
 
663
743
 
664
744
class cmd_deleted(Command):
771
851
        if filename:
772
852
            b, fp = Branch.open_containing(filename)
773
853
            if fp != '':
774
 
                file_id = b.read_working_inventory().path2id(fp)
 
854
                try:
 
855
                    inv = b.working_tree().read_working_inventory()
 
856
                except NoWorkingTree:
 
857
                    inv = b.get_inventory(b.last_revision())
 
858
                file_id = inv.path2id(fp)
775
859
            else:
776
860
                file_id = None  # points to branch root
777
861
        else:
830
914
    @display_command
831
915
    def run(self, filename):
832
916
        b, relpath = Branch.open_containing(filename)[0]
833
 
        inv = b.read_working_inventory()
 
917
        inv = b.working_tree().read_working_inventory()
834
918
        file_id = inv.path2id(relpath)
835
919
        for revno, revision_id, what in bzrlib.log.find_touching_revisions(b, file_id):
836
920
            print "%6d %s" % (revno, what)