~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

Merged Martin

Show diffs side-by-side

added added

removed removed

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