# HG changeset patch # User Josef "Jeff" Sipek # Date 1161465504 14400 # Node ID 371833e0fc5ce2db6a11fc6570a04a443b73924f # Parent 1a6856093e4c8ccdc569f32efc5b92ce92f90c42 fixed indentation & pack index file writing diff -r 1a6856093e4c -r 371833e0fc5c .hgignore --- a/.hgignore Sat Oct 21 16:20:08 2006 -0400 +++ b/.hgignore Sat Oct 21 17:18:24 2006 -0400 @@ -22,6 +22,7 @@ patches mercurial/__version__.py .DS_Store +tmp syntax: regexp ^\.pc/ diff -r 1a6856093e4c -r 371833e0fc5c hgext/gitserve.py --- a/hgext/gitserve.py Sat Oct 21 16:20:08 2006 -0400 +++ b/hgext/gitserve.py Sat Oct 21 17:18:24 2006 -0400 @@ -284,19 +284,20 @@ f.close() def buildtrees(dirs): - tree = "" - for name in dirs.keys(): - if dirs[name].__class__ == dict: - # a directory - hash = node.bin(buildtrees(dirs[name])) - mode = "40000" - else: - hash = dirs[name] - mode = "100644" + tree = "" + for name in dirs.keys(): + if dirs[name].__class__ == dict: + # a directory + hash = node.bin(buildtrees(dirs[name])) + mode = "40000" + else: + # a file + hash = dirs[name] + mode = "100644" - tree+="%s %s\0%s"%(mode,name,hash) + tree+="%s %s\0%s"%(mode,name,hash) - return make_tree_object(tree) + return make_tree_object(tree) ## @@ -308,7 +309,7 @@ else: print "looking up \"%s\"" % (node.hex(rev),) r = repo.lookup(rev) - print "got: " + node.hex(r) + print "got: " + node.hex(r) pars = repo.changelog.parents(r) if not h2g.has_key(pars[0]) and pars[0] != node.nullid: @@ -325,12 +326,12 @@ githash = make_file_object(repo, name, mmap[name]) pn = name.split("/") - d = dirs - for p in pn[:-1]: - if not d.has_key(p): - d[p] = {} - d = d[p] - d[pn[-1]] = node.bin(githash) + d = dirs + for p in pn[:-1]: + if not d.has_key(p): + d[p] = {} + d = d[p] + d[pn[-1]] = node.bin(githash) gittree = buildtrees(dirs) @@ -349,6 +350,23 @@ if usemap: save_map() +class pack: + def __init__(self, hash): + self.hash = hash + self.offset = None + + def __str__(self): + return self.hash + + def __repr__(self): + return "" % (self.hash,) + + def __cmp__(self, rhs): + return cmp(self.hash, rhs.hash) + + def bin(self): + return node.bin(self.hash) + def gitpack(ui, repo): "Create a git pack file for a given range of revisions" @@ -357,18 +375,58 @@ return chr(i) return _h(i >> 24) + _h((i >> 16) & 0xff) + _h((i >> 8) & 0xff) + _h(i & 0xff) - pack = open("git.pack", "w") + def hashed_write(h, f, d): + h.update(d) + f.write(d) + return len(d) + + ## - pack.write("PACK") # magic - pack.write(hexify(2)) # version - pack.write(hexity(nr_objs)) # number of objects + objs = [pack("66f2467906e280f956e45318ab7c153f0e32bc3e"), + pack("56d5e5ba85c84cb8deb38f40c294405c5650e079"), + pack("8baef1b4abc478178b004d62031cf7fe6db6f903")] + objs.sort() + print objs + + hash = sha.sha() + packf = open("git.pack", "w") + + hashed_write(hash, packf, "PACK") # magic + hashed_write(hash, packf, hexify(2)) # version + hashed_write(hash, packf, hexify(len(objs)))# number of objects + + off = 12 # header is 12 bytes long for obj in objs: - if obj.deltify: - pass - else: - pass + obj.offset = off + off += hashed_write(hash, packf, str(obj)) + + packhash = hash.digest() + packf.write(packhash) + packf.close() + + # + # index file + # + hash = sha.sha() + idx = open("git.idx", "w") - pack.close() + # header + count = 0 + oidx = 0 + for i in range(0,256): + if oidx < len(objs) and str(objs[oidx]).startswith("%02x" % (i,)): + oidx += 1 + count += 1 + hashed_write(hash, idx, hexify(count)) + + # per object entries + for obj in objs: + hashed_write(hash, idx, hexify(obj.offset)) + hashed_write(hash, idx, obj.bin()) + + hashed_write(hash, idx, packhash) + idx.write(hash.digest()) + idx.close() cmdtable = { "gitserve":