/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

Share more code between local and remote classes, support opening remote branches.

Show diffs side-by-side

added added

removed removed

Lines of Context:
71
71
class GitDir(bzrdir.BzrDir):
72
72
    """An adapter to the '.git' dir used by git."""
73
73
 
74
 
    def is_supported(self):
75
 
        return True
76
 
 
77
 
    def cloning_metadir(self, stacked=False):
78
 
        return bzrlib.bzrdir.format_registry.make_bzrdir("1.9-rich-root")
79
 
 
80
 
 
81
 
class LocalGitDir(GitDir):
82
 
    """An adapter to the '.git' dir used by git."""
83
 
 
84
74
    _gitrepository_class = repository.LocalGitRepository
85
75
 
86
76
    def __init__(self, transport, lockfiles, gitrepo, format):
103
93
    get_repository_transport = get_branch_transport
104
94
    get_workingtree_transport = get_branch_transport
105
95
 
 
96
    def is_supported(self):
 
97
        return True
 
98
 
106
99
    def open_branch(self, ignored=None):
107
100
        """'create' a branch for this dir."""
108
101
        repo = self.open_repository()
109
 
        return branch.LocalGitBranch(self, repo, "HEAD", repo._git.head(), self._lockfiles)
 
102
        if repo._git.heads == []:
 
103
            head = None
 
104
        else:
 
105
            head = repo._git.head()
 
106
        return branch.LocalGitBranch(self, repo, "HEAD", head, self._lockfiles)
110
107
 
111
108
    def open_repository(self, shared=False):
112
109
        """'open' a repository for this dir."""
113
110
        return self._gitrepository_class(self, self._lockfiles)
114
111
 
115
112
    def open_workingtree(self, recommend_upgrade=True):
116
 
        if (not self._git.bare and 
117
 
            os.path.exists(os.path.join(self._git.controldir(), "index"))):
 
113
        if self._git.bare:
 
114
            loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
 
115
            raise errors.bzr_errors.NoWorkingTree(loc)
 
116
        else:
118
117
            return workingtree.GitWorkingTree(self, self.open_repository(), 
119
118
                                                  self.open_branch())
120
 
        loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
121
 
        raise errors.bzr_errors.NoWorkingTree(loc)
 
119
 
 
120
    def cloning_metadir(self, stacked=False):
 
121
        if stacked:
 
122
            return bzrlib.bzrdir.format_registry.make_bzrdir("pack-0.92")
 
123
        else:
 
124
            return bzrlib.bzrdir.format_registry.make_bzrdir("1.6")
122
125
 
123
126
    def create_repository(self, shared=False):
124
127
        return self.open_repository()
125
128
 
126
129
 
127
 
class GitBzrDirFormat(bzrdir.BzrDirFormat):
 
130
class LocalGitBzrDirFormat(bzrdir.BzrDirFormat):
 
131
    """The .git directory control format."""
 
132
 
 
133
    _gitdir_class = GitDir
128
134
    _lock_class = TransportLock
129
135
 
130
 
    def is_supported(self):
131
 
        return True
132
 
 
133
 
 
134
 
class LocalGitBzrDirFormat(GitBzrDirFormat):
135
 
    """The .git directory control format."""
136
 
 
137
 
    _gitdir_class = LocalGitDir
138
 
 
139
136
    @classmethod
140
137
    def _known_formats(self):
141
138
        return set([LocalGitBzrDirFormat()])
144
141
        """Open this directory.
145
142
 
146
143
        """
147
 
        import dulwich as git
 
144
        from bzrlib.plugins.git import git
148
145
        # we dont grok readonly - git isn't integrated with transport.
149
146
        url = transport.base
150
147
        if url.startswith('readonly+'):
160
157
    @classmethod
161
158
    def probe_transport(klass, transport):
162
159
        """Our format is present if the transport ends in '.not/'."""
163
 
        import dulwich as git
164
160
        # little ugly, but works
165
161
        format = klass()
166
162
        # delegate to the main opening code. This pays a double rtt cost at the
170
166
        try:
171
167
            format.open(transport)
172
168
            return format
173
 
        except git.errors.NotGitRepository, e:
 
169
        except Exception, e:
174
170
            raise errors.bzr_errors.NotBranchError(path=transport.base)
175
171
        raise errors.bzr_errors.NotBranchError(path=transport.base)
176
172
 
182
178
 
183
179
    def initialize_on_transport(self, transport):
184
180
        from bzrlib.transport.local import LocalTransport
185
 
        import dulwich as git
 
181
        from bzrlib.plugins.git import git
186
182
 
187
183
        if not isinstance(transport, LocalTransport):
188
184
            raise NotImplementedError(self.initialize, 
196
192
        return True
197
193
 
198
194
 
199
 
class RemoteGitBzrDirFormat(GitBzrDirFormat):
 
195
class RemoteGitBzrDirFormat(bzrdir.BzrDirFormat):
200
196
    """The .git directory control format."""
201
197
 
 
198
    _lock_class = TransportLock
 
199
 
202
200
    @classmethod
203
201
    def _known_formats(self):
204
202
        return set([RemoteGitBzrDirFormat()])
231
229
        try:
232
230
            transport.fetch_pack(lambda x: [], None, lambda x: None, 
233
231
                                 lambda x: mutter("git: %s" % x))
234
 
        except errors.git_errors.GitProtocolError:
 
232
        except GitProtocolException, e:
235
233
            raise errors.bzr_errors.NotBranchError(path=transport.base)
236
234
        else:
237
235
            return format
246
244
    def initialize_on_transport(self, transport):
247
245
        raise errors.bzr_errors.UninitializableFormat(self)
248
246
 
 
247
    def is_supported(self):
 
248
        return True