changeset 16596:95ca6c8b38da stable

subrepo: do not traceback on .hgsubstate parsing errors Note that aborting in subrepo.state() prevents "repairing" commands like revert to be issued. The user will have to edit the .hgsubstate manually (but he probably had already otherwise this would not be failing). The same behaviour already happens with invalid .hgsub entries.
author Patrick Mezard <patrick@mezard.eu>
date Fri, 04 May 2012 14:19:55 +0200
parents 2de6ac4ac17c
children b767382a8675
files mercurial/subrepo.py tests/test-subrepo-missing.t
diffstat 2 files changed, 16 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/subrepo.py	Fri May 04 14:19:52 2012 +0200
+++ b/mercurial/subrepo.py	Fri May 04 14:19:55 2012 +0200
@@ -43,11 +43,16 @@
     rev = {}
     if '.hgsubstate' in ctx:
         try:
-            for l in ctx['.hgsubstate'].data().splitlines():
+            for i, l in enumerate(ctx['.hgsubstate'].data().splitlines()):
                 l = l.lstrip()
                 if not l:
                     continue
-                revision, path = l.split(" ", 1)
+                try:
+                    revision, path = l.split(" ", 1)
+                except ValueError:
+                    raise util.Abort(_("invalid subrepository revision "
+                                       "specifier in .hgsubstate line %d")
+                                     % (i + 1))
                 rev[path] = revision
         except IOError, err:
             if err.errno != errno.ENOENT:
--- a/tests/test-subrepo-missing.t	Fri May 04 14:19:52 2012 +0200
+++ b/tests/test-subrepo-missing.t	Fri May 04 14:19:55 2012 +0200
@@ -19,6 +19,15 @@
   M .hgsubstate
   $ hg revert -qC .hgsubstate
 
+abort more gracefully on .hgsubstate parsing error
+
+  $ cp .hgsubstate .hgsubstate.old
+  >>> file('.hgsubstate', 'wb').write('\ninvalid')
+  $ hg st --subrepos
+  abort: invalid subrepository revision specifier in .hgsubstate line 2
+  [255]
+  $ mv .hgsubstate.old .hgsubstate
+
 delete .hgsub and revert it
 
   $ rm .hgsub