mod_hg.py

changeset 151
e24793fae424
parent 147
4a72fb181a43
child 152
1b734faab67a
equal deleted inserted replaced
150:2fd1f6ee05f5 151:e24793fae424
111 111
112 repo = noderepos[0] 112 repo = noderepos[0]
113 113
114 return (node, repo) 114 return (node, repo)
115 115
116 def get_version_string (reponame, node): 116 def get_version_string (repo, node):
117 try: 117 try:
118 data = subprocess.check_output (['hg', '--cwd', reponame, 'cat', 118 data = repo.hg ('cat', '--rev', node, 'src/version.h')
119 '--rev', node, 'src/version.h'])
120 119
121 regexps = [ \ 120 regexps = [ \
122 re.compile (r'#define\s+GAMEVER_STRING\s+"([^"]+)"'), \ 121 re.compile (r'#define\s+GAMEVER_STRING\s+"([^"]+)"'), \
123 re.compile (r'#define\s+DOTVERSIONSTR_NOREV\s+"([^"]+)"'), \ 122 re.compile (r'#define\s+DOTVERSIONSTR_NOREV\s+"([^"]+)"'), \
124 re.compile (r'#define\s+DOTVERSIONSTR\s+"([^"]+)"')] 123 re.compile (r'#define\s+DOTVERSIONSTR\s+"([^"]+)"')]
125 except subprocess.CalledProcessError: 124 except subprocess.CalledProcessError:
126 try: 125 try:
127 data = subprocess.check_output (['hg', '--cwd', reponame, 'cat', 126 data = repo.hg ('cat', '--rev', node, 'src/core/versiondefs.h')
128 '--rev', node, 'src/core/versiondefs.h'])
129 regexps = [re.compile (r'#define\s+VERSION_STRING\s+"([^"]+)"')] 127 regexps = [re.compile (r'#define\s+VERSION_STRING\s+"([^"]+)"')]
130 except subprocess.CalledProcessError: 128 except subprocess.CalledProcessError:
131 return '' 129 return ''
132 130
133 for line in data.splitlines(): 131 for line in data.splitlines():
136 134
137 if match: 135 if match:
138 return match.group (1) 136 return match.group (1)
139 137
140 def cmd_cset (bot, args, reply, **rest): 138 def cmd_cset (bot, args, reply, **rest):
141 data = ""
142 node, repo = resolve_node (args['key']) 139 node, repo = resolve_node (args['key'])
143 140
144 try: 141 try:
145 data = repo.get_commit_data (rev=node, 142 commit = repo.get_commit_data (rev=node,
146 node='node|short', 143 node='node|short',
147 message='desc', 144 message='desc',
148 author='author', 145 author='author',
149 diffstat='diffstat', 146 diffstat='diffstat',
150 time='date|hgdate', 147 time='date|hgdate',
151 bookmarks='bookmarks', 148 bookmarks='bookmarks',
152 latesttagdistance='latesttagdistance', 149 latesttagdistance='latesttagdistance',
153 latesttag='latesttag', 150 latesttag='latesttag',
154 email='author|email') 151 email='author|email')
155 except Subprocess.CalledProcessError: 152 except Subprocess.CalledProcessError:
156 command_error ('''couldn't find changeset %s in %s''' % (node, reponame)) 153 command_error ('''couldn't find changeset %s in %s''' % (node, repo.name))
157 154
158 del node 155 del node
159 commit['date'] = datetime.utcfromtimestamp (int (commit['time'].split (' ')[0])) 156 commit['date'] = datetime.utcfromtimestamp (int (commit['time'].split (' ')[0]))
160 commit['latesttagdistance'] = int (commit['latesttagdistance']) 157 commit['latesttagdistance'] = int (commit['latesttagdistance'])
161 commit['bookmarks'] = hgpoll.prettify_bookmarks (commit['bookmarks']) 158 commit['bookmarks'] = hgpoll.prettify_bookmarks (commit['bookmarks'])
162 159
163 # Find out the version string of this changeset 160 # Find out the version string of this changeset
164 versionstring = get_version_string (reponame, commit['node']) 161 versionstring = get_version_string (repo, commit['node'])
165 username = Config.find_developer_by_email (email) 162 username = Config.find_developer_by_email (commit['email'])
166 163
167 if username: 164 if username:
168 commit['author'] = username 165 commit['author'] = username
169 166
170 # Try prettify the diffstat 167 # Try prettify the diffstat
172 169
173 if match: 170 if match:
174 commit['diffstat'] = "%s\003:\0033 +%s\003/\0034-%s\003" % \ 171 commit['diffstat'] = "%s\003:\0033 +%s\003/\0034-%s\003" % \
175 (match.group (1), match.group (2), match.group (3)) 172 (match.group (1), match.group (2), match.group (3))
176 173
177 delta = datetime.utcnow() - date 174 delta = datetime.utcnow() - commit['date']
178 if delta.days < 4: 175 if delta.days < 4:
179 if delta.days == 0: 176 if delta.days == 0:
180 if delta.seconds < 60: 177 if delta.seconds < 60:
181 datestring = 'just now' 178 datestring = 'just now'
182 elif delta.seconds < 3600: 179 elif delta.seconds < 3600:
194 versionblurb = "" 191 versionblurb = ""
195 192
196 if versionstring: 193 if versionstring:
197 versionblurb = versionstring + ' ' 194 versionblurb = versionstring + ' '
198 195
199 versionblurb += '%s, %d hops from %s' % (date.strftime ('%y%m%d-%H%M'), 196 versionblurb += '%s, %d hops from %s' % (commit['date'].strftime ('%y%m%d-%H%M'),
200 latesttagdistance, latesttag) 197 commit['latesttagdistance'], commit['latesttag'])
201 else: 198 else:
202 versionblurb = latesttag 199 versionblurb = latesttag
203 200
204 reply ('changeset\0035 %s%s\003 (%s)\003: committed by\0032 %s\003 %s,\0032 %s' % \ 201 reply ('changeset\0035 %s%s\003 (%s)\003: committed by\0032 %s\003 %s,\0032 %s' % \
205 (commit['node'], commit['bookmarks'], versionblurb, commit['author'], datestring, 202 (commit['node'], commit['bookmarks'], versionblurb, commit['author'], datestring,
206 commit['diffstat'])) 203 commit['diffstat']))
207 204
208 for line in message.split ('\n'): 205 for line in commit['message'].split ('\n'):
209 reply (' ' + line) 206 reply (' ' + line)
210 207
211 reply ('url: %s/commits/%s' % (repo.url, commit['node'])) 208 reply ('url: %s/commits/%s' % (repo.url, commit['node']))
212 209
213 def cmd_hg (bot, args, reply, **rest): 210 def cmd_hg (bot, args, reply, **rest):

mercurial