Patrick Mézard avatar Patrick Mézard committed 95ca6c8

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.

Comments (0)

Files changed (2)

mercurial/subrepo.py

     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:

tests/test-subrepo-missing.t

   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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.