/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

Support submodules during fetch.

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
 
75
from dulwich.pack import load_pack_index
79
76
 
80
77
 
81
78
# Don't run any tests on GitSmartTransport as it is not intended to be 
100
97
    def has(self, relpath):
101
98
        return False
102
99
 
103
 
    def _get_client(self):
 
100
    def _get_client(self, thin_packs):
104
101
        raise NotImplementedError(self._get_client)
105
102
 
106
103
    def _get_path(self):
110
107
        if progress is None:
111
108
            def progress(text):
112
109
                info("git: %s" % text)
113
 
        client = self._get_client()
 
110
        client = self._get_client(thin_packs=False)
114
111
        try:
115
112
            return client.fetch_pack(self._get_path(), determine_wants, 
116
113
                graph_walker, pack_data, progress)
118
115
            raise BzrError(e)
119
116
 
120
117
    def send_pack(self, get_changed_refs, generate_pack_contents):
121
 
        client = self._get_client()
 
118
        client = self._get_client(thin_packs=False)
122
119
        try:
123
120
            return client.send_pack(self._get_path(), get_changed_refs, 
124
121
                generate_pack_contents)
145
142
 
146
143
    _scheme = 'git'
147
144
 
148
 
    def _get_client(self):
 
145
    def _get_client(self, thin_packs):
149
146
        if self._client is not None:
150
147
            ret = self._client
151
148
            self._client = None
152
149
            return ret
153
 
        return git.client.TCPGitClient(self._host, self._port, thin_packs=False,
 
150
        return git.client.TCPGitClient(self._host, self._port, thin_packs=thin_packs,
154
151
            report_activity=self._report_activity)
155
152
 
156
153
 
163
160
            return self._path[3:]
164
161
        return self._path
165
162
 
166
 
    def _get_client(self):
 
163
    def _get_client(self, thin_packs):
167
164
        if self._client is not None:
168
165
            ret = self._client
169
166
            self._client = None
170
167
            return ret
171
168
        return git.client.SSHGitClient(self._host, self._port, self._username,
172
 
            thin_packs=False, report_activity=self._report_activity)
 
169
            thin_packs=thin_packs, report_activity=self._report_activity)
173
170
 
174
171
 
175
172
class RemoteGitDir(GitDir):
189
186
        # TODO: Support for multiple branches in one bzrdir in bzrlib!
190
187
        return RemoteGitBranch(self, repo, "HEAD", self._lockfiles)
191
188
 
192
 
    def open_workingtree(self):
 
189
    def open_workingtree(self, recommend_upgrade=False):
193
190
        raise NotLocalUrl(self.transport.base)
194
191
 
195
192
 
206
203
        self.resolve_ext_ref = resolve_ext_ref
207
204
 
208
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
209
212
    def index(self):
210
213
        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()
 
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()
219
223
            self._idx = load_pack_index(self._idx_path)
220
224
        return self._idx
221
225
 
222
226
    def __del__(self):
223
 
        os.remove(self._data_path)
224
 
        os.remove(self._idx_path)
 
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)
225
233
 
226
234
 
227
235
class RemoteGitRepository(GitRepository):
246
254
        if self._refs is not None:
247
255
            return self._refs
248
256
        self._refs = self.bzrdir.root_transport.fetch_pack(lambda x: [], None, 
249
 
            lambda x: None, lambda x: mutter("git: %s" % x))
 
257
            lambda x: None, lambda x: trace.mutter("git: %s" % x))
250
258
        return self._refs
251
259
 
252
260
    def fetch_pack(self, determine_wants, graph_walker, pack_data, 
265
273
            return EmptyObjectStoreIterator()
266
274
        return TemporaryPackIterator(path[:-len(".pack")], resolve_ext_ref)
267
275
 
268
 
    def lookup_git_revid(self, bzr_revid):
 
276
    def lookup_bzr_revision_id(self, bzr_revid):
269
277
        # This won't work for any round-tripped bzr revisions, but it's a start..
270
278
        try:
271
279
            return mapping_registry.revision_id_bzr_to_foreign(bzr_revid)
280
288
        self.repository = branch.repository
281
289
 
282
290
    def get_tag_dict(self):
283
 
        return extract_tags(self.repository.get_refs(), self.branch.mapping)
 
291
        tags = {}
 
292
        for k, v in extract_tags(self.repository.get_refs()).iteritems():
 
293
            tags[k] = self.branch.mapping.revision_id_foreign_to_bzr(v)
 
294
        return tags
284
295
 
285
296
    def set_tag(self, name, revid):
286
297
        # FIXME: Not supported yet, should do a push of a new ref
300
311
    def last_revision(self):
301
312
        return self.mapping.revision_id_foreign_to_bzr(self.head)
302
313
 
 
314
    def _get_config(self):
 
315
        class EmptyConfig(object):
 
316
 
 
317
            def _get_configobj(self):
 
318
                return config.ConfigObj()
 
319
 
 
320
        return EmptyConfig()
 
321
 
303
322
    @property
304
323
    def head(self):
305
324
        if self._ref is not None:
306
325
            return self._ref
307
326
        heads = self.repository.get_refs()
308
327
        if not self.name in heads:
309
 
            raise NoSuchRef(name)
 
328
            raise NoSuchRef(self.name)
310
329
        self._ref = heads[self.name]
311
330
        return self._ref
312
331