dulwich-users team mailing list archive
-
dulwich-users team
-
Mailing list archive
-
Message #00742
Re: dulwich porcelain
>> This is the new push code:
>
> This seems quite reasonable:
>
>>
>> from dulwich.repo import Repo
>> from dulwich.client import get_transport_and_path
>> from getopt import getopt
>> import sys
>>
>>
>> def push(args):
>> opts, args = getopt(args, "", [])
>> opts = dict(opts)
>> client, path = get_transport_and_path(args.pop(0))
>> r = Repo(".")
>> objsto = r.object_store
>> refs = r.get_refs()
>> def determine_wants_new(old):
>> same = list(set(refs).intersection(old))
>> new = dict([(k,refs[k]) for k in same if refs[k] != old[k]])
>> dfky = list(set(refs) - set(new))
>> dfrnt = dict([(k,refs[k]) for k in dfky if k != 'HEAD'])
> This is probably more appropriate to name "update_refs" rather than
> "determine_wants_new".
OK, I will rename it to update_refs
>
> This function seems a lot more complicated than it needs to be. Note
> that it's not necessary to find the refs that differ - it's fine to
> update a ref even if it already exists.
>
OK, then the update_refs function can just be
`lambda old: r.get_refs()`
Does that seem right? Why does send_pack pass old_refs to
update_refs (previously called determine_wants) if it isn't needed?
Or what is old_refs needed for?
>> return dict(new.items() + dfrnt.items())
>> refs = client.send_pack(path,
>> determine_wants_new,
>> objsto.generate_pack_contents,
>> sys.stdout.write)
>
> Cheers,
>
> Jelmer
>
Thanks!
Follow ups
References