Comment 16 for bug 1025886

Revision history for this message
Jelmer Vernooij (jelmer) wrote : Re: [Bug 1025886] Re: Client.fetch() doesn't support thin packs

On Thu, Dec 06, 2012 at 02:34:39PM -0000, dom wrote:
> It's been a while but I still have this problem.
> I looked into bzr-git/fetch.py and experimented a bit
> I tried to following which is based on the fetch_objects method of fetch.py
>
> from dulwich.repo import Repo
> from dulwich.client import HttpGitClient
> from dulwich.repo import Repo
>
> ref_changes = {}
> def determine_wants(heads):
> old_refs = dict([(k, (v, None)) for (k, v) in heads.iteritems()])
> new_refs = old_refs
> ref_changes.update(new_refs)
> return [sha1 for (sha1, bzr_revid) in new_refs.itervalues()]
>
> def process(text):
> print text
>
> repo = Repo('django-csp')
> url = 'https://github.com/fmarier/django-csp.git'
> client = HttpGitClient(url)
>
> localrepo = Repo('django-csp\\.git')
> graphwalker = localrepo.get_graph_walker()
> f, commit = localrepo.object_store.add_pack()
> refs = client.fetch_pack(url,
> determine_wants, graphwalker, f.write,
> process)
> commit()
>
> But I still get the same error(s).
>
> Can somebody tell my what's the right/a working way to fetch remote
> packs and commit them to the local repository?
This code still assumes full packs. You'll want to use
localrepo.object_store.add_thin_pack rather than
localrepo.object_store.add_pack.

A trivial way to do it would be to create a temporary file/StringIO,
have fetch_pack write into that and then pass the read method on that
object to add_thin_pack.

Cheers,

Jelmer