churn: do not crash on malformed lines in alias file stable
authorMartin Geisler <mg@lazybytes.net>
Sun, 29 Aug 2010 22:46:00 +0200
branchstable
changeset 12069 7c3c44413bc1
parent 12068 2e7647d25458
child 12070 fddacca3202e
child 12080 eb7ddba6046a
churn: do not crash on malformed lines in alias file
hgext/churn.py
tests/test-churn
tests/test-churn.out
--- 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 *****************************************