~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

Use global osutils, otherwise it creates a local var.

Which works, but causes us to run the import on every call.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 
30
30
from bzrlib.lazy_import import lazy_import
31
31
lazy_import(globals(), """
 
32
from stat import S_ISDIR
 
33
 
32
34
import bzrlib
33
35
from bzrlib import (
34
 
    branch as _mod_branch,
35
36
    cleanup,
36
37
    config,
37
38
    controldir,
48
49
    transport as _mod_transport,
49
50
    ui,
50
51
    urlutils,
 
52
    versionedfile,
51
53
    win32utils,
52
 
    workingtree_3,
 
54
    workingtree,
53
55
    workingtree_4,
54
56
    )
55
 
from bzrlib.repofmt import knitpack_repo
 
57
from bzrlib.repofmt import pack_repo
56
58
from bzrlib.transport import (
57
59
    do_catching_redirections,
58
60
    local,
1252
1254
    def has_workingtree(self):
1253
1255
        """Tell if this bzrdir contains a working tree.
1254
1256
 
 
1257
        This will still raise an exception if the bzrdir has a workingtree that
 
1258
        is remote & inaccessible.
 
1259
 
1255
1260
        Note: if you're going to open the working tree, you should just go
1256
1261
        ahead and try, and not ask permission first.
1257
1262
        """
1258
1263
        from bzrlib.workingtree import WorkingTreeFormat
1259
1264
        try:
1260
 
            WorkingTreeFormat.find_format_string(self)
 
1265
            WorkingTreeFormat.find_format(self)
1261
1266
        except errors.NoWorkingTree:
1262
1267
            return False
1263
1268
        return True
1703
1708
                    # stack_on is inaccessible, JFDI.
1704
1709
                    # TODO: bad monkey, hard-coded formats...
1705
1710
                    if self.repository_format.rich_root_data:
1706
 
                        new_repo_format = knitpack_repo.RepositoryFormatKnitPack5RichRoot()
 
1711
                        new_repo_format = pack_repo.RepositoryFormatKnitPack5RichRoot()
1707
1712
                    else:
1708
 
                        new_repo_format = knitpack_repo.RepositoryFormatKnitPack5()
 
1713
                        new_repo_format = pack_repo.RepositoryFormatKnitPack5()
1709
1714
            else:
1710
1715
                # If the target already supports stacking, then we know the
1711
1716
                # project is already able to use stacking, so auto-upgrade
1855
1860
            # TODO: conversions of Branch and Tree should be done by
1856
1861
            # InterXFormat lookups/some sort of registry.
1857
1862
            # Avoid circular imports
 
1863
            from bzrlib import branch as _mod_branch
1858
1864
            old = branch._format.__class__
1859
1865
            new = self.target_format.get_branch_format().__class__
1860
1866
            while old != new:
1883
1889
        else:
1884
1890
            # TODO: conversions of Branch and Tree should be done by
1885
1891
            # InterXFormat lookups
1886
 
            if (isinstance(tree, workingtree_3.WorkingTree3) and
 
1892
            if (isinstance(tree, workingtree.WorkingTree3) and
1887
1893
                not isinstance(tree, workingtree_4.DirStateWorkingTree) and
1888
1894
                isinstance(self.target_format.workingtree_format,
1889
1895
                    workingtree_4.DirStateWorkingTreeFormat)):
2110
2116
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2111
2117
    'Format using knits.  Recommended for interoperation with bzr <= 0.14.',
2112
2118
    branch_format='bzrlib.branch.BzrBranchFormat5',
2113
 
    tree_format='bzrlib.workingtree_3.WorkingTreeFormat3',
 
2119
    tree_format='bzrlib.workingtree.WorkingTreeFormat3',
2114
2120
    hidden=True,
2115
2121
    deprecated=True)
2116
2122
register_metadir(controldir.format_registry, 'dirstate',
2118
2124
    help='New in 0.15: Fast local operations. Compatible with bzr 0.8 and '
2119
2125
        'above when accessed over the network.',
2120
2126
    branch_format='bzrlib.branch.BzrBranchFormat5',
2121
 
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
 
2127
    # this uses bzrlib.workingtree.WorkingTreeFormat4 because importing
 
2128
    # directly from workingtree_4 triggers a circular import.
 
2129
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2122
2130
    hidden=True,
2123
2131
    deprecated=True)
2124
2132
register_metadir(controldir.format_registry, 'dirstate-tags',
2127
2135
        'network operations. Additionally adds support for tags.'
2128
2136
        ' Incompatible with bzr < 0.15.',
2129
2137
    branch_format='bzrlib.branch.BzrBranchFormat6',
2130
 
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
 
2138
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2131
2139
    hidden=True,
2132
2140
    deprecated=True)
2133
2141
register_metadir(controldir.format_registry, 'rich-root',
2135
2143
    help='New in 1.0.  Better handling of tree roots.  Incompatible with'
2136
2144
        ' bzr < 1.0.',
2137
2145
    branch_format='bzrlib.branch.BzrBranchFormat6',
2138
 
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
 
2146
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2139
2147
    hidden=True,
2140
2148
    deprecated=True)
2141
2149
register_metadir(controldir.format_registry, 'dirstate-with-subtree',
2144
2152
        'network operations. Additionally adds support for versioning nested '
2145
2153
        'bzr branches. Incompatible with bzr < 0.15.',
2146
2154
    branch_format='bzrlib.branch.BzrBranchFormat6',
2147
 
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
 
2155
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2148
2156
    experimental=True,
2149
2157
    hidden=True,
2150
2158
    )
2151
2159
register_metadir(controldir.format_registry, 'pack-0.92',
2152
 
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack1',
 
2160
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack1',
2153
2161
    help='New in 0.92: Pack-based format with data compatible with '
2154
2162
        'dirstate-tags format repositories. Interoperates with '
2155
2163
        'bzr repositories before 0.92 but cannot be read by bzr < 0.92. '
2156
2164
        ,
2157
2165
    branch_format='bzrlib.branch.BzrBranchFormat6',
2158
 
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
 
2166
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2159
2167
    )
2160
2168
register_metadir(controldir.format_registry, 'pack-0.92-subtree',
2161
 
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack3',
 
2169
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack3',
2162
2170
    help='New in 0.92: Pack-based format with data compatible with '
2163
2171
        'dirstate-with-subtree format repositories. Interoperates with '
2164
2172
        'bzr repositories before 0.92 but cannot be read by bzr < 0.92. '
2165
2173
        ,
2166
2174
    branch_format='bzrlib.branch.BzrBranchFormat6',
2167
 
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
 
2175
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2168
2176
    hidden=True,
2169
2177
    experimental=True,
2170
2178
    )
2171
2179
register_metadir(controldir.format_registry, 'rich-root-pack',
2172
 
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack4',
 
2180
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack4',
2173
2181
    help='New in 1.0: A variant of pack-0.92 that supports rich-root data '
2174
2182
         '(needed for bzr-svn and bzr-git).',
2175
2183
    branch_format='bzrlib.branch.BzrBranchFormat6',
2176
 
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
 
2184
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2177
2185
    hidden=True,
2178
2186
    )
2179
2187
register_metadir(controldir.format_registry, '1.6',
2180
 
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack5',
 
2188
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5',
2181
2189
    help='A format that allows a branch to indicate that there is another '
2182
2190
         '(stacked) repository that should be used to access data that is '
2183
2191
         'not present locally.',
2184
2192
    branch_format='bzrlib.branch.BzrBranchFormat7',
2185
 
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
 
2193
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2186
2194
    hidden=True,
2187
2195
    )
2188
2196
register_metadir(controldir.format_registry, '1.6.1-rich-root',
2189
 
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack5RichRoot',
 
2197
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5RichRoot',
2190
2198
    help='A variant of 1.6 that supports rich-root data '
2191
2199
         '(needed for bzr-svn and bzr-git).',
2192
2200
    branch_format='bzrlib.branch.BzrBranchFormat7',
2193
 
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
 
2201
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2194
2202
    hidden=True,
2195
2203
    )
2196
2204
register_metadir(controldir.format_registry, '1.9',
2197
 
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack6',
 
2205
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6',
2198
2206
    help='A repository format using B+tree indexes. These indexes '
2199
2207
         'are smaller in size, have smarter caching and provide faster '
2200
2208
         'performance for most operations.',
2201
2209
    branch_format='bzrlib.branch.BzrBranchFormat7',
2202
 
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
 
2210
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2203
2211
    hidden=True,
2204
2212
    )
2205
2213
register_metadir(controldir.format_registry, '1.9-rich-root',
2206
 
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack6RichRoot',
 
2214
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6RichRoot',
2207
2215
    help='A variant of 1.9 that supports rich-root data '
2208
2216
         '(needed for bzr-svn and bzr-git).',
2209
2217
    branch_format='bzrlib.branch.BzrBranchFormat7',
2210
 
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
 
2218
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2211
2219
    hidden=True,
2212
2220
    )
2213
2221
register_metadir(controldir.format_registry, '1.14',
2214
 
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack6',
 
2222
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6',
2215
2223
    help='A working-tree format that supports content filtering.',
2216
2224
    branch_format='bzrlib.branch.BzrBranchFormat7',
2217
 
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat5',
 
2225
    tree_format='bzrlib.workingtree.WorkingTreeFormat5',
2218
2226
    )
2219
2227
register_metadir(controldir.format_registry, '1.14-rich-root',
2220
 
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack6RichRoot',
 
2228
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6RichRoot',
2221
2229
    help='A variant of 1.14 that supports rich-root data '
2222
2230
         '(needed for bzr-svn and bzr-git).',
2223
2231
    branch_format='bzrlib.branch.BzrBranchFormat7',
2224
 
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat5',
 
2232
    tree_format='bzrlib.workingtree.WorkingTreeFormat5',
2225
2233
    )
2226
2234
# The following un-numbered 'development' formats should always just be aliases.
2227
2235
register_metadir(controldir.format_registry, 'development-subtree',
2233
2241
        'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
2234
2242
        'before use.',
2235
2243
    branch_format='bzrlib.branch.BzrBranchFormat7',
2236
 
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat6',
 
2244
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
2237
2245
    experimental=True,
2238
2246
    hidden=True,
2239
2247
    alias=False, # Restore to being an alias when an actual development subtree format is added
2241
2249
                 # chk based subtree format.
2242
2250
    )
2243
2251
register_metadir(controldir.format_registry, 'development5-subtree',
2244
 
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatPackDevelopment2Subtree',
 
2252
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2Subtree',
2245
2253
    help='Development format, subtree variant. Can convert data to and '
2246
2254
        'from pack-0.92-subtree (and anything compatible with '
2247
2255
        'pack-0.92-subtree) format repositories. Repositories and branches in '
2249
2257
        'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
2250
2258
        'before use.',
2251
2259
    branch_format='bzrlib.branch.BzrBranchFormat7',
2252
 
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat6',
 
2260
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
2253
2261
    experimental=True,
2254
2262
    hidden=True,
2255
2263
    alias=False,
2266
2274
        # 'storage in packs, 255-way hashed CHK inventory, bencode revision, group compress, '
2267
2275
        # 'rich roots. Supported by bzr 1.16 and later.',
2268
2276
    branch_format='bzrlib.branch.BzrBranchFormat7',
2269
 
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat6',
 
2277
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
2270
2278
    experimental=False,
2271
2279
    )
2272
2280
 
2275
2283
register_metadir(controldir.format_registry, 'default-rich-root',
2276
2284
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
2277
2285
    branch_format='bzrlib.branch.BzrBranchFormat7',
2278
 
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat6',
 
2286
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
2279
2287
    alias=True,
2280
2288
    hidden=True,
2281
2289
    help='Same as 2a.')