/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

Fix regression in git-import.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2007 Canonical Ltd
 
2
# Copyright (C) 2010 Jelmer Vernooij
2
3
#
3
4
# This program is free software; you can redistribute it and/or modify
4
5
# it under the terms of the GNU General Public License as published by
28
29
 
29
30
from bzrlib.plugins.git import (
30
31
    LocalGitBzrDirFormat,
31
 
    get_rich_root_format,
32
32
    )
33
33
 
34
34
 
75
75
    def is_supported(self):
76
76
        return True
77
77
 
 
78
    def can_convert_format(self):
 
79
        return False
 
80
 
78
81
    def cloning_metadir(self, stacked=False):
79
 
        return get_rich_root_format(stacked)
 
82
        return bzrdir.format_registry.make_bzrdir("default")
80
83
 
81
84
    def _branch_name_to_ref(self, name):
82
 
        from bzrlib.plugins.git.branch import branch_name_to_ref
83
 
        return branch_name_to_ref(name)
 
85
        raise NotImplementedError(self._branch_name_to_ref)
84
86
 
85
87
    if bzrlib_version >= (2, 2):
86
 
        def open_branch(self, name=None, ignore_fallbacks=None,
87
 
            unsupported=False):
 
88
        def open_branch(self, name=None, unsupported=False, 
 
89
            ignore_fallbacks=None):
88
90
            return self._open_branch(name=name,
89
91
                ignore_fallbacks=ignore_fallbacks, unsupported=unsupported)
90
92
    else:
113
115
        self._lockfiles = lockfiles
114
116
        self._mode_check_done = None
115
117
 
 
118
    def _branch_name_to_ref(self, name):
 
119
        from bzrlib.plugins.git.refs import branch_name_to_ref
 
120
        ref = branch_name_to_ref(name, None)
 
121
        if ref == "HEAD":
 
122
            from dulwich.repo import SYMREF
 
123
            refcontents = self._git.refs.read_ref(ref)
 
124
            if refcontents.startswith(SYMREF):
 
125
                ref = refcontents[len(SYMREF):]
 
126
        return ref
 
127
 
116
128
    def is_control_filename(self, filename):
117
129
        return filename == '.git' or filename.startswith('.git/')
118
130
 
119
 
    def get_branch_transport(self, branch_format):
 
131
    def get_branch_transport(self, branch_format, name=None):
120
132
        if branch_format is None:
121
133
            return self.transport
122
134
        if isinstance(branch_format, LocalGitBzrDirFormat):
123
135
            return self.transport
124
136
        raise bzr_errors.IncompatibleFormat(branch_format, self._format)
125
137
 
126
 
    get_repository_transport = get_branch_transport
127
 
    get_workingtree_transport = get_branch_transport
 
138
    def get_repository_transport(self, format):
 
139
        if format is None:
 
140
            return self.transport
 
141
        if isinstance(format, LocalGitBzrDirFormat):
 
142
            return self.transport
 
143
        raise bzr_errors.IncompatibleFormat(format, self._format)
 
144
 
 
145
    def get_workingtree_transport(self, format):
 
146
        if format is None:
 
147
            return self.transport
 
148
        if isinstance(format, LocalGitBzrDirFormat):
 
149
            return self.transport
 
150
        raise bzr_errors.IncompatibleFormat(format, self._format)
128
151
 
129
152
    def _open_branch(self, name=None, ignore_fallbacks=None, unsupported=False):
130
153
        """'create' a branch for this dir."""
134
157
            self._lockfiles)
135
158
 
136
159
    def destroy_branch(self, name=None):
137
 
        del self._git.refs[self._branch_name_to_ref(name)]
 
160
        refname = self._branch_name_to_ref(name)
 
161
        if not refname in self._git.refs:
 
162
            raise bzr_errors.NotBranchError(self.root_transport.base,
 
163
                    bzrdir=self)
 
164
        del self._git.refs[refname]
 
165
 
 
166
    def destroy_repository(self):
 
167
        raise bzr_errors.UnsupportedOperation(self.destroy_repository, self)
 
168
 
 
169
    def destroy_workingtree(self):
 
170
        raise bzr_errors.UnsupportedOperation(self.destroy_workingtree, self)
 
171
 
 
172
    def needs_format_conversion(self, format=None):
 
173
        return not isinstance(self._format, format.__class__)
138
174
 
139
175
    def list_branches(self):
140
176
        ret = []
141
177
        for name in self._git.get_refs():
142
 
            if name.startswith("refs/heads/") or name == "HEAD":
 
178
            if name.startswith("refs/heads/"):
143
179
                ret.append(self.open_branch(name=name))
144
180
        return ret
145
181
 
157
193
                pass
158
194
            else:
159
195
                from bzrlib.plugins.git.workingtree import GitWorkingTree
160
 
                return GitWorkingTree(self, repo, self.open_branch(), index)
 
196
                try:
 
197
                    branch = self.open_branch()
 
198
                except bzr_errors.NotBranchError:
 
199
                    pass
 
200
                else:
 
201
                    return GitWorkingTree(self, repo, branch, index)
161
202
        loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
162
203
        raise bzr_errors.NoWorkingTree(loc)
163
204
 
166
207
 
167
208
    def create_branch(self, name=None):
168
209
        refname = self._branch_name_to_ref(name)
169
 
        self._git.refs[refname] = "0" * 40
 
210
        from dulwich.protocol import ZERO_SHA
 
211
        self._git.refs[refname or "HEAD"] = ZERO_SHA
170
212
        return self.open_branch(name)
171
213
 
172
214
    def backup_bzrdir(self):