~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Martin Pool
  • Date: 2006-03-10 06:29:53 UTC
  • mfrom: (1608 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1611.
  • Revision ID: mbp@sourcefrog.net-20060310062953-bc1c7ade75c89a7a
[merge] bzr.dev; pycurl not updated for readv yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
from bzrlib.log import show_one_log
37
37
from bzrlib.merge import Merge3Merger
38
38
from bzrlib.option import Option
39
 
from bzrlib.progress import DummyProgress
 
39
from bzrlib.progress import DummyProgress, ProgressPhase
40
40
from bzrlib.revisionspec import RevisionSpec
41
41
import bzrlib.trace
42
42
from bzrlib.trace import mutter, note, log_error, warning, is_quiet
70
70
    return tree, new_list
71
71
 
72
72
 
 
73
def get_format_type(typestring):
 
74
    """Parse and return a format specifier."""
 
75
    if typestring == "metadir":
 
76
        return bzrdir.BzrDirMetaFormat1()
 
77
    if typestring == "knit":
 
78
        format = bzrdir.BzrDirMetaFormat1()
 
79
        format.repository_format = bzrlib.repository.RepositoryFormatKnit1()
 
80
        return format
 
81
    msg = "No known bzr-dir format %s. Supported types are: metadir\n" %\
 
82
        (typestring)
 
83
    raise BzrCommandError(msg)
 
84
 
 
85
 
73
86
# TODO: Make sure no commands unconditionally use the working directory as a
74
87
# branch.  If a filename argument is used, the first of them should be used to
75
88
# specify the branch.  (Perhaps this can be factored out into some kind of
482
495
                print "Using saved location: %s" % stored_loc
483
496
                location = stored_loc
484
497
        try:
485
 
            br_to = Branch.open(location)
 
498
            dir_to = bzrlib.bzrdir.BzrDir.open(location)
 
499
            br_to = dir_to.open_branch()
486
500
        except NotBranchError:
487
501
            # create a branch.
488
502
            transport = get_transport(location).clone('..')
507
521
                        if new_transport.base == transport.base:
508
522
                            raise BzrCommandError("Could not creeate "
509
523
                                                  "path prefix.")
510
 
            br_to = bzrlib.bzrdir.BzrDir.create_branch_convenience(location)
 
524
            dir_to = br_from.bzrdir.clone(location)
 
525
            br_to = dir_to.open_branch()
511
526
        old_rh = br_to.revision_history()
512
527
        try:
513
528
            try:
514
 
                tree_to = br_to.working_tree()
515
 
            except NoWorkingTree:
 
529
                tree_to = dir_to.open_workingtree()
 
530
            except errors.NotLocalUrl:
516
531
                # TODO: This should be updated for branches which don't have a
517
532
                # working tree, as opposed to ones where we just couldn't 
518
533
                # update the tree.
519
534
                warning('Unable to update the working tree of: %s' % (br_to.base,))
520
535
                count = br_to.pull(br_from, overwrite)
 
536
            except NoWorkingTree:
 
537
                count = br_to.pull(br_from, overwrite)
521
538
            else:
522
539
                count = tree_to.pull(br_from, overwrite)
523
540
        except DivergedBranches:
862
879
        bzr commit -m 'imported project'
863
880
    """
864
881
    takes_args = ['location?']
865
 
    def run(self, location=None):
 
882
    takes_options = [
 
883
                     Option('format', 
 
884
                            help='Create a specific format rather than the'
 
885
                                 ' current default format. Currently this '
 
886
                                 ' option only accepts =metadir',
 
887
                            type=get_format_type),
 
888
                     ]
 
889
    def run(self, location=None, format=None):
866
890
        from bzrlib.branch import Branch
867
891
        if location is None:
868
892
            location = u'.'
874
898
            # locations if the user supplies an extended path
875
899
            if not os.path.exists(location):
876
900
                os.mkdir(location)
877
 
        bzrdir.BzrDir.create_standalone_workingtree(location)
 
901
        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)
878
911
 
879
912
 
880
913
class cmd_diff(Command):
1520
1553
            c.write()
1521
1554
 
1522
1555
 
1523
 
def get_format_type(typestring):
1524
 
    """Parse and return a format specifier."""
1525
 
    if typestring == "metadir":
1526
 
        return bzrdir.BzrDirMetaFormat1()
1527
 
    if typestring == "knit":
1528
 
        format = bzrdir.BzrDirMetaFormat1()
1529
 
        format.repository_format = bzrlib.repository.RepositoryFormatKnit1()
1530
 
        return format
1531
 
    msg = "No known bzr-dir format %s. Supported types are: metadir\n" %\
1532
 
        (typestring)
1533
 
    raise BzrCommandError(msg)
1534
 
 
1535
 
 
1536
1556
class cmd_upgrade(Command):
1537
1557
    """Upgrade branch storage to current format.
1538
1558
 
1766
1786
    will be used as a BASE, and the second one as OTHER.  Revision
1767
1787
    numbers are always relative to the specified branch.
1768
1788
 
1769
 
    By default bzr will try to merge in all new work from the other
 
1789
    By default, bzr will try to merge in all new work from the other
1770
1790
    branch, automatically determining an appropriate base.  If this
1771
1791
    fails, you may need to give an explicit base.
1772
1792
    
 
1793
    Merge will do its best to combine the changes in two branches, but there
 
1794
    are some kinds of problems only a human can fix.  When it encounters those,
 
1795
    it will mark a conflict.  A conflict means that you need to fix something,
 
1796
    before you should commit.
 
1797
 
 
1798
    Use bzr resolve when you have fixed a problem.  See also bzr conflicts.
 
1799
 
1773
1800
    Examples:
1774
1801
 
1775
1802
    To merge the latest revision from bzr.dev
1817
1844
 
1818
1845
                base = [branch, revision[0].in_history(b).revno]
1819
1846
                other = [branch, revision[1].in_history(b).revno]
1820
 
 
 
1847
        pb = bzrlib.ui.ui_factory.nested_progress_bar()
1821
1848
        try:
1822
 
            conflict_count = merge(other, base, check_clean=(not force),
1823
 
                                   merge_type=merge_type, reprocess=reprocess,
1824
 
                                   show_base=show_base, 
1825
 
                                   pb=bzrlib.ui.ui_factory.progress_bar())
 
1849
            try:
 
1850
                conflict_count = merge(other, base, check_clean=(not force),
 
1851
                                       merge_type=merge_type, 
 
1852
                                       reprocess=reprocess,
 
1853
                                       show_base=show_base, 
 
1854
                                       pb=pb)
 
1855
            finally:
 
1856
                pb.finished()
1826
1857
            if conflict_count != 0:
1827
1858
                return 1
1828
1859
            else:
1886
1917
                    restore(tree.abspath(filename))
1887
1918
                except NotConflicted:
1888
1919
                    pass
1889
 
            conflicts =  merge_inner(tree.branch, other_tree, base_tree, 
 
1920
            conflicts =  merge_inner(tree.branch, other_tree, base_tree,
 
1921
                                     this_tree=tree,
1890
1922
                                     interesting_ids = interesting_ids, 
1891
1923
                                     other_rev_id=pending_merges[0], 
1892
1924
                                     merge_type=merge_type, 
1921
1953
        tree, file_list = tree_files(file_list)
1922
1954
        if revision is None:
1923
1955
            # FIXME should be tree.last_revision
1924
 
            rev_id = tree.branch.last_revision()
 
1956
            rev_id = tree.last_revision()
1925
1957
        elif len(revision) != 1:
1926
1958
            raise BzrCommandError('bzr revert --revision takes exactly 1 argument')
1927
1959
        else:
1928
1960
            rev_id = revision[0].in_history(tree.branch).rev_id
1929
 
        tree.revert(file_list, tree.branch.repository.revision_tree(rev_id),
1930
 
                    not no_backup, bzrlib.ui.ui_factory.progress_bar())
 
1961
        pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
1962
        try:
 
1963
            tree.revert(file_list, 
 
1964
                        tree.branch.repository.revision_tree(rev_id),
 
1965
                        not no_backup, pb)
 
1966
        finally:
 
1967
            pb.finished()
1931
1968
 
1932
1969
 
1933
1970
class cmd_assert_fail(Command):
2012
2049
                raise BzrCommandError("No missing location known or specified.")
2013
2050
            print "Using last location: " + local_branch.get_parent()
2014
2051
        remote_branch = bzrlib.branch.Branch.open(other_branch)
2015
 
        local_extra, remote_extra = find_unmerged(local_branch, remote_branch)
2016
 
        if (log_format == None):
2017
 
            default = bzrlib.config.BranchConfig(local_branch).log_format()
2018
 
            log_format = get_log_format(long=long, short=short, line=line, default=default)
2019
 
        lf = log_formatter(log_format, sys.stdout,
2020
 
                           show_ids=show_ids,
2021
 
                           show_timezone='original')
2022
 
        if reverse is False:
2023
 
            local_extra.reverse()
2024
 
            remote_extra.reverse()
2025
 
        if local_extra and not theirs_only:
2026
 
            print "You have %d extra revision(s):" % len(local_extra)
2027
 
            for data in iter_log_data(local_extra, local_branch.repository,
2028
 
                                      verbose):
2029
 
                lf.show(*data)
2030
 
            printed_local = True
2031
 
        else:
2032
 
            printed_local = False
2033
 
        if remote_extra and not mine_only:
2034
 
            if printed_local is True:
2035
 
                print "\n\n"
2036
 
            print "You are missing %d revision(s):" % len(remote_extra)
2037
 
            for data in iter_log_data(remote_extra, remote_branch.repository, 
2038
 
                                      verbose):
2039
 
                lf.show(*data)
2040
 
        if not remote_extra and not local_extra:
2041
 
            status_code = 0
2042
 
            print "Branches are up to date."
2043
 
        else:
2044
 
            status_code = 1
2045
 
        if parent is None and other_branch is not None:
2046
 
            local_branch.set_parent(other_branch)
2047
 
        return status_code
 
2052
        remote_branch.lock_read()
 
2053
        try:
 
2054
            local_branch.lock_write()
 
2055
            try:
 
2056
                local_extra, remote_extra = find_unmerged(local_branch, remote_branch)
 
2057
                if (log_format == None):
 
2058
                    default = bzrlib.config.BranchConfig(local_branch).log_format()
 
2059
                    log_format = get_log_format(long=long, short=short, line=line, default=default)
 
2060
                lf = log_formatter(log_format, sys.stdout,
 
2061
                                   show_ids=show_ids,
 
2062
                                   show_timezone='original')
 
2063
                if reverse is False:
 
2064
                    local_extra.reverse()
 
2065
                    remote_extra.reverse()
 
2066
                if local_extra and not theirs_only:
 
2067
                    print "You have %d extra revision(s):" % len(local_extra)
 
2068
                    for data in iter_log_data(local_extra, local_branch.repository,
 
2069
                                              verbose):
 
2070
                        lf.show(*data)
 
2071
                    printed_local = True
 
2072
                else:
 
2073
                    printed_local = False
 
2074
                if remote_extra and not mine_only:
 
2075
                    if printed_local is True:
 
2076
                        print "\n\n"
 
2077
                    print "You are missing %d revision(s):" % len(remote_extra)
 
2078
                    for data in iter_log_data(remote_extra, remote_branch.repository, 
 
2079
                                              verbose):
 
2080
                        lf.show(*data)
 
2081
                if not remote_extra and not local_extra:
 
2082
                    status_code = 0
 
2083
                    print "Branches are up to date."
 
2084
                else:
 
2085
                    status_code = 1
 
2086
                if parent is None and other_branch is not None:
 
2087
                    local_branch.set_parent(other_branch)
 
2088
                return status_code
 
2089
            finally:
 
2090
                local_branch.unlock()
 
2091
        finally:
 
2092
            remote_branch.unlock()
2048
2093
 
2049
2094
 
2050
2095
class cmd_plugins(Command):
2337
2382
                              " type. %s" % merge_type)
2338
2383
    if reprocess and show_base:
2339
2384
        raise BzrCommandError("Cannot reprocess and show base.")
2340
 
    merger = Merger(this_tree.branch, this_tree=this_tree, pb=pb)
2341
 
    merger.check_basis(check_clean)
2342
 
    merger.set_other(other_revision)
2343
 
    merger.set_base(base_revision)
2344
 
    if merger.base_rev_id == merger.other_rev_id:
2345
 
        note('Nothing to do.')
2346
 
        return 0
2347
 
    merger.backup_files = backup_files
2348
 
    merger.merge_type = merge_type 
2349
 
    merger.set_interesting_files(file_list)
2350
 
    merger.show_base = show_base 
2351
 
    merger.reprocess = reprocess
2352
 
    conflicts = merger.do_merge()
2353
 
    merger.set_pending()
 
2385
    try:
 
2386
        merger = Merger(this_tree.branch, this_tree=this_tree, pb=pb)
 
2387
        merger.pp = ProgressPhase("Merge phase", 5, pb)
 
2388
        merger.pp.next_phase()
 
2389
        merger.check_basis(check_clean)
 
2390
        merger.set_other(other_revision)
 
2391
        merger.pp.next_phase()
 
2392
        merger.set_base(base_revision)
 
2393
        if merger.base_rev_id == merger.other_rev_id:
 
2394
            note('Nothing to do.')
 
2395
            return 0
 
2396
        merger.backup_files = backup_files
 
2397
        merger.merge_type = merge_type 
 
2398
        merger.set_interesting_files(file_list)
 
2399
        merger.show_base = show_base 
 
2400
        merger.reprocess = reprocess
 
2401
        conflicts = merger.do_merge()
 
2402
        merger.set_pending()
 
2403
    finally:
 
2404
        pb.clear()
2354
2405
    return conflicts
2355
2406
 
2356
2407