/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 remote.py

More tests for sha maps, fix cache misses in tdb.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
 
17
import bzrlib
17
18
from bzrlib import (
18
 
    config,
 
19
    branch,
19
20
    tag,
20
 
    trace,
21
21
    ui,
22
22
    urlutils,
23
23
    )
55
55
    mapping_registry,
56
56
    )
57
57
from bzrlib.plugins.git.repository import (
 
58
    GitRepositoryFormat,
58
59
    GitRepository,
59
60
    )
60
61
 
71
72
import urllib
72
73
import urlparse
73
74
 
74
 
from dulwich.pack import load_pack_index
75
 
 
76
 
 
77
 
# Don't run any tests on GitSmartTransport as it is not intended to be
 
75
try:
 
76
    from dulwich.pack import load_pack_index
 
77
except ImportError:
 
78
    from dulwich.pack import PackIndex as load_pack_index
 
79
 
 
80
 
 
81
# Don't run any tests on GitSmartTransport as it is not intended to be 
78
82
# a full implementation of Transport
79
83
def get_test_permutations():
80
84
    return []
85
89
    def __init__(self, url, _client=None):
86
90
        Transport.__init__(self, url)
87
91
        (scheme, _, loc, _, _) = urlparse.urlsplit(url)
88
 
        hostport, escaped_path = urllib.splithost(loc)
89
 
        self._path = urllib.unquote(escaped_path)
 
92
        hostport, self._path = urllib.splithost(loc)
90
93
        (self._username, hostport) = urllib.splituser(hostport)
91
94
        (self._host, self._port) = urllib.splitnport(hostport, None)
92
95
        self._client = _client
93
96
 
94
 
    def external_url(self):
95
 
        return self.base
96
 
 
97
97
    def has(self, relpath):
98
98
        return False
99
99
 
100
 
    def _get_client(self, thin_packs):
 
100
    def _get_client(self):
101
101
        raise NotImplementedError(self._get_client)
102
102
 
103
103
    def _get_path(self):
107
107
        if progress is None:
108
108
            def progress(text):
109
109
                info("git: %s" % text)
110
 
        client = self._get_client(thin_packs=False)
 
110
        client = self._get_client()
111
111
        try:
112
 
            return client.fetch_pack(self._get_path(), determine_wants,
 
112
            return client.fetch_pack(self._get_path(), determine_wants, 
113
113
                graph_walker, pack_data, progress)
114
114
        except GitProtocolError, e:
115
115
            raise BzrError(e)
116
116
 
117
117
    def send_pack(self, get_changed_refs, generate_pack_contents):
118
 
        client = self._get_client(thin_packs=False)
 
118
        client = self._get_client()
119
119
        try:
120
 
            return client.send_pack(self._get_path(), get_changed_refs,
 
120
            return client.send_pack(self._get_path(), get_changed_refs, 
121
121
                generate_pack_contents)
122
122
        except GitProtocolError, e:
123
123
            raise BzrError(e)
142
142
 
143
143
    _scheme = 'git'
144
144
 
145
 
    def _get_client(self, thin_packs):
 
145
    def _get_client(self):
146
146
        if self._client is not None:
147
147
            ret = self._client
148
148
            self._client = None
149
149
            return ret
150
 
        return git.client.TCPGitClient(self._host, self._port, thin_packs=thin_packs,
 
150
        return git.client.TCPGitClient(self._host, self._port, thin_packs=False,
151
151
            report_activity=self._report_activity)
152
152
 
153
153
 
160
160
            return self._path[3:]
161
161
        return self._path
162
162
 
163
 
    def _get_client(self, thin_packs):
 
163
    def _get_client(self):
164
164
        if self._client is not None:
165
165
            ret = self._client
166
166
            self._client = None
167
167
            return ret
168
168
        return git.client.SSHGitClient(self._host, self._port, self._username,
169
 
            thin_packs=thin_packs, report_activity=self._report_activity)
 
169
            thin_packs=False, report_activity=self._report_activity)
170
170
 
171
171
 
172
172
class RemoteGitDir(GitDir):
186
186
        # TODO: Support for multiple branches in one bzrdir in bzrlib!
187
187
        return RemoteGitBranch(self, repo, "HEAD", self._lockfiles)
188
188
 
189
 
    def open_workingtree(self, recommend_upgrade=False):
 
189
    def open_workingtree(self):
190
190
        raise NotLocalUrl(self.transport.base)
191
191
 
192
192
 
203
203
        self.resolve_ext_ref = resolve_ext_ref
204
204
 
205
205
    @property
206
 
    def data(self):
207
 
        if self._data is None:
208
 
            self._data = PackData(self._data_path)
209
 
        return self._data
210
 
 
211
 
    @property
212
206
    def index(self):
213
207
        if self._idx is None:
214
 
            if not os.path.exists(self._idx_path):
215
 
                pb = ui.ui_factory.nested_progress_bar()
216
 
                try:
217
 
                    def report_progress(cur, total):
218
 
                        pb.update("generating index", cur, total)
219
 
                    self.data.create_index(self._idx_path, self.resolve_ext_ref,
220
 
                        progress=report_progress)
221
 
                finally:
222
 
                    pb.finished()
 
208
            if self._data is None:
 
209
                self._data = PackData(self._data_path)
 
210
            pb = ui.ui_factory.nested_progress_bar()
 
211
            try:
 
212
                def report_progress(cur, total):
 
213
                    pb.update("generating index", cur, total)
 
214
                self._data.create_index_v2(self._idx_path, self.resolve_ext_ref,
 
215
                    progress=report_progress)
 
216
            finally:
 
217
                pb.finished()
223
218
            self._idx = load_pack_index(self._idx_path)
224
219
        return self._idx
225
220
 
226
221
    def __del__(self):
227
 
        if self._idx is not None:
228
 
            self._idx.close()
229
 
            os.remove(self._idx_path)
230
 
        if self._data is not None:
231
 
            self._data.close()
232
 
            os.remove(self._data_path)
 
222
        os.remove(self._data_path)
 
223
        os.remove(self._idx_path)
233
224
 
234
225
 
235
226
class RemoteGitRepository(GitRepository):
253
244
    def get_refs(self):
254
245
        if self._refs is not None:
255
246
            return self._refs
256
 
        self._refs = self.bzrdir.root_transport.fetch_pack(lambda x: [], None,
257
 
            lambda x: None, lambda x: trace.mutter("git: %s" % x))
 
247
        self._refs = self.bzrdir.root_transport.fetch_pack(lambda x: [], None, 
 
248
            lambda x: None, lambda x: mutter("git: %s" % x))
258
249
        return self._refs
259
250
 
260
 
    def fetch_pack(self, determine_wants, graph_walker, pack_data,
 
251
    def fetch_pack(self, determine_wants, graph_walker, pack_data, 
261
252
                   progress=None):
262
253
        return self._transport.fetch_pack(determine_wants, graph_walker,
263
254
                                          pack_data, progress)
265
256
    def send_pack(self, get_changed_refs, generate_pack_contents):
266
257
        return self._transport.send_pack(get_changed_refs, generate_pack_contents)
267
258
 
268
 
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref,
269
 
                      progress=None):
 
259
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref, progress=None):
270
260
        fd, path = tempfile.mkstemp(suffix=".pack")
271
 
        self.fetch_pack(determine_wants, graph_walker,
272
 
            lambda x: os.write(fd, x), progress)
 
261
        self.fetch_pack(determine_wants, graph_walker, lambda x: os.write(fd, x), progress)
273
262
        os.close(fd)
274
263
        if os.path.getsize(path) == 0:
275
264
            return EmptyObjectStoreIterator()
276
265
        return TemporaryPackIterator(path[:-len(".pack")], resolve_ext_ref)
277
266
 
278
 
    def lookup_bzr_revision_id(self, bzr_revid):
 
267
    def lookup_git_revid(self, bzr_revid):
279
268
        # This won't work for any round-tripped bzr revisions, but it's a start..
280
269
        try:
281
270
            return mapping_registry.revision_id_bzr_to_foreign(bzr_revid)
290
279
        self.repository = branch.repository
291
280
 
292
281
    def get_tag_dict(self):
293
 
        tags = {}
294
 
        for k, v in extract_tags(self.repository.get_refs()).iteritems():
295
 
            tags[k] = self.branch.mapping.revision_id_foreign_to_bzr(v)
296
 
        return tags
 
282
        return extract_tags(self.repository.get_refs(), self.branch.mapping)
297
283
 
298
284
    def set_tag(self, name, revid):
299
285
        # FIXME: Not supported yet, should do a push of a new ref
304
290
 
305
291
    def __init__(self, bzrdir, repository, name, lockfiles):
306
292
        self._ref = None
307
 
        super(RemoteGitBranch, self).__init__(bzrdir, repository, name,
 
293
        super(RemoteGitBranch, self).__init__(bzrdir, repository, name, 
308
294
                lockfiles)
309
295
 
310
296
    def revision_history(self):
313
299
    def last_revision(self):
314
300
        return self.mapping.revision_id_foreign_to_bzr(self.head)
315
301
 
316
 
    def _get_config(self):
317
 
        class EmptyConfig(object):
318
 
 
319
 
            def _get_configobj(self):
320
 
                return config.ConfigObj()
321
 
 
322
 
        return EmptyConfig()
323
 
 
324
302
    @property
325
303
    def head(self):
326
304
        if self._ref is not None:
327
305
            return self._ref
328
306
        heads = self.repository.get_refs()
329
307
        if not self.name in heads:
330
 
            raise NoSuchRef(self.name)
 
308
            raise NoSuchRef(name)
331
309
        self._ref = heads[self.name]
332
310
        return self._ref
333
311
 
334
312
    def _synchronize_history(self, destination, revision_id):
335
313
        """See Branch._synchronize_history()."""
336
314
        destination.generate_revision_history(self.last_revision())
337
 
 
338
 
    def get_push_location(self):
339
 
        return None
340
 
 
341
 
    def set_push_location(self, url):
342
 
        pass
 
315