changeset 3465:e07147ab4de4

read rev list from the argument
author Josef "Jeff" Sipek <jeffpc@josefsipek.net>
date Sat, 21 Oct 2006 18:58:32 -0400
parents ec4d38e2777d
children 7d0b4aa72322
files hgext/gitserve.py
diffstat 1 files changed, 37 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/gitserve.py	Sat Oct 21 18:48:23 2006 -0400
+++ b/hgext/gitserve.py	Sat Oct 21 18:58:32 2006 -0400
@@ -350,10 +350,18 @@
     if usemap:
         save_map()
 
+OBJ_NONE = 0
+OBJ_COMMIT = 1
+OBJ_TREE = 2
+OBJ_BLOB = 3
+OBJ_TAG = 4
+# 5/6 for future expansion 
+OBJ_DELTA = 7
+
 class pack:
-    def __init__(self, hash, t):
+    def __init__(self, hash):
         self.hash = hash
-        self.type = t
+        self.__type = None
         self.offset = None
         self.reall = None
 	self.clen = None
@@ -379,6 +387,15 @@
 	header, decbuf = decbuf.split("\0", 1)
 	self.strtype, self.reall = header.split(" ")
 
+	if self.strtype == "blob":
+            self.__type = OBJ_BLOB
+	elif self.strtype == "tree":
+            self.__type = OBJ_TREE
+	elif self.strtype == "commit":
+            self.__type = OBJ_COMMIT
+        else:
+            raise ValueError
+
 	buf = zlib.compress(decbuf)
 
 	self.reall = int(self.reall)
@@ -394,15 +411,13 @@
 			self.clen, self.offset)
         return self.reall
 
-OBJ_NONE = 0
-OBJ_COMMIT = 1
-OBJ_TREE = 2
-OBJ_BLOB = 3
-OBJ_TAG = 4
-# 5/6 for future expansion 
-OBJ_DELTA = 7
+    def type(self):
+        if self.__type is None:
+            self.dump()
 
-def gitpack(ui, repo):
+        return self.__type
+
+def gitpack(ui, repo, objs=None):
     "Create a git pack file for a given range of revisions"
 
     def hexify(i):
@@ -426,16 +441,20 @@
 	if l or len(buf) == 1:
             buf += chr(l & 0x7f)
 
-        print repr(buf)
         return buf
 
     ##
 
-    objs = [
-	    pack("66f2467906e280f956e45318ab7c153f0e32bc3e", OBJ_COMMIT),
-	    pack("56d5e5ba85c84cb8deb38f40c294405c5650e079", OBJ_TREE),
-	    pack("8baef1b4abc478178b004d62031cf7fe6db6f903", OBJ_BLOB),
-	   ]
+    __objs = []
+    if objs:
+        for h in revs.split(","):
+            __objs.append(pack(h))
+    else:
+	    print "Need a list of revs"
+	    return
+
+    objs = __objs
+    __objs = None
     print objs
 
     hash = sha.sha()
@@ -451,7 +470,7 @@
 
         rawobj = obj.dump()
 
-        off += hashed_write(hash, packf, typelen(obj.type, obj.reallen()))
+        off += hashed_write(hash, packf, typelen(obj.type(), obj.reallen()))
         off += hashed_write(hash, packf, rawobj)
 
     packhash = hash.digest()
@@ -491,7 +510,7 @@
     'hg gitserve'),
     "gitpack":
     (gitpack,
-     [],
+     [('o', 'objs', '', 'comma separated list of revisions to create a pack for')],
     'hg gitpack'),
     "gitobject":
     (gitobject,