mod_hg.py

changeset 121
ac07779f788d
parent 117
6c0609395889
child 123
aeb0d0788869
equal deleted inserted replaced
120:9880bb697149 121:ac07779f788d
34 'name': 'resolves', 34 'name': 'resolves',
35 'description': 'Manually cause a ticket to be resolved by a changeset', 35 'description': 'Manually cause a ticket to be resolved by a changeset',
36 'args': '<ticket> <changeset>', 36 'args': '<ticket> <changeset>',
37 'level': 'admin', # TODO 37 'level': 'admin', # TODO
38 }, 38 },
39
40 {
41 'name': 'compress',
42 'description': 'Compresses a head on the sandbox repositories.',
43 'args': '<changeset>',
44 'level': 'admin', # TODO
45 }
46 ] 39 ]
47 } 40 }
48 41
49 def plural (a): 42 def plural (a):
50 return '' if a == 1 else 's' 43 return '' if a == 1 else 's'
51 44
52 def cmd_checkhg (bot, **rest): 45 def cmd_checkhg (bot, **rest):
53 HgPoll.force_poll() 46 HgPoll.force_poll()
54 47
48 def is_dateversion (key):
49 try:
50 datetime.strptime (key, '%y%m%d-%H%M')
51 return True
52 except ValueError:
53 return False
54
55 def resolve_node (node):
56 reponame = None
57
58 if '/' in node:
59 reponame, node = node.split ('/')[0:2]
60
61 if reponame not in HgPoll.all_repo_names():
62 command_error ('''unknown repository %s''' % reponame)
63
64 # Possibly we're passed a date version instead. Try find the node for this.
65 if is_dateversion (node):
66 node = HgPoll.g_CommitsDb.find_commit_by_dateversion (node)
67
68 if node == None:
69 command_error ('''couldn't find changeset for date %s''' % node)
70 return
71
72 node = node[0:7]
73
74 noderepos = HgPoll.g_CommitsDb.get_commit_repos (node)
75
76 if reponame == None:
77 if not noderepos:
78 command_error ('''couldn't find changeset %s''' % node)
79
80 reponame = noderepos[0]
81
82 return (node, reponame)
83
55 def cmd_cset (bot, args, reply, **rest): 84 def cmd_cset (bot, args, reply, **rest):
56 repo = Repo ('zandronum-everything')
57 data = "" 85 data = ""
58 node = args['key'] 86 node, reponame = resolve_node (args['key'])
59 87 repourl = HgPoll.get_repo_info (reponame).get_value ('url')
60 # Possibly we're passed a date version instead. Try find the node for this. 88 repo = Repo (reponame)
61 try: 89 delim = '@@@@@@@@@@@@'
62 datetime.strptime (args['key'], '%y%m%d-%H%M') 90
63 HgPoll.make_commits_txt()
64 commits_txt = open ('commits.txt', 'r')
65
66 for line in commits_txt:
67 data = line.replace ('\n', '').split (' ')
68 if data[1] == args['key']:
69 node = data[0]
70 break
71 else:
72 command_error ('couldn\'t find changeset for date %s' % args['key'])
73 return
74 except ValueError:
75 pass
76
77 # zandronum-everything contains all zandronum changesets, so look for changesets in that.
78 try: 91 try:
79 data = repo.hg_command ("log", "-l1", "-r", node, "--template", 92 data = repo.hg_command ("log", "-l1", "-r", node, "--template",
80 "{node|short}@@@@@@@" + 93 delim.join (["{node|short}",
81 "{desc}@@@@@@@" + 94 "{desc}",
82 "{author}@@@@@@@" + 95 "{author}",
83 "{diffstat}@@@@@@@" + 96 "{diffstat}",
84 "{date|hgdate}@@@@@@@" + 97 "{date|hgdate}",
85 "{bookmarks}@@@@@@@" + 98 "{bookmarks}",
86 "{latesttagdistance}@@@@@@@" + 99 "{latesttagdistance}",
87 "{latesttag}") 100 "{latesttag}"])).split (delim)
88 except hgapi.HgException: 101 except hgapi.HgException:
89 command_error ('couldn\'t find changeset %s' % (node)) 102 command_error ('''couldn't find changeset %s in %s''' % (node, reponame))
90 return 103 return
91 104
92 try: 105 try:
93 data = data.split ('@@@@@@@')
94 node = data[0] 106 node = data[0]
95 message = data[1] 107 message = data[1]
96 author = data[2] 108 author = data[2]
97 diffstat = data[3] 109 diffstat = data[3]
98 date = datetime.utcfromtimestamp (int (data[4].split (' ')[0])) 110 date = datetime.utcfromtimestamp (int (data[4].split (' ')[0]))
105 if bookmarks: 117 if bookmarks:
106 bookmarks = HgPoll.prettify_bookmarks (bookmarks) 118 bookmarks = HgPoll.prettify_bookmarks (bookmarks)
107 119
108 # Find out the Zandronum version of this changeset 120 # Find out the Zandronum version of this changeset
109 repo.hg_command ('revert', '-r', node, 'src/version.h') 121 repo.hg_command ('revert', '-r', node, 'src/version.h')
110 zanversion = '<unknown zandronum version>' 122 zanversion = '<unknown version>'
111 123
112 with open ('zandronum-everything/src/version.h') as version_file: 124 try:
113 regexps = [ \ 125 with open (reponame + '/src/version.h') as version_file:
114 re.compile (r'#define\s+GAMEVER_STRING\s+"([^"]+)"'), \ 126 regexps = [ \
115 re.compile (r'#define\s+DOTVERSIONSTR_NOREV\s+"([^"]+)"'), \ 127 re.compile (r'#define\s+GAMEVER_STRING\s+"([^"]+)"'), \
116 re.compile (r'#define\s+DOTVERSIONSTR\s+"([^"]+)"')] 128 re.compile (r'#define\s+DOTVERSIONSTR_NOREV\s+"([^"]+)"'), \
117 129 re.compile (r'#define\s+DOTVERSIONSTR\s+"([^"]+)"')]
118 for line in version_file: 130
119 for rex in regexps: 131 for line in version_file:
120 match = rex.match (line) 132 for rex in regexps:
133 match = rex.match (line)
134 if match != None:
135 zanversion = match.group (1)
136 break
137
121 if match != None: 138 if match != None:
122 zanversion = match.group (1)
123 break 139 break
124 140 except IOError:
125 if match != None: 141 pass
126 break
127 142
128 143
129 repo.hg_command ('revert', '--all') 144 repo.hg_command ('revert', '--all')
130 145
131 # Remove the email address from the author if possible 146 # Remove the email address from the author if possible
170 reply ('changeset\0035 %s%s\003 (%s)\003: committed by\0032 %s\003 %s,\0032 %s' % \ 185 reply ('changeset\0035 %s%s\003 (%s)\003: committed by\0032 %s\003 %s,\0032 %s' % \
171 (node, bookmarks, versionstring, author, datestring, diffstat)) 186 (node, bookmarks, versionstring, author, datestring, diffstat))
172 187
173 for line in message.split ('\n'): 188 for line in message.split ('\n'):
174 reply (' ' + line) 189 reply (' ' + line)
190
191 reply ('url: %s/commits/%s' % (repourl, node))
175 except hgapi.HgException as e: 192 except hgapi.HgException as e:
176 result = HgPoll.decipher_hgapi_error (e) 193 result = HgPoll.decipher_hgapi_error (e)
177 194
178 if result[0]: 195 if result[0]:
179 command_error (result[1]) 196 command_error (result[1])

mercurial