changeset 12069:7c3c44413bc1 stable

churn: do not crash on malformed lines in alias file
author Martin Geisler <mg@lazybytes.net>
date Sun, 29 Aug 2010 22:46:00 +0200
parents 2e7647d25458
children fddacca3202e eb7ddba6046a
files hgext/churn.py tests/test-churn tests/test-churn.out
diffstat 3 files changed, 10 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/churn.py	Sun Aug 29 10:54:22 2010 +0200
+++ b/hgext/churn.py	Sun Aug 29 22:46:00 2010 +0200
@@ -129,10 +129,14 @@
         aliases = repo.wjoin('.hgchurn')
     if aliases:
         for l in open(aliases, "r"):
-            if not l.strip():
+            try:
+                alias, actual = l.split('=' in l and '=' or None, 1)
+                amap[alias.strip()] = actual.strip()
+            except ValueError:
+                l = l.strip()
+                if l:
+                    ui.warn(_("skipping malformed alias: %s\n" % l))
                 continue
-            alias, actual = l.split('=' in l and '=' or None, 1)
-            amap[alias.strip()] = actual.strip()
 
     rate = countrate(ui, repo, amap, *pats, **opts).items()
     if not rate:
--- a/tests/test-churn	Sun Aug 29 10:54:22 2010 +0200
+++ b/tests/test-churn	Sun Aug 29 22:46:00 2010 +0200
@@ -40,6 +40,7 @@
 user1 alias1
 
 user3 alias3
+not-an-alias
 EOF
 hg churn --aliases ../aliases
 echo % churn with .hgchurn
--- a/tests/test-churn.out	Sun Aug 29 10:54:22 2010 +0200
+++ b/tests/test-churn.out	Sun Aug 29 22:46:00 2010 +0200
@@ -16,10 +16,12 @@
 user2      2 ***************************************************************
 user1      1 ********************************
 % churn with aliases
+skipping malformed alias: not-an-alias
 alias3      3 **************************************************************
 alias1      3 **************************************************************
 user2       2 *****************************************
 % churn with .hgchurn
+skipping malformed alias: not-an-alias
 alias3      3 **************************************************************
 alias1      3 **************************************************************
 user2       2 *****************************************