changeset 13505:9b617c56eb65 stable

eol: do not abort on parse error Handle parse errors in the .hgeol similarly to how parse errors in the .hgtags file are handled: by issuing a warning. This allows the user to revert the file using 'hg revert' or 'hg update -C'.
author Martin Geisler <mg@aragost.com>
date Mon, 28 Feb 2011 15:46:48 +0100
parents 85840c4ae2ad
children 117990768fe0
files hgext/eol.py tests/test-eol.t
diffstat 2 files changed, 25 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/eol.py	Mon Feb 28 11:34:51 2011 +0100
+++ b/hgext/eol.py	Mon Feb 28 15:46:48 2011 +0100
@@ -152,7 +152,11 @@
 
 def preupdate(ui, repo, hooktype, parent1, parent2):
     #print "preupdate for %s: %s -> %s" % (repo.root, parent1, parent2)
-    repo.readhgeol(parent1)
+    try:
+        repo.readhgeol(parent1)
+    except error.ParseError, inst:
+        ui.warn(_("warning: ignoring .hgeol file due to parse error "
+                  "at %s: %s\n") % (inst.args[1], inst.args[0]))
     return False
 
 def uisetup(ui):
@@ -233,7 +237,12 @@
             return match.match(self.root, '', [], include, exclude)
 
         def _hgcleardirstate(self):
-            self._eolfile = self.readhgeol() or self.readhgeol('tip')
+            try:
+                self._eolfile = self.readhgeol() or self.readhgeol('tip')
+            except error.ParseError, inst:
+                ui.warn(_("warning: ignoring .hgeol file due to parse error "
+                          "at %s: %s\n") % (inst.args[1], inst.args[0]))
+                self._eolfile = None
 
             if not self._eolfile:
                 self._eolfile = util.never
--- a/tests/test-eol.t	Mon Feb 28 11:34:51 2011 +0100
+++ b/tests/test-eol.t	Mon Feb 28 15:46:48 2011 +0100
@@ -426,3 +426,17 @@
   foo
   bar
   baz
+
+Test handling of a broken .hgeol file:
+
+  $ touch .hgeol
+  $ hg add .hgeol
+  $ hg commit -m 'clean version'
+  $ echo "bad" > .hgeol
+  $ hg status
+  warning: ignoring .hgeol file due to parse error at .hgeol:1: bad
+  M .hgeol
+  $ hg revert .hgeol
+  warning: ignoring .hgeol file due to parse error at .hgeol:1: bad
+  $ hg status
+  ? .hgeol.orig