# HG changeset patch # User Josef "Jeff" Sipek # Date 1161473835 14400 # Node ID 7d0b4aa723223244d4e516f6916c95eefd567c15 # Parent e07147ab4de41cfd4bd0d04a0cc4419934299b5f convert a want into a list of objects for that want (trees & blobs) diff -r e07147ab4de4 -r 7d0b4aa72322 hgext/gitserve.py --- a/hgext/gitserve.py Sat Oct 21 18:58:32 2006 -0400 +++ b/hgext/gitserve.py Sat Oct 21 19:37:15 2006 -0400 @@ -73,14 +73,20 @@ caps = "multi_ack thin-pack" name = "HEAD" - hash = partial_hash + + f = open(".git/refs/heads/master","r") + hash = f.read().strip() + f.close() safe_write(sock, "%s %s\0%s\n" % (hash, name, caps)) def send_all_refs(sock): "send info for each ref" - hash = partial_hash + f = open(".git/refs/heads/master","r") + hash = f.read().strip() + f.close() + name = "master" safe_write(sock, "%s refs/heads/%s\n" % (hash, name)) @@ -161,8 +167,52 @@ def create_pack(sock, want, have, flags): "create the pack, and send it to the client" - # test pack - raw_write(sock, partial) + def get_obj(w): + f = open(".git/objects/%s/%s" % (w[:2], w[2:]), "r") + buf = f.read() + f.close() + + buf = zlib.decompress(buf) + + print repr(buf) + return buf.split("\0",1) + + def __get_tree(w): + t, buf = get_obj(w) + if t.startswith("blob"): + return [w,] + + t = [w] + while buf: + pre, post = buf.split("\0",1) + hash = post[:20] + buf = post[20:] + + t.extend(__get_tree(node.hex(hash))) + + return t + + def get_tree(w): + t, buf = get_obj(w) + for p in buf.split("\n"): + if p.startswith("tree "): + return __get_tree(p.split(" ")[1].strip()) + raise ValueError + + # find path to all the wants + # for each commit in the path + # get all tree & blob objects + l = list(want) + for w in want: + print "want %s:" % (w,) + l.extend(get_tree(w)) + + print l + gitpack(ui, repo, ",".join(l)) + + f = open("git.pack") + raw_write(sock, f.read()) + f.close() # first let's wait for a greeting buf = safe_read(sock) @@ -447,7 +497,7 @@ __objs = [] if objs: - for h in revs.split(","): + for h in objs.split(","): __objs.append(pack(h)) else: print "Need a list of revs"