/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

Merge in dulwich.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""An adapter between a Git control dir and a Bazaar BzrDir"""
18
18
 
 
19
import git, os
 
20
 
 
21
import bzrlib
19
22
from bzrlib.lazy_import import lazy_import
20
23
from bzrlib import (
21
24
    bzrdir,
24
27
    )
25
28
 
26
29
lazy_import(globals(), """
 
30
from bzrlib.lockable_files import TransportLock
27
31
from bzrlib.plugins.git import (
28
32
    errors,
29
 
    git_branch,
30
 
    git_repository,
 
33
    branch,
 
34
    repository,
 
35
    workingtree,
31
36
    )
32
37
""")
33
38
 
35
40
class GitLock(object):
36
41
    """A lock that thunks through to Git."""
37
42
 
38
 
    def lock_write(self):
 
43
    def lock_write(self, token=None):
39
44
        pass
40
45
 
41
46
    def lock_read(self):
61
66
class GitDir(bzrdir.BzrDir):
62
67
    """An adapter to the '.git' dir used by git."""
63
68
 
64
 
    _gitrepository_class = git_repository.GitRepository
 
69
    _gitrepository_class = repository.GitRepository
65
70
 
66
 
    def __init__(self, transport, lockfiles, format):
 
71
    def __init__(self, transport, lockfiles, gitrepo, format):
67
72
        self._format = format
68
73
        self.root_transport = transport
69
 
        self.transport = transport.clone('.git')
 
74
        self._git = gitrepo
 
75
        if gitrepo.bare:
 
76
            self.transport = transport
 
77
        else:
 
78
            self.transport = transport.clone('.git')
70
79
        self._lockfiles = lockfiles
71
80
 
72
81
    def get_branch_transport(self, branch_format):
88
97
        if repo._git.heads == []:
89
98
            head = None
90
99
        else:
91
 
            head = repo._git.heads[0].commit.id
92
 
        return git_branch.GitBranch(self, repo, head, 
 
100
            head = filter(lambda h: h.name == repo._git.active_branch, repo._git.heads)[0].commit.id
 
101
        return branch.GitBranch(self, repo, head, 
93
102
                                    self.root_transport.base, self._lockfiles)
94
103
 
95
104
    def open_repository(self, shared=False):
97
106
        return self._gitrepository_class(self, self._lockfiles)
98
107
 
99
108
    def open_workingtree(self, recommend_upgrade=True):
100
 
        loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
101
 
        raise errors.bzr_errors.NoWorkingTree(loc)
102
 
 
103
 
    def cloning_metadir(self):
104
 
        return bzrdir.BzrDirFormat.get_default_format()
 
109
        if self._git.bare:
 
110
            loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
 
111
            raise errors.bzr_errors.NoWorkingTree(loc)
 
112
        else:
 
113
            return workingtree.GitWorkingTree(self, self.open_repository(), 
 
114
                                                  self.open_branch())
 
115
 
 
116
    def cloning_metadir(self, stacked=False):
 
117
        if stacked:
 
118
            return bzrlib.bzrdir.format_registry.make_bzrdir("pack-0.92")
 
119
        else:
 
120
            return bzrlib.bzrdir.format_registry.make_bzrdir("1.6")
 
121
 
 
122
    def create_repository(self, shared=False):
 
123
        return self.open_repository()
105
124
 
106
125
 
107
126
class GitBzrDirFormat(bzrdir.BzrDirFormat):
108
127
    """The .git directory control format."""
109
128
 
110
129
    _gitdir_class = GitDir
 
130
    _lock_class = TransportLock
111
131
 
112
132
    @classmethod
113
133
    def _known_formats(self):
114
134
        return set([GitBzrDirFormat()])
115
135
 
116
 
    def open(self, transport, _create=False, _found=None):
 
136
    def open(self, transport, _found=None):
117
137
        """Open this directory.
118
138
 
119
 
        :param _create: create the git dir on the fly. private to GitDirFormat.
120
139
        """
121
140
        # we dont grok readonly - git isn't integrated with transport.
122
141
        url = transport.base
123
142
        if url.startswith('readonly+'):
124
143
            url = url[len('readonly+'):]
125
 
        if not transport.has('.git'):
 
144
 
 
145
        try:
 
146
            gitrepo = git.repo.Repo(transport.local_abspath("."))
 
147
        except errors.bzr_errors.NotLocalUrl:
126
148
            raise errors.bzr_errors.NotBranchError(path=transport.base)
127
149
        lockfiles = GitLockableFiles(GitLock())
128
 
        return self._gitdir_class(transport, lockfiles, self)
 
150
        return self._gitdir_class(transport, lockfiles, gitrepo, self)
129
151
 
130
152
    @classmethod
131
153
    def probe_transport(klass, transport):
146
168
    def get_format_description(self):
147
169
        return "Local Git Repository"
148
170
 
 
171
    def get_format_string(self):
 
172
        return "Local Git Repository"
 
173
 
 
174
    def initialize_on_transport(self, transport):
 
175
        from bzrlib.transport.local import LocalTransport
 
176
 
 
177
        if not isinstance(transport, LocalTransport):
 
178
            raise NotImplementedError(self.initialize, 
 
179
                "Can't create Git Repositories/branches on "
 
180
                "non-local transports")
 
181
 
 
182
        git.repo.Repo.create(transport.local_abspath(".")) 
 
183
        return self.open(transport)
 
184
 
149
185
 
150
186
bzrdir.BzrDirFormat.register_control_format(GitBzrDirFormat)