[PATCH 2 of 3] convert: Fix authormap handling of lines without '='; refactor readauthormap()
Marti Raudsepp
marti at juffo.org
Sat Mar 14 07:39:33 CDT 2009
# HG changeset patch
# User Marti Raudsepp <marti at juffo.org>
# Date 1235986682 0
# Node ID 500b4fd352a9194c2a52b90e922f5110cdabeda9
# Parent 4c4f8257cd43d5a8ad1002f9348979c0dfef6ffc
convert: Fix authormap handling of lines without '='; refactor readauthormap()
Unpacking the result from str.split raises ValueError, not IndexError, if the
line does not contain a '='.
diff --git a/hgext/convert/convcmd.py b/hgext/convert/convcmd.py
--- a/hgext/convert/convcmd.py
+++ b/hgext/convert/convcmd.py
@@ -201,20 +201,22 @@
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:
+ except ValueError:
self.ui.warn(
_('Ignoring bad line in author map file %s: %s\n')
% (authorfile, line.rstrip()))
+ continue
+
+ 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
afile.close()
def cachecommit(self, rev):
diff --git a/tests/test-convert-authormap b/tests/test-convert-authormap
--- a/tests/test-convert-authormap
+++ b/tests/test-convert-authormap
@@ -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
diff --git a/tests/test-convert-authormap.out b/tests/test-convert-authormap.out
--- a/tests/test-convert-authormap.out
+++ b/tests/test-convert-authormap.out
@@ -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...
More information about the Mercurial-devel
mailing list