/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

  • Committer: Jelmer Vernooij
  • Date: 2009-05-16 21:13:17 UTC
  • mto: (0.200.527 trunk)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@samba.org-20090516211317-a0s14tsrf2qusapf
Fix tests.

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
            pb = ui.ui_factory.nested_progress_bar()
 
209
            try:
 
210
                def report_progress(cur, total):
 
211
                    pb.update("generating index", cur, total)
 
212
                self.data.create_index(self._idx_path, self.resolve_ext_ref,
 
213
                    progress=report_progress)
 
214
            finally:
 
215
                pb.finished()
223
216
            self._idx = load_pack_index(self._idx_path)
224
217
        return self._idx
225
218
 
226
219
    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)
 
220
        os.remove(self._data_path)
 
221
        os.remove(self._idx_path)
233
222
 
234
223
 
235
224
class RemoteGitRepository(GitRepository):
253
242
    def get_refs(self):
254
243
        if self._refs is not None:
255
244
            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))
 
245
        self._refs = self.bzrdir.root_transport.fetch_pack(lambda x: [], None, 
 
246
            lambda x: None, lambda x: mutter("git: %s" % x))
258
247
        return self._refs
259
248
 
260
 
    def fetch_pack(self, determine_wants, graph_walker, pack_data,
 
249
    def fetch_pack(self, determine_wants, graph_walker, pack_data, 
261
250
                   progress=None):
262
251
        return self._transport.fetch_pack(determine_wants, graph_walker,
263
252
                                          pack_data, progress)
265
254
    def send_pack(self, get_changed_refs, generate_pack_contents):
266
255
        return self._transport.send_pack(get_changed_refs, generate_pack_contents)
267
256
 
268
 
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref,
269
 
                      progress=None):
 
257
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref, progress=None):
270
258
        fd, path = tempfile.mkstemp(suffix=".pack")
271
 
        self.fetch_pack(determine_wants, graph_walker,
272
 
            lambda x: os.write(fd, x), progress)
 
259
        self.fetch_pack(determine_wants, graph_walker, lambda x: os.write(fd, x), progress)
273
260
        os.close(fd)
274
261
        if os.path.getsize(path) == 0:
275
262
            return EmptyObjectStoreIterator()
276
263
        return TemporaryPackIterator(path[:-len(".pack")], resolve_ext_ref)
277
264
 
278
 
    def lookup_bzr_revision_id(self, bzr_revid):
 
265
    def lookup_git_revid(self, bzr_revid):
279
266
        # This won't work for any round-tripped bzr revisions, but it's a start..
280
267
        try:
281
268
            return mapping_registry.revision_id_bzr_to_foreign(bzr_revid)
290
277
        self.repository = branch.repository
291
278
 
292
279
    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
 
280
        return extract_tags(self.repository.get_refs(), self.branch.mapping)
297
281
 
298
282
    def set_tag(self, name, revid):
299
283
        # FIXME: Not supported yet, should do a push of a new ref
304
288
 
305
289
    def __init__(self, bzrdir, repository, name, lockfiles):
306
290
        self._ref = None
307
 
        super(RemoteGitBranch, self).__init__(bzrdir, repository, name,
 
291
        super(RemoteGitBranch, self).__init__(bzrdir, repository, name, 
308
292
                lockfiles)
309
293
 
310
294
    def revision_history(self):
313
297
    def last_revision(self):
314
298
        return self.mapping.revision_id_foreign_to_bzr(self.head)
315
299
 
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
300
    @property
325
301
    def head(self):
326
302
        if self._ref is not None:
327
303
            return self._ref
328
304
        heads = self.repository.get_refs()
329
305
        if not self.name in heads:
330
 
            raise NoSuchRef(self.name)
 
306
            raise NoSuchRef(name)
331
307
        self._ref = heads[self.name]
332
308
        return self._ref
333
309
 
334
310
    def _synchronize_history(self, destination, revision_id):
335
311
        """See Branch._synchronize_history()."""
336
312
        destination.generate_revision_history(self.last_revision())
337
 
 
 
313
 
338
314
    def get_push_location(self):
339
315
        return None
340
316