src/logging.py
changeset 55 2661b21688d4
parent 54 e2ca551c2822
child 56 9ea9a30cd060
equal deleted inserted replaced
54:e2ca551c2822 55:2661b21688d4
    13 import os
    13 import os
    14 import time
    14 import time
    15 import changes
    15 import changes
    16         
    16         
    17 def hook(ui, repo, hooktype, node=None, source=None, **kwargs):
    17 def hook(ui, repo, hooktype, node=None, source=None, **kwargs):
    18     if hooktype != 'changegroup':
    18     if hooktype == 'changegroup':
       
    19         op = "push"
       
    20     elif hooktype == 'outgoing':
       
    21         op = "pull"
       
    22     else:
    19         raise mercurial.util.Abort(_('logging installed as wrong hook type,'
    23         raise mercurial.util.Abort(_('logging installed as wrong hook type,'
    20             ' must be changegroup but is %s') % hooktype)
    24             ' must be changegroup or outgoing but is %s') % hooktype)
    21     t = time.strftime("%Y-%m-%d_%H:%M:%S", time.gmtime())
    25     t = time.strftime("%Y-%m-%d_%H:%M:%S", time.gmtime())
    22     user = os.environ['REMOTE_USER']
    26     user = os.environ['REMOTE_USER']
    23     # FIXME: lock it
    27     # FIXME: lock it
    24     log = open(repo.join("push-log"), "a+")
    28     log = open(repo.join("push-log"), "a+")
    25     try:
    29     try:
    26         for ctx in changes.changes(repo, node):
    30         for ctx in changes.changes(repo, node):
    27             log.write("%s push key=%s changeset=%s\n" % 
    31             log.write("%s %s key=%s changeset=%s\n" % 
    28                 (t, user, mercurial.node.hex(ctx.node())))
    32                 (t, op, user, mercurial.node.hex(ctx.node())))
    29     finally:
    33     finally:
    30         log.close()
    34         log.close()
    31 
    35