Add push logging
authorPaul Crowley <paul@lshift.net>
Fri, 20 Feb 2009 15:19:51 +0000
changeset 54 e2ca551c2822
parent 53 853444c5d393
child 55 2661b21688d4
Add push logging
install
src/init/conf/remote-hgrc
src/init/hgadmin-hgrc
src/logging.py
--- a/install	Fri Feb 20 15:19:33 2009 +0000
+++ b/install	Fri Feb 20 15:19:51 2009 +0000
@@ -9,6 +9,7 @@
 install -o root -g root -t /usr/local/lib/mercurial-server -m 644 \
     src/changes.py \
     src/access.py \
+    src/logging.py \
     src/ruleset.py
 install -o root -g root -d /usr/local/lib/mercurial-server/init
 install -o root -g root -t /usr/local/lib/mercurial-server/init \
--- a/src/init/conf/remote-hgrc	Fri Feb 20 15:19:33 2009 +0000
+++ b/src/init/conf/remote-hgrc	Fri Feb 20 15:19:51 2009 +0000
@@ -5,3 +5,5 @@
 
 [hooks]
 pretxnchangegroup.access = python:access.hook
+changegroup.aaaaa_logging = python:logging.hook
+
--- a/src/init/hgadmin-hgrc	Fri Feb 20 15:19:33 2009 +0000
+++ b/src/init/hgadmin-hgrc	Fri Feb 20 15:19:51 2009 +0000
@@ -2,7 +2,7 @@
 # ~/.ssh/authorized_keys
 
 [hooks]
-changegroup.aaaaa_update = hg update -C default > /dev/null
-changegroup.aaaab_purge = hg purge --all > /dev/null
+changegroup.aaaab_update = hg update -C default > /dev/null
+changegroup.aaaac_purge = hg purge --all > /dev/null
 changegroup.refreshauth = /etc/mercurial-server/refresh-auth
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/logging.py	Fri Feb 20 15:19:51 2009 +0000
@@ -0,0 +1,31 @@
+# Copyright 2008-2009 LShift Ltd
+#
+# Authors:
+# Paul Crowley <paul@lshift.net>
+#
+# This software may be used and distributed according to the terms
+# of the GNU General Public License, incorporated herein by reference.
+
+from mercurial.i18n import _
+import mercurial.util
+import mercurial.node
+
+import os
+import time
+import changes
+        
+def hook(ui, repo, hooktype, node=None, source=None, **kwargs):
+    if hooktype != 'changegroup':
+        raise mercurial.util.Abort(_('logging installed as wrong hook type,'
+            ' must be changegroup but is %s') % hooktype)
+    t = time.strftime("%Y-%m-%d_%H:%M:%S", time.gmtime())
+    user = os.environ['REMOTE_USER']
+    # FIXME: lock it
+    log = open(repo.join("push-log"), "a+")
+    try:
+        for ctx in changes.changes(repo, node):
+            log.write("%s push key=%s changeset=%s\n" % 
+                (t, user, mercurial.node.hex(ctx.node())))
+    finally:
+        log.close()
+