/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

properly commit write group

Show diffs side-by-side

added added

removed removed

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