comparison hgext/convert/convcmd.py @ 7962:62154415821f

convert: fix authormap handling of lines without '=' Unpacking the result from str.split raises ValueError, not IndexError, if the line does not contain a '='.
author Marti Raudsepp <marti@juffo.org>
date Sat, 04 Apr 2009 15:41:32 +0200
parents de377b1a9a84
children 43b70a964e0d
comparison
equal deleted inserted replaced
7961:52e442fe43f4 7962:62154415821f
195 ofile.close() 195 ofile.close()
196 196
197 def readauthormap(self, authorfile): 197 def readauthormap(self, authorfile):
198 afile = open(authorfile, 'r') 198 afile = open(authorfile, 'r')
199 for line in afile: 199 for line in afile:
200
200 if line.strip() == '': 201 if line.strip() == '':
201 continue 202 continue
203
202 try: 204 try:
203 srcauthor, dstauthor = line.split('=', 1) 205 srcauthor, dstauthor = line.split('=', 1)
204 srcauthor = srcauthor.strip() 206 except ValueError:
205 dstauthor = dstauthor.strip() 207 msg = _('Ignoring bad line in author map file %s: %s\n')
206 if srcauthor in self.authors and dstauthor != self.authors[srcauthor]: 208 self.ui.warn(msg % (authorfile, line.rstrip()))
207 self.ui.status( 209 continue
208 _('Overriding mapping for author %s, was %s, will be %s\n') 210
209 % (srcauthor, self.authors[srcauthor], dstauthor)) 211 srcauthor = srcauthor.strip()
210 else: 212 dstauthor = dstauthor.strip()
211 self.ui.debug(_('mapping author %s to %s\n') 213 if self.authors.get(srcauthor) in (None, dstauthor):
212 % (srcauthor, dstauthor)) 214 msg = _('mapping author %s to %s\n')
213 self.authors[srcauthor] = dstauthor 215 self.ui.debug(msg % (srcauthor, dstauthor))
214 except IndexError: 216 self.authors[srcauthor] = dstauthor
215 self.ui.warn( 217 continue
216 _('Ignoring bad line in author map file %s: %s\n') 218
217 % (authorfile, line.rstrip())) 219 m = _('overriding mapping for author %s, was %s, will be %s\n')
220 self.ui.status(m % (srcauthor, self.authors[srcauthor], dstauthor))
221
218 afile.close() 222 afile.close()
219 223
220 def cachecommit(self, rev): 224 def cachecommit(self, rev):
221 commit = self.source.getcommit(rev) 225 commit = self.source.getcommit(rev)
222 commit.author = self.authors.get(commit.author, commit.author) 226 commit.author = self.authors.get(commit.author, commit.author)