/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: 2018-03-10 17:49:06 UTC
  • mto: (0.200.1842 work)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180310174906-vdfej8g2cds7r2aa
Allow using local git executable by accessing git:///some/path.

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
from .dir import (
51
51
    GitControlDirFormat,
52
52
    GitDir,
 
53
    BareLocalGitControlDirFormat,
53
54
    )
54
55
from .errors import (
55
56
    GitSmartRemoteNotSupported,
150
151
    def has(self, relpath):
151
152
        return False
152
153
 
153
 
    def _get_client(self, thin_packs):
 
154
    def _get_client(self):
154
155
        raise NotImplementedError(self._get_client)
155
156
 
156
157
    def _get_path(self):
176
177
 
177
178
    _scheme = 'git'
178
179
 
179
 
    def _get_client(self, thin_packs):
 
180
    def _get_client(self):
180
181
        if self._client is not None:
181
182
            ret = self._client
182
183
            self._client = None
183
184
            return ret
 
185
        if self._host == '':
 
186
            return dulwich.client.LocalGitClient()
184
187
        return dulwich.client.TCPGitClient(self._host, self._port,
185
 
            thin_packs=thin_packs, report_activity=self._report_activity)
 
188
            report_activity=self._report_activity)
186
189
 
187
190
 
188
191
class SSHSocketWrapper(object):
229
232
            return path[3:]
230
233
        return path
231
234
 
232
 
    def _get_client(self, thin_packs):
 
235
    def _get_client(self):
233
236
        if self._client is not None:
234
237
            ret = self._client
235
238
            self._client = None
236
239
            return ret
237
240
        location_config = config.LocationConfig(self.base)
238
241
        client = dulwich.client.SSHGitClient(self._host, self._port, self._username,
239
 
            thin_packs=thin_packs, report_activity=self._report_activity)
 
242
            report_activity=self._report_activity)
240
243
        # Set up alternate pack program paths
241
244
        upload_pack = location_config.get_user_option('git_upload_pack')
242
245
        if upload_pack:
263
266
 
264
267
class RemoteGitDir(GitDir):
265
268
 
266
 
    def __init__(self, transport, format, get_client, client_path):
 
269
    def __init__(self, transport, format, client, client_path):
267
270
        self._format = format
268
271
        self.root_transport = transport
269
272
        self.transport = transport
270
273
        self._mode_check_done = None
271
 
        self._get_client = get_client
 
274
        self._client = client
272
275
        self._client_path = client_path
273
276
        self.base = self.root_transport.base
274
277
        self._refs = None
283
286
                trace.info("git: %s" % text)
284
287
        def wrap_determine_wants(refs_dict):
285
288
            return determine_wants(remote_refs_dict_to_container(refs_dict))
286
 
        client = self._get_client(thin_packs=True)
287
289
        try:
288
 
            refs_dict = client.fetch_pack(self._client_path, wrap_determine_wants,
 
290
            refs_dict = self._client.fetch_pack(self._client_path, wrap_determine_wants,
289
291
                graph_walker, pack_data, progress)
290
292
            if refs_dict is None:
291
293
                refs_dict = {}
295
297
            raise parse_git_error(self.transport.external_url(), e)
296
298
 
297
299
    def send_pack(self, get_changed_refs, generate_pack_contents):
298
 
        client = self._get_client(thin_packs=True)
299
300
        try:
300
 
            return client.send_pack(self._client_path, get_changed_refs,
 
301
            return self._client.send_pack(self._client_path, get_changed_refs,
301
302
                generate_pack_contents)
302
303
        except GitProtocolError, e:
303
304
            raise parse_git_error(self.transport.external_url(), e)
433
434
        url = transport.base
434
435
        if url.startswith('readonly+'):
435
436
            url = url[len('readonly+'):]
 
437
        scheme = urlparse.urlsplit(transport.external_url())[0]
436
438
        if isinstance(transport, GitSmartTransport):
437
 
            get_client = transport._get_client
 
439
            client = transport._get_client()
438
440
            client_path = transport._get_path()
439
 
        elif urlparse.urlsplit(transport.external_url())[0] in ("http", "https"):
440
 
            def get_client(thin_packs):
441
 
                return BzrGitHttpClient(transport, thin_packs=thin_packs)
 
441
        elif scheme in ("http", "https"):
 
442
            client = BzrGitHttpClient(transport)
442
443
            client_path, _ = urlutils.split_segment_parameters(transport._path)
 
444
        elif scheme == 'file':
 
445
            client = dulwich.client.LocalGitClient()
 
446
            client_path = transport.local_abspath('.')
443
447
        else:
444
448
            raise NotBranchError(transport.base)
445
 
        return RemoteGitDir(transport, self, get_client, client_path)
 
449
        if not _found:
 
450
            pass # TODO(jelmer): Actually probe for something
 
451
        return RemoteGitDir(transport, self, client, client_path)
446
452
 
447
453
    def get_format_description(self):
448
454
        return "Remote Git Repository"