~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

Merge from bzr.ab.integration

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
866
879
        bzr commit -m 'imported project'
867
880
    """
868
881
    takes_args = ['location?']
869
 
    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):
870
890
        from bzrlib.branch import Branch
871
891
        if location is None:
872
892
            location = u'.'
878
898
            # locations if the user supplies an extended path
879
899
            if not os.path.exists(location):
880
900
                os.mkdir(location)
881
 
        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)
882
911
 
883
912
 
884
913
class cmd_diff(Command):
1524
1553
            c.write()
1525
1554
 
1526
1555
 
1527
 
def get_format_type(typestring):
1528
 
    """Parse and return a format specifier."""
1529
 
    if typestring == "metadir":
1530
 
        return bzrdir.BzrDirMetaFormat1()
1531
 
    if typestring == "knit":
1532
 
        format = bzrdir.BzrDirMetaFormat1()
1533
 
        format.repository_format = bzrlib.repository.RepositoryFormatKnit1()
1534
 
        return format
1535
 
    msg = "No known bzr-dir format %s. Supported types are: metadir\n" %\
1536
 
        (typestring)
1537
 
    raise BzrCommandError(msg)
1538
 
 
1539
 
 
1540
1556
class cmd_upgrade(Command):
1541
1557
    """Upgrade branch storage to current format.
1542
1558
 
1901
1917
                    restore(tree.abspath(filename))
1902
1918
                except NotConflicted:
1903
1919
                    pass
1904
 
            conflicts =  merge_inner(tree.branch, other_tree, base_tree, 
 
1920
            conflicts =  merge_inner(tree.branch, other_tree, base_tree,
 
1921
                                     this_tree=tree,
1905
1922
                                     interesting_ids = interesting_ids, 
1906
1923
                                     other_rev_id=pending_merges[0], 
1907
1924
                                     merge_type=merge_type, 
1936
1953
        tree, file_list = tree_files(file_list)
1937
1954
        if revision is None:
1938
1955
            # FIXME should be tree.last_revision
1939
 
            rev_id = tree.branch.last_revision()
 
1956
            rev_id = tree.last_revision()
1940
1957
        elif len(revision) != 1:
1941
1958
            raise BzrCommandError('bzr revert --revision takes exactly 1 argument')
1942
1959
        else:
2032
2049
                raise BzrCommandError("No missing location known or specified.")
2033
2050
            print "Using last location: " + local_branch.get_parent()
2034
2051
        remote_branch = bzrlib.branch.Branch.open(other_branch)
2035
 
        local_extra, remote_extra = find_unmerged(local_branch, remote_branch)
2036
 
        if (log_format == None):
2037
 
            default = bzrlib.config.BranchConfig(local_branch).log_format()
2038
 
            log_format = get_log_format(long=long, short=short, line=line, default=default)
2039
 
        lf = log_formatter(log_format, sys.stdout,
2040
 
                           show_ids=show_ids,
2041
 
                           show_timezone='original')
2042
 
        if reverse is False:
2043
 
            local_extra.reverse()
2044
 
            remote_extra.reverse()
2045
 
        if local_extra and not theirs_only:
2046
 
            print "You have %d extra revision(s):" % len(local_extra)
2047
 
            for data in iter_log_data(local_extra, local_branch.repository,
2048
 
                                      verbose):
2049
 
                lf.show(*data)
2050
 
            printed_local = True
2051
 
        else:
2052
 
            printed_local = False
2053
 
        if remote_extra and not mine_only:
2054
 
            if printed_local is True:
2055
 
                print "\n\n"
2056
 
            print "You are missing %d revision(s):" % len(remote_extra)
2057
 
            for data in iter_log_data(remote_extra, remote_branch.repository, 
2058
 
                                      verbose):
2059
 
                lf.show(*data)
2060
 
        if not remote_extra and not local_extra:
2061
 
            status_code = 0
2062
 
            print "Branches are up to date."
2063
 
        else:
2064
 
            status_code = 1
2065
 
        if parent is None and other_branch is not None:
2066
 
            local_branch.set_parent(other_branch)
2067
 
        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()
2068
2093
 
2069
2094
 
2070
2095
class cmd_plugins(Command):