convert: fix authormap handling of lines without '='
Unpacking the result from str.split raises ValueError, not IndexError, if the
line does not contain a '='.
--- a/hgext/convert/convcmd.py Sat Mar 14 14:31:08 2009 +0200
+++ b/hgext/convert/convcmd.py Sat Apr 04 15:41:32 2009 +0200
@@ -197,24 +197,28 @@
def readauthormap(self, authorfile):
afile = open(authorfile, 'r')
for line in afile:
+
if line.strip() == '':
continue
+
try:
srcauthor, dstauthor = line.split('=', 1)
- srcauthor = srcauthor.strip()
- dstauthor = dstauthor.strip()
- if srcauthor in self.authors and dstauthor != self.authors[srcauthor]:
- self.ui.status(
- _('Overriding mapping for author %s, was %s, will be %s\n')
- % (srcauthor, self.authors[srcauthor], dstauthor))
- else:
- self.ui.debug(_('mapping author %s to %s\n')
- % (srcauthor, dstauthor))
- self.authors[srcauthor] = dstauthor
- except IndexError:
- self.ui.warn(
- _('Ignoring bad line in author map file %s: %s\n')
- % (authorfile, line.rstrip()))
+ except ValueError:
+ msg = _('Ignoring bad line in author map file %s: %s\n')
+ self.ui.warn(msg % (authorfile, line.rstrip()))
+ continue
+
+ srcauthor = srcauthor.strip()
+ dstauthor = dstauthor.strip()
+ if self.authors.get(srcauthor) in (None, dstauthor):
+ msg = _('mapping author %s to %s\n')
+ self.ui.debug(msg % (srcauthor, dstauthor))
+ self.authors[srcauthor] = dstauthor
+ continue
+
+ m = _('overriding mapping for author %s, was %s, will be %s\n')
+ self.ui.status(m % (srcauthor, self.authors[srcauthor], dstauthor))
+
afile.close()
def cachecommit(self, rev):
--- a/tests/test-convert-authormap Sat Mar 14 14:31:08 2009 +0200
+++ b/tests/test-convert-authormap Sat Apr 04 15:41:32 2009 +0200
@@ -15,6 +15,8 @@
# Explicit --authors
cat > authormap.txt <<EOF
user name = Long User Name
+
+this line is ignored
EOF
hg convert --authors authormap.txt orig new
--- a/tests/test-convert-authormap.out Sat Mar 14 14:31:08 2009 +0200
+++ b/tests/test-convert-authormap.out Sat Apr 04 15:41:32 2009 +0200
@@ -1,4 +1,5 @@
initializing destination new repository
+Ignoring bad line in author map file authormap.txt: this line is ignored
scanning source...
sorting...
converting...
@@ -12,6 +13,7 @@
date: Thu Jan 01 00:00:00 1970 +0000
summary: foo
+Ignoring bad line in author map file new/.hg/authormap: this line is ignored
scanning source...
sorting...
converting...