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

# 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()