/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to dir.py

Set RepositoryFormat.supports_external_lookups.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
    BareLocalGitControlDirFormat,
31
31
    LocalGitControlDirFormat,
32
32
    )
33
 
try:
34
 
    from bzrlib.controldir import (
35
 
        ControlDir,
36
 
        format_registry,
37
 
        )
38
 
except ImportError:
39
 
    # bzr < 2.3
40
 
    from bzrlib.bzrdir import (
41
 
        BzrDir,
42
 
        format_registry,
43
 
        )
44
 
    ControlDir = BzrDir
 
33
 
 
34
from bzrlib.controldir import (
 
35
    ControlDir,
 
36
    format_registry,
 
37
    )
45
38
 
46
39
 
47
40
class GitLock(object):
48
41
    """A lock that thunks through to Git."""
49
42
 
 
43
    def __init__(self):
 
44
        self.lock_name = "git lock"
 
45
 
50
46
    def lock_write(self, token=None):
51
47
        pass
52
48
 
121
117
    def get_config(self):
122
118
        return GitDirConfig()
123
119
 
 
120
    def clone_on_transport(self, transport, revision_id=None,
 
121
        force_new_repo=False, preserve_stacking=False, stacked_on=None,
 
122
        create_prefix=False, use_existing_dir=True, no_tree=False):
 
123
        from dulwich.protocol import ZERO_SHA
 
124
        """See ControlDir.clone_on_transport."""
 
125
        if no_tree:
 
126
            format = BareLocalGitControlDirFormat()
 
127
        else:
 
128
            format = LocalGitControlDirFormat()
 
129
        (target_repo, target_controldir, stacking, repo_policy) = format.initialize_on_transport_ex(transport, use_existing_dir=use_existing_dir, create_prefix=create_prefix, force_new_repo=force_new_repo)
 
130
        target_git_repo = target_repo._git
 
131
        source_repo = self.open_repository()
 
132
        source_git_repo = source_repo._git
 
133
        if revision_id is not None:
 
134
            git_sha, mapping = source_repo.lookup_bzr_revision_id(revision_id)
 
135
            if git_sha == ZERO_SHA:
 
136
                wants = []
 
137
            else:
 
138
                wants = [git_sha]
 
139
            determine_wants = lambda heads: wants
 
140
        else:
 
141
            determine_wants = target_git_repo.object_store.determine_wants_all
 
142
        refs = source_git_repo.fetch(target_git_repo, determine_wants)
 
143
        for name, val in refs.iteritems():
 
144
            target_git_repo.refs[name] = val
 
145
        lockfiles = GitLockableFiles(transport, GitLock())
 
146
        return self.__class__(transport, lockfiles, target_git_repo, format)
 
147
 
124
148
 
125
149
class LocalGitDir(GitDir):
126
150
    """An adapter to the '.git' dir used by git."""
162
186
        return ref
163
187
 
164
188
    def is_control_filename(self, filename):
165
 
        return filename == '.git' or filename.startswith('.git/')
 
189
        return (filename == '.git' or filename.startswith('.git/'))
166
190
 
167
191
    def get_branch_transport(self, branch_format, name=None):
168
192
        if branch_format is None:
215
239
                ret.append(self.open_branch(name=name))
216
240
        return ret
217
241
 
218
 
    def open_repository(self, shared=False):
 
242
    def open_repository(self):
219
243
        """'open' a repository for this dir."""
220
244
        return self._gitrepository_class(self, self._lockfiles)
221
245
 
239
263
        raise bzr_errors.NoWorkingTree(loc)
240
264
 
241
265
    def create_repository(self, shared=False):
 
266
        from bzrlib.plugins.git.repository import GitRepositoryFormat
 
267
        if shared:
 
268
            raise bzr_errors.IncompatibleFormat(GitRepositoryFormat(), self._format)
242
269
        return self.open_repository()
243
270
 
244
 
    def create_branch(self, name=None):
 
271
    def create_branch(self, name=None, repository=None):
245
272
        refname = self._branch_name_to_ref(name)
246
273
        from dulwich.protocol import ZERO_SHA
247
274
        self._git.refs[refname or "HEAD"] = ZERO_SHA
258
285
    def create_workingtree(self, revision_id=None, from_branch=None,
259
286
        accelerator_tree=None, hardlink=False):
260
287
        if self._git.bare:
261
 
            raise bzr_errors.BzrError("Can't create working tree in a bare repo")
 
288
            raise bzr_errors.UnsupportedOperation(self.create_workingtree, self)
262
289
        from dulwich.index import write_index
263
290
        from dulwich.pack import SHA1Writer
264
291
        f = open(self.transport.local_abspath("index"), 'w+')
278
305
        """
279
306
        return self.open_repository()
280
307
 
 
308
    def _find_or_create_repository(self, force_new_repo=None):
 
309
        return self.create_repository(shared=False)
 
310
 
281
311
    def _find_creation_modes(self):
282
312
        """Determine the appropriate modes for files and directories.
283
313
 
291
321
        self._mode_check_done = True
292
322
        try:
293
323
            st = self.transport.stat('.')
294
 
        except TransportNotPossible:
 
324
        except bzr_errors.TransportNotPossible:
295
325
            self._dir_mode = None
296
326
            self._file_mode = None
297
327
        else:
322
352
            self._find_creation_modes()
323
353
        return self._dir_mode
324
354
 
325