This repository has been archived by the owner on Jun 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpost-commmit.py
83 lines (66 loc) · 1.87 KB
/
post-commmit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/python
import sys
from svnlook import SvnLook
from sets import Set
import tempfile
import subprocess
import assets
import os
import syslog
CutOffLimit = 10
def AddToLog(newLog, changes, changeName):
if len(changes) > 0:
newLog = newLog + changeName + ": "
if len(changes) < CutOffLimit:
for file in changes:
newLog = newLog + file + " "
else:
newLog = newLog + len(changes) + " files"
newLog = newLog + "\n"
return newLog
def AddFiles(marker, changes, look):
for change in look.GetChanges(marker):
if not assets.IsAsset(change) or not assets.IsMetaData(change):
if assets.IsDirectory(change):
changes.add(change)
else:
changes.add(assets.GetFileName(change))
def FixCommitMessage(look):
newLog = look.GetLog()
if len(newLog) == 0 or newLog == "\n":
updates = Set()
adds = Set()
deletes = Set()
AddFiles(SvnLook.AddMarker, adds, look)
AddFiles(SvnLook.UpdateMarker, updates, look)
AddFiles(SvnLook.DeleteMarker, deletes, look)
moves = Set()
for file in adds:
if file in deletes:
adds.remove(file)
deletes.remove(file)
moves.add(file)
newLog = ""
newLog = AddToLog(newLog, updates, "Updated")
newLog = AddToLog(newLog, adds, "Added")
newLog = AddToLog(newLog, deletes, "Deleted")
newLog = AddToLog(newLog, moves, "Moved")
return newLog
def main(repo, revision):
svnlook = SvnLook(repo, revision = revision)
if not svnlook.CheckBypass():
log = FixCommitMessage(svnlook)
temp = tempfile.NamedTemporaryFile()
temp.write(log)
temp.flush()
args = ["svnadmin", "setlog", repo, "-r", revision, "--bypass-hooks", temp.name]
subprocess.call(args, universal_newlines = True)
temp.close()
return 0
if __name__ == "__main__":
sys.stdout = sys.stderr
if len(sys.argv) < 3:
syslog.syslog("args: " + str(sys.argv))
print "invalid args"
sys.exit(1)
sys.exit(main(sys.argv[1], sys.argv[2]))