changeset 39465:4062bbb1d10f

narrow: use util.readfile() and improve error message using --narrowspec This patch improves the error message and uses util.readfile() for reading narrowspecs file while cloning. Differential Revision: https://phab.mercurial-scm.org/D4462
author Pulkit Goyal <pulkit@yandex-team.ru>
date Tue, 04 Sep 2018 19:26:50 +0300
parents 3dd34b401bc2
children 83dd656586b1
files hgext/narrow/narrowcommands.py
diffstat 1 files changed, 5 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/narrow/narrowcommands.py	Tue Sep 04 15:55:23 2018 -0700
+++ b/hgext/narrow/narrowcommands.py	Tue Sep 04 19:26:50 2018 +0300
@@ -84,12 +84,12 @@
         filepath = os.path.join(pycompat.getcwd(), narrowspecfile)
         ui.status(_("reading narrowspec from '%s'\n") % filepath)
         try:
-            fp = open(filepath, 'rb')
-        except IOError:
-            raise error.Abort(_("file '%s' not found") % filepath)
+            fdata = util.readfile(filepath)
+        except IOError as inst:
+            raise error.Abort(_("cannot read narrowspecs from '%s': %s") %
+                              (filepath, encoding.strtolocal(inst.strerror)))
 
-        includes, excludes, profiles = sparse.parseconfig(ui, fp.read(),
-                                                          'narrow')
+        includes, excludes, profiles = sparse.parseconfig(ui, fdata, 'narrow')
         if profiles:
             raise error.Abort(_("cannot specify other files using '%include' in"
                                 " narrowspec"))