~bzr-pqm/bzr/bzr.dev

« 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:
52
52
        raise BzrCommandError("%s is not in the same branch as %s" %
53
53
                             (e.path, file_list[0]))
54
54
 
 
55
 
 
56
# XXX: Bad function name; should possibly also be a class method of
 
57
# WorkingTree rather than a function.
55
58
def internal_tree_files(file_list, default_branch=u'.'):
56
 
    """\
57
 
    Return a branch and list of branch-relative paths.
58
 
    If supplied file_list is empty or None, the branch default will be used,
59
 
    and returned file_list will match the original.
 
59
    """Convert command-line paths to a WorkingTree and relative paths.
 
60
 
 
61
    This is typically used for command-line processors that take one or
 
62
    more filenames, and infer the workingtree that contains them.
 
63
 
 
64
    The filenames given are not required to exist.
 
65
 
 
66
    :param file_list: Filenames to convert.  
 
67
 
 
68
    :param default_branch: Fallback tree path to use if file_list is empty or None.
 
69
 
 
70
    :return: workingtree, [relative_paths]
60
71
    """
61
72
    if file_list is None or len(file_list) == 0:
62
73
        return WorkingTree.open_containing(default_branch)[0], file_list
360
371
            
361
372
    
362
373
class cmd_pull(Command):
363
 
    """Pull any changes from another branch into the current one.
 
374
    """Turn this branch into a mirror of another branch.
 
375
 
 
376
    This command only works on branches that have not diverged.  Branches are
 
377
    considered diverged if the destination branch's most recent commit is one
 
378
    that has not been merged (directly or indirectly) into the parent.
 
379
 
 
380
    If branches have diverged, you can use 'bzr merge' to integrate the changes
 
381
    from one into the other.  Once one branch has merged, the other should
 
382
    be able to pull it again.
 
383
 
 
384
    If branches have diverged, you can use 'bzr merge' to pull the text changes
 
385
    from one into the other.  Once one branch has merged, the other should
 
386
    be able to pull it again.
 
387
 
 
388
    If you want to forget your local changes and just update your branch to
 
389
    match the remote one, use pull --overwrite.
364
390
 
365
391
    If there is no default location set, the first pull will set it.  After
366
392
    that, you can omit the location to use the default.  To change the
367
393
    default, use --remember.
368
 
 
369
 
    This command only works on branches that have not diverged.  Branches are
370
 
    considered diverged if both branches have had commits without first
371
 
    pulling from the other.
372
 
 
373
 
    If branches have diverged, you can use 'bzr merge' to pull the text changes
374
 
    from one into the other.  Once one branch has merged, the other should
375
 
    be able to pull it again.
376
 
 
377
 
    If you want to forget your local changes and just update your branch to
378
 
    match the remote one, use --overwrite.
379
394
    """
380
395
    takes_options = ['remember', 'overwrite', 'revision', 'verbose']
381
396
    takes_args = ['location?']
396
411
                print "Using saved location: %s" % stored_loc
397
412
                location = stored_loc
398
413
 
399
 
        br_from = Branch.open(location)
 
414
        if branch_to.get_parent() is None or remember:
 
415
            branch_to.set_parent(location)
 
416
 
 
417
        branch_from = Branch.open(location)
400
418
 
401
419
        if revision is None:
402
420
            rev_id = None
403
421
        elif len(revision) == 1:
404
 
            rev_id = revision[0].in_history(br_from).rev_id
 
422
            rev_id = revision[0].in_history(branch_from).rev_id
405
423
        else:
406
424
            raise BzrCommandError('bzr pull --revision takes one value.')
407
425
 
408
426
        old_rh = branch_to.revision_history()
409
427
        if tree_to is not None:
410
 
            count = tree_to.pull(br_from, overwrite, rev_id)
 
428
            count = tree_to.pull(branch_from, overwrite, rev_id)
411
429
        else:
412
 
            count = branch_to.pull(br_from, overwrite, rev_id)
413
 
 
414
 
        if branch_to.get_parent() is None or remember:
415
 
            branch_to.set_parent(location)
 
430
            count = branch_to.pull(branch_from, overwrite, rev_id)
416
431
        note('%d revision(s) pulled.' % (count,))
417
432
 
418
433
        if verbose:
424
439
 
425
440
 
426
441
class cmd_push(Command):
427
 
    """Push this branch into another branch.
428
 
    
429
 
    The remote branch will not have its working tree populated because this
430
 
    is both expensive, and may not be supported on the remote file system.
431
 
    
432
 
    Some smart servers or protocols *may* put the working tree in place.
 
442
    """Update a mirror of this branch.
 
443
    
 
444
    The target branch will not have its working tree populated because this
 
445
    is both expensive, and is not supported on remote file systems.
 
446
    
 
447
    Some smart servers or protocols *may* put the working tree in place in
 
448
    the future.
 
449
 
 
450
    This command only works on branches that have not diverged.  Branches are
 
451
    considered diverged if the destination branch's most recent commit is one
 
452
    that has not been merged (directly or indirectly) by the source branch.
 
453
 
 
454
    If branches have diverged, you can use 'bzr push --overwrite' to replace
 
455
    the other branch completely, discarding its unmerged changes.
 
456
    
 
457
    If you want to ensure you have the different changes in the other branch,
 
458
    do a merge (see bzr help merge) from the other branch, and commit that.
 
459
    After that you will be able to do a push without '--overwrite'.
433
460
 
434
461
    If there is no default push location set, the first push will set it.
435
462
    After that, you can omit the location to use the default.  To change the
436
463
    default, use --remember.
437
 
 
438
 
    This command only works on branches that have not diverged.  Branches are
439
 
    considered diverged if the branch being pushed to is not an older version
440
 
    of this branch.
441
 
 
442
 
    If branches have diverged, you can use 'bzr push --overwrite' to replace
443
 
    the other branch completely.
444
 
    
445
 
    If you want to ensure you have the different changes in the other branch,
446
 
    do a merge (see bzr help merge) from the other branch, and commit that
447
 
    before doing a 'push --overwrite'.
448
464
    """
449
465
    takes_options = ['remember', 'overwrite', 
450
466
                     Option('create-prefix', 
467
483
            else:
468
484
                print "Using saved location: %s" % stored_loc
469
485
                location = stored_loc
 
486
        if br_from.get_push_location() is None or remember:
 
487
            br_from.set_push_location(location)
470
488
        try:
471
489
            dir_to = bzrlib.bzrdir.BzrDir.open(location)
472
490
            br_to = dir_to.open_branch()
514
532
        except DivergedBranches:
515
533
            raise BzrCommandError("These branches have diverged."
516
534
                                  "  Try a merge then push with overwrite.")
517
 
        if br_from.get_push_location() is None or remember:
518
 
            br_from.set_push_location(location)
519
535
        note('%d revision(s) pushed.' % (count,))
520
536
 
521
537
        if verbose:
750
766
class cmd_info(Command):
751
767
    """Show statistical information about a branch."""
752
768
    takes_args = ['branch?']
 
769
    takes_options = ['verbose']
753
770
    
754
771
    @display_command
755
 
    def run(self, branch=None):
 
772
    def run(self, branch=None, verbose=False):
756
773
        import bzrlib.info
757
 
        bzrlib.info.show_bzrdir_info(bzrdir.BzrDir.open_containing(branch)[0])
 
774
        bzrlib.info.show_bzrdir_info(bzrdir.BzrDir.open_containing(branch)[0],
 
775
                                     verbose=verbose)
758
776
 
759
777
 
760
778
class cmd_remove(Command):
875
893
                     Option('format', 
876
894
                            help='Create a specific format rather than the'
877
895
                                 ' current default format. Currently this '
878
 
                                 ' option only accepts =metadir',
 
896
                                 ' option only accepts "metadir"',
879
897
                            type=get_format_type),
880
898
                     ]
881
899
    def run(self, location=None, format=None):
890
908
            # locations if the user supplies an extended path
891
909
            if not os.path.exists(location):
892
910
                os.mkdir(location)
893
 
        bzrdir.BzrDir.create_branch_convenience(location, format=format)
 
911
        try:
 
912
            existing = bzrdir.BzrDir.open(location)
 
913
        except NotBranchError:
 
914
            bzrdir.BzrDir.create_branch_convenience(location, format=format)
 
915
        else:
 
916
            try:
 
917
                existing.open_branch()
 
918
            except NotBranchError:
 
919
                existing.create_branch()
 
920
                existing.create_workingtree()
 
921
            else:
 
922
                raise errors.AlreadyBranchError(location)
894
923
 
895
924
 
896
925
class cmd_init_repository(Command):
897
 
    """Create a shared repository to keep branches in."""
 
926
    """Create a shared repository to hold branches.
 
927
 
 
928
    New branches created under the repository directory will store their revisions
 
929
    in the repository, not in the branch directory, if the branch format supports
 
930
    shared storage.
 
931
 
 
932
    example:    
 
933
        bzr init-repo repo
 
934
        bzr init --format=metadir repo/trunk
 
935
        cd repo/trunk
 
936
        (add files here)
 
937
    """
898
938
    takes_args = ["location"] 
899
939
    takes_options = [Option('format', 
900
940
                            help='Use a specific format rather than the'
912
952
        from bzrlib.transport import get_transport
913
953
        if format is None:
914
954
            format = BzrDirMetaFormat1()
915
 
        get_transport(location).mkdir('')
916
 
        newdir = format.initialize(location)
 
955
        transport = get_transport(location)
 
956
        if not transport.has('.'):
 
957
            transport.mkdir('')
 
958
        newdir = format.initialize_on_transport(transport)
917
959
        repo = newdir.create_repository(shared=True)
918
960
        repo.set_make_working_trees(trees)
919
961
 
1587
1629
                     Option('format', 
1588
1630
                            help='Upgrade to a specific format rather than the'
1589
1631
                                 ' current default format. Currently this'
1590
 
                                 ' option only accepts -metadir and -knit'
 
1632
                                 ' option only accepts "metadir" and "knit".'
1591
1633
                                 ' WARNING: the knit format is currently'
1592
1634
                                 ' unstable and only for experimental use.',
1593
1635
                            type=get_format_type),
1824
1866
 
1825
1867
    Use bzr resolve when you have fixed a problem.  See also bzr conflicts.
1826
1868
 
 
1869
    If there is no default branch set, the first merge will set it. After
 
1870
    that, you can omit the branch to use the default.  To change the
 
1871
    default, use --remember.
 
1872
 
1827
1873
    Examples:
1828
1874
 
1829
1875
    To merge the latest revision from bzr.dev
1839
1885
    --force is given.
1840
1886
    """
1841
1887
    takes_args = ['branch?']
1842
 
    takes_options = ['revision', 'force', 'merge-type', 'reprocess',
 
1888
    takes_options = ['revision', 'force', 'merge-type', 'reprocess', 'remember',
1843
1889
                     Option('show-base', help="Show base revision text in "
1844
1890
                            "conflicts")]
1845
1891
 
1846
1892
    def run(self, branch=None, revision=None, force=False, merge_type=None,
1847
 
            show_base=False, reprocess=False):
 
1893
            show_base=False, reprocess=False, remember=False):
1848
1894
        if merge_type is None:
1849
1895
            merge_type = Merge3Merger
 
1896
 
 
1897
        tree = WorkingTree.open_containing(u'.')[0]
 
1898
        stored_loc = tree.branch.get_parent()
1850
1899
        if branch is None:
1851
 
            branch = WorkingTree.open_containing(u'.')[0].branch.get_parent()
1852
 
            if branch is None:
1853
 
                raise BzrCommandError("No merge location known or specified.")
 
1900
            if stored_loc is None:
 
1901
                raise BzrCommandError("No merge branch known or specified.")
1854
1902
            else:
1855
 
                print "Using saved location: %s" % branch 
 
1903
                print "Using saved branch: %s" % stored_loc
 
1904
                branch = stored_loc
 
1905
 
 
1906
        if tree.branch.get_parent() is None or remember:
 
1907
            tree.branch.set_parent(branch)
 
1908
 
1856
1909
        if revision is None or len(revision) < 1:
1857
1910
            base = [None, None]
1858
1911
            other = [branch, -1]
 
1912
            other_branch, path = Branch.open_containing(branch)
1859
1913
        else:
1860
1914
            if len(revision) == 1:
1861
1915
                base = [None, None]
1862
 
                other_branch = Branch.open_containing(branch)[0]
 
1916
                other_branch, path = Branch.open_containing(branch)
1863
1917
                revno = revision[0].in_history(other_branch).revno
1864
1918
                other = [branch, revno]
1865
1919
            else:
1867
1921
                if None in revision:
1868
1922
                    raise BzrCommandError(
1869
1923
                        "Merge doesn't permit that revision specifier.")
1870
 
                b = Branch.open_containing(branch)[0]
 
1924
                b, path = Branch.open_containing(branch)
1871
1925
 
1872
1926
                base = [branch, revision[0].in_history(b).revno]
1873
1927
                other = [branch, revision[1].in_history(b).revno]
 
1928
        if path != "":
 
1929
            interesting_files = [path]
 
1930
        else:
 
1931
            interesting_files = None
1874
1932
        pb = bzrlib.ui.ui_factory.nested_progress_bar()
1875
1933
        try:
1876
1934
            try:
1878
1936
                                       merge_type=merge_type, 
1879
1937
                                       reprocess=reprocess,
1880
1938
                                       show_base=show_base, 
1881
 
                                       pb=pb)
 
1939
                                       pb=pb, file_list=interesting_files)
1882
1940
            finally:
1883
1941
                pb.finished()
1884
1942
            if conflict_count != 0:
2427
2485
        merger.show_base = show_base 
2428
2486
        merger.reprocess = reprocess
2429
2487
        conflicts = merger.do_merge()
2430
 
        merger.set_pending()
 
2488
        if file_list is None:
 
2489
            merger.set_pending()
2431
2490
    finally:
2432
2491
        pb.clear()
2433
2492
    return conflicts