src/mercurialserver/servelog.py
author Paul Crowley <paul@lshift.net>
Tue, 22 Dec 2009 15:45:35 +0000
branchdebian
changeset 251 7ec344c1917b
parent 242 03d8f07230b3
child 262 675474f5be32
permissions -rw-r--r--
Spanish translation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
242
03d8f07230b3 Tidy up file prologues; move credits to CREDITS
Paul Crowley <paul@lshift.net>
parents: 78
diff changeset
     1
"""
03d8f07230b3 Tidy up file prologues; move credits to CREDITS
Paul Crowley <paul@lshift.net>
parents: 78
diff changeset
     2
Hook to log changesets pushed and pulled
03d8f07230b3 Tidy up file prologues; move credits to CREDITS
Paul Crowley <paul@lshift.net>
parents: 78
diff changeset
     3
"""
54
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
     4
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
     5
from mercurial.i18n import _
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
     6
import mercurial.util
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
     7
import mercurial.node
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
import os
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
    10
import time
78
2a3407a14654 Replaced env vars with Python globals
Paul Crowley <paul@lshift.net>
parents: 67
diff changeset
    11
from mercurialserver import ruleset, changes
2a3407a14654 Replaced env vars with Python globals
Paul Crowley <paul@lshift.net>
parents: 67
diff changeset
    12
54
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
    13
def hook(ui, repo, hooktype, node=None, source=None, **kwargs):
55
2661b21688d4 Log pulls too
Paul Crowley <paul@lshift.net>
parents: 54
diff changeset
    14
    if hooktype == 'changegroup':
2661b21688d4 Log pulls too
Paul Crowley <paul@lshift.net>
parents: 54
diff changeset
    15
        op = "push"
2661b21688d4 Log pulls too
Paul Crowley <paul@lshift.net>
parents: 54
diff changeset
    16
    elif hooktype == 'outgoing':
2661b21688d4 Log pulls too
Paul Crowley <paul@lshift.net>
parents: 54
diff changeset
    17
        op = "pull"
2661b21688d4 Log pulls too
Paul Crowley <paul@lshift.net>
parents: 54
diff changeset
    18
    else:
59
f96de2d99f00 give logging module a more specific name
Paul Crowley <paul@lshift.net>
parents: 56
diff changeset
    19
        raise mercurial.util.Abort(_('servelog installed as wrong hook type,'
55
2661b21688d4 Log pulls too
Paul Crowley <paul@lshift.net>
parents: 54
diff changeset
    20
            ' must be changegroup or outgoing but is %s') % hooktype)
54
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
    21
    t = time.strftime("%Y-%m-%d_%H:%M:%S", time.gmtime())
78
2a3407a14654 Replaced env vars with Python globals
Paul Crowley <paul@lshift.net>
parents: 67
diff changeset
    22
    user = ruleset.rules.get('user')
54
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
    23
    # FIXME: lock it
56
9ea9a30cd060 Give log more appropriate name now it has pulls too
Paul Crowley <paul@lshift.net>
parents: 55
diff changeset
    24
    log = open(repo.join("serve-log"), "a+")
54
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):
55
2661b21688d4 Log pulls too
Paul Crowley <paul@lshift.net>
parents: 54
diff changeset
    27
            log.write("%s %s key=%s changeset=%s\n" % 
2661b21688d4 Log pulls too
Paul Crowley <paul@lshift.net>
parents: 54
diff changeset
    28
                (t, op, user, mercurial.node.hex(ctx.node())))
54
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()