[Frugalware-darcs] git-hooks: don't try to read stin twice

VMiklos vmiklos at frugalware.org
Mon Jun 25 13:04:06 CEST 2007


Darcsweb-Url: http://darcs.frugalware.org/darcsweb/darcsweb.cgi?r=git-hooks;a=darcs_commitdiff;h=20070624114606-e2957-52a3e4a3434711179132925b3f7db20f26252a01.gz;

[don't try to read stin twice
VMiklos <vmiklos at frugalware.org>**20070624114606] {
hunk ./git-hooks.py 5
-class Hook:
-	def __init__(self, callback):
+def run_hook(callback, old, new):
+	sock = os.popen("git rev-list %s..%s" % (old, new))
+	hashes = sock.readlines()
+	sock.close()
+	hashes.reverse()
hunk ./git-hooks.py 11
-		# currently we don't care about !master branches
-		old = None
-		for i in sys.stdin.readlines():
-			(old, new, ref) = i.split(' ')
-			if ref == "refs/heads/master":
-				break
-		if not old:
-			return
+	for i in hashes:
+		callback(i.strip())
hunk ./git-hooks.py 14
-		sock = os.popen("git rev-list %s..%s" % (old, new))
-		hashes = sock.readlines()
-		sock.close()
-		hashes.reverse()
+def read_stdin():
+	# currently we don't care about !master branches
+	old = None
+	for i in sys.stdin.readlines():
+		(old, new, ref) = i.split(' ')
+		if ref == "refs/heads/master":
+			break
+	if not old:
+		sys.exit(1)
+	return old, new
hunk ./git-hooks.py 25
-		for i in hashes:
-			callback(i.strip())
hunk ./git-hooks.py 30
+	old, new = read_stdin()
hunk ./git-hooks.py 36
-		s = "%s.config" % i
-		config = __import__(s)
-		for j in s.split(".")[1:]:
-			config = getattr(config, j)
hunk ./git-hooks.py 37
-			hook = Hook(plugin.callback)
+			run_hook(plugin.callback, old, new)
}


More information about the Frugalware-darcs mailing list