src/logging.py
author Paul Crowley <paul@lshift.net>
Fri, 20 Feb 2009 15:19:51 +0000
changeset 54 e2ca551c2822
child 55 2661b21688d4
permissions -rw-r--r--
Add push logging
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
54
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
     1
# Copyright 2008-2009 LShift Ltd
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
     2
#
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
     3
# Authors:
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
     4
# Paul Crowley <paul@lshift.net>
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
     5
#
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
     6
# This software may be used and distributed according to the terms
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
     7
# of the GNU General Public License, incorporated herein by reference.
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
     8
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
     9
from mercurial.i18n import _
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
    10
import mercurial.util
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
    11
import mercurial.node
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
    12
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
    13
import os
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
    14
import time
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
    15
import changes
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
    16
        
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
    17
def hook(ui, repo, hooktype, node=None, source=None, **kwargs):
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
    18
    if hooktype != 'changegroup':
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
    19
        raise mercurial.util.Abort(_('logging installed as wrong hook type,'
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
    20
            ' must be changegroup but is %s') % hooktype)
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
    21
    t = time.strftime("%Y-%m-%d_%H:%M:%S", time.gmtime())
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
    22
    user = os.environ['REMOTE_USER']
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
    23
    # FIXME: lock it
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
    24
    log = open(repo.join("push-log"), "a+")
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
    25
    try:
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
    26
        for ctx in changes.changes(repo, node):
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
    27
            log.write("%s push key=%s changeset=%s\n" % 
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
    28
                (t, user, mercurial.node.hex(ctx.node())))
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
    29
    finally:
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
    30
        log.close()
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
    31