src/mercurialserver/servelog.py
changeset 67 fd16d9a1234b
parent 62 f1e319d3672a
child 78 2a3407a14654
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/mercurialserver/servelog.py	Fri Mar 06 09:15:00 2009 +0000
@@ -0,0 +1,34 @@
+# 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
+from mercurialserver import changes
+        
+def hook(ui, repo, hooktype, node=None, source=None, **kwargs):
+    if hooktype == 'changegroup':
+        op = "push"
+    elif hooktype == 'outgoing':
+        op = "pull"
+    else:
+        raise mercurial.util.Abort(_('servelog installed as wrong hook type,'
+            ' must be changegroup or outgoing 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("serve-log"), "a+")
+    try:
+        for ctx in changes.changes(repo, node):
+            log.write("%s %s key=%s changeset=%s\n" % 
+                (t, op, user, mercurial.node.hex(ctx.node())))
+    finally:
+        log.close()