← Back to team overview

dulwich-users team mailing list archive

Re: dulwich porcelain

 

Am Thursday, den 13.09.2012, 22:12 -0700 schrieb Mark Mikofski:
> >>  Hi Jelmer,
> 
> >>  So what is supposed to be used with send_pack? Should I modify or write
> >>  my own determine_wants_all for send_pack that returns the dictionary as
> >>  requested?
> > Yes, the easiest thing to do is to write your own. This should be fairly
> > simple if you're just updating a single branch or copying over the refs
> > of another repository.
> > 
> >>  Is new_refs *all* of the refs in objects? or is it only the ones that are 
> > not
> >>  _old_?
> > It's just the changes to the refs.
> > 
> >>  For example, I have 4 ref:shas in objects. One commit is already on the
> >>  remote, because it was there when I cloned it. So I assume that's 
> > old_ref.
> >>  Now is new_refs the 3 remaining refs in objects, not including the one
> >>  already on the remote? I really need to learn a lot more about git 
> > plumbing!
> > It's just the changes, though including refs that are already set (to
> > the same SHA1) shouldn't be harmful.
> > 
> > Cheers,
> > 
> > Jelmer
> > 
> 
> 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".

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.

>         return dict(new.items() + dfrnt.items())
>     refs = client.send_pack(path,
>                             determine_wants_new,
>                             objsto.generate_pack_contents,
>                             sys.stdout.write)

Cheers,

Jelmer

Attachment: signature.asc
Description: This is a digitally signed message part


Follow ups

References