author | Paul Crowley <paul@lshift.net> |
Sat, 19 Dec 2009 10:47:13 +0000 | |
changeset 242 | 03d8f07230b3 |
parent 78 | 2a3407a14654 |
child 262 | 675474f5be32 |
permissions | -rw-r--r-- |
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 | 4 |
|
5 |
from mercurial.i18n import _ |
|
6 |
import mercurial.util |
|
7 |
import mercurial.node |
|
8 |
||
9 |
import os |
|
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 | 13 |
def hook(ui, repo, hooktype, node=None, source=None, **kwargs): |
55 | 14 |
if hooktype == 'changegroup': |
15 |
op = "push" |
|
16 |
elif hooktype == 'outgoing': |
|
17 |
op = "pull" |
|
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 | 20 |
' must be changegroup or outgoing but is %s') % hooktype) |
54 | 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 | 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 | 25 |
try: |
26 |
for ctx in changes.changes(repo, node): |
|
55 | 27 |
log.write("%s %s key=%s changeset=%s\n" % |
28 |
(t, op, user, mercurial.node.hex(ctx.node()))) |
|
54 | 29 |
finally: |
30 |
log.close() |