/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

Cope with imports.

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
18
17
from bzrlib import (
19
 
    branch,
 
18
    config,
20
19
    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,
59
58
    GitRepository,
60
59
    )
61
60
 
72
71
import urllib
73
72
import urlparse
74
73
 
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 
 
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
82
78
# a full implementation of Transport
83
79
def get_test_permutations():
84
80
    return []
89
85
    def __init__(self, url, _client=None):
90
86
        Transport.__init__(self, url)
91
87
        (scheme, _, loc, _, _) = urlparse.urlsplit(url)
92
 
        hostport, self._path = urllib.splithost(loc)
 
88
        hostport, escaped_path = urllib.splithost(loc)
 
89
        self._path = urllib.unquote(escaped_path)
93
90
        (self._username, hostport) = urllib.splituser(hostport)
94
91
        (self._host, self._port) = urllib.splitnport(hostport, None)
95
92
        self._client = _client
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
 
            return client.fetch_pack(self._get_path(), determine_wants, 
 
112
            return client.fetch_pack(self._get_path(), determine_wants,
116
113
                graph_walker, pack_data, progress)
117
114
        except GitProtocolError, e:
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
 
            return client.send_pack(self._get_path(), get_changed_refs, 
 
120
            return client.send_pack(self._get_path(), get_changed_refs,
124
121
                generate_pack_contents)
125
122
        except GitProtocolError, e:
126
123
            raise BzrError(e)
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):
245
253
    def get_refs(self):
246
254
        if self._refs is not None:
247
255
            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))
 
256
        self._refs = self.bzrdir.root_transport.fetch_pack(lambda x: [], None,
 
257
            lambda x: None, lambda x: trace.mutter("git: %s" % x))
250
258
        return self._refs
251
259
 
252
 
    def fetch_pack(self, determine_wants, graph_walker, pack_data, 
 
260
    def fetch_pack(self, determine_wants, graph_walker, pack_data,
253
261
                   progress=None):
254
262
        return self._transport.fetch_pack(determine_wants, graph_walker,
255
263
                                          pack_data, progress)
257
265
    def send_pack(self, get_changed_refs, generate_pack_contents):
258
266
        return self._transport.send_pack(get_changed_refs, generate_pack_contents)
259
267
 
260
 
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref, progress=None):
 
268
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref,
 
269
                      progress=None):
261
270
        fd, path = tempfile.mkstemp(suffix=".pack")
262
 
        self.fetch_pack(determine_wants, graph_walker, lambda x: os.write(fd, x), progress)
 
271
        self.fetch_pack(determine_wants, graph_walker,
 
272
            lambda x: os.write(fd, x), progress)
263
273
        os.close(fd)
264
274
        if os.path.getsize(path) == 0:
265
275
            return EmptyObjectStoreIterator()
266
276
        return TemporaryPackIterator(path[:-len(".pack")], resolve_ext_ref)
267
277
 
268
 
    def lookup_git_revid(self, bzr_revid):
 
278
    def lookup_bzr_revision_id(self, bzr_revid):
269
279
        # This won't work for any round-tripped bzr revisions, but it's a start..
270
280
        try:
271
281
            return mapping_registry.revision_id_bzr_to_foreign(bzr_revid)
280
290
        self.repository = branch.repository
281
291
 
282
292
    def get_tag_dict(self):
283
 
        return extract_tags(self.repository.get_refs(), self.branch.mapping)
 
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
284
297
 
285
298
    def set_tag(self, name, revid):
286
299
        # FIXME: Not supported yet, should do a push of a new ref
291
304
 
292
305
    def __init__(self, bzrdir, repository, name, lockfiles):
293
306
        self._ref = None
294
 
        super(RemoteGitBranch, self).__init__(bzrdir, repository, name, 
 
307
        super(RemoteGitBranch, self).__init__(bzrdir, repository, name,
295
308
                lockfiles)
296
309
 
297
310
    def revision_history(self):
300
313
    def last_revision(self):
301
314
        return self.mapping.revision_id_foreign_to_bzr(self.head)
302
315
 
 
316
    def _get_config(self):
 
317
        class EmptyConfig(object):
 
318
 
 
319
            def _get_configobj(self):
 
320
                return config.ConfigObj()
 
321
 
 
322
        return EmptyConfig()
 
323
 
303
324
    @property
304
325
    def head(self):
305
326
        if self._ref is not None:
306
327
            return self._ref
307
328
        heads = self.repository.get_refs()
308
329
        if not self.name in heads:
309
 
            raise NoSuchRef(name)
 
330
            raise NoSuchRef(self.name)
310
331
        self._ref = heads[self.name]
311
332
        return self._ref
312
333
 
313
334
    def _synchronize_history(self, destination, revision_id):
314
335
        """See Branch._synchronize_history()."""
315
336
        destination.generate_revision_history(self.last_revision())
316
 
 
 
337
 
317
338
    def get_push_location(self):
318
339
        return None
319
340