-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrewrite.py
85 lines (70 loc) · 2.4 KB
/
rewrite.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
84
85
# File comes from https://lists.osgeo.org/pipermail/gdal-dev/2018-March/048246.html
import sys
msg = sys.stdin.read()
# Don't touch messages that reference other databases
if msg.find('MITAB bug ') >= 0 or msg.find('Safe bug ') >= 0 or msg.find('bugzilla') >= 0 or msg.find('Bugzilla') >= 0:
sys.stdout.write(msg)
sys.exit(0)
oldpos = 0
old_msg = msg
while True:
# We already have reference to github pull requests written like
# 'github #1234', so skip them
newpos = msg.find('github #', oldpos)
if newpos >= 0:
oldpos = newpos + len('github #')
continue
# Exception...
newpos = msg.find('patch #1 ', oldpos)
if newpos >= 0:
oldpos = newpos + len('patch #1 ')
continue
# Exception...
newpos = msg.find('bug 1 ', oldpos)
if newpos >= 0:
oldpos = newpos + len('bug 1 ')
continue
# Fix 'bug 1234'
newpos = msg.find('bug ', oldpos)
if newpos >= 0:
if newpos == len(msg) - 4:
break
if not(msg[newpos+4] >= '1' and msg[newpos+4] <= '9'):
oldpos = newpos + 4
continue
msg = msg[0:newpos] + 'https://svn.zoo-project.org/trac/ticket/' + msg[newpos+4:]
oldpos = newpos
continue
# Fix 'ticket 1234'
newpos = msg.find('ticket ', oldpos)
if newpos >= 0:
if newpos == len(msg) - 7:
break
if not(msg[newpos+7] >= '1' and msg[newpos+7] <= '9'):
oldpos = newpos + 7
continue
msg = msg[0:newpos] + 'https://svn.zoo-project.org/trac/ticket/' + msg[newpos+7:]
oldpos = newpos
continue
# Fix '#1234'
newpos = msg.find('#', oldpos)
if newpos >= 0:
if newpos == len(msg) - 1:
break
if not(msg[newpos+1] >= '1' and msg[newpos+1] <= '9'):
oldpos = newpos + 1
continue
# Skip stacktraces like '#1 0xdeadbeef'
space_pos = msg.find(' ', newpos)
if space_pos > 0 and space_pos + 2 < len(msg) and msg[space_pos + 1] == '0' and msg[space_pos + 2] == 'x':
oldpos = newpos + 1
continue
msg = msg[0:newpos] + 'https://svn.zoo-project.org/trac/ticket/' + msg[newpos+1:]
oldpos = newpos
continue
break
if msg != old_msg:
f = open('/tmp/log.txt', 'a')
f.write('Old message was:\n' + old_msg + 'New message is:\n' + msg + '\n')
f.close()
sys.stdout.write(msg)