[PATCH 6 of 6] require: includes all required features in the error message

Pierre-Yves David pierre-yves.david at ens-lyon.org
Sat Jun 18 06:10:04 CDT 2011


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1308395316 -7200
# Node ID e874fc9c2abaa476c854c354414ced41dd2e8f06
# Parent  2adef5173ae7566867fbb6d1cba76fd3711f1653
require: includes all required features in the error message

The goal is to avoid the following scenario:

1) Bob using version 1.6 try to access repo created with dotencode+generaldelta,
2) Bob get an error --> abort: […] requires features 'dotencode',
3) Bob check the wiki see that dotencode is introduced in 1.7,
4) Bob install version 1.8.0 (may include fighting with IT departement),
5) Bob get an error --> abort: […] requires features 'generaldelta',
6) Bob check the wiki see that generaldelta is introduced in 1.9,
7) Bob install version 1.9.0 (may include fighting with IT departement).
8) Bob access it's repo.

Note:

Version and requirement used here are for demo purpose only as version prior 1.9
wont have this changeset.

Such scenario are far from pure theorycraft, current mercurial version in debian
stable (squeeze) is 1.6.x. Current mercurial version in stable-backport is
1.8.4.

diff -r 2adef5173ae7 -r e874fc9c2aba mercurial/dispatch.py
--- a/mercurial/dispatch.py	Sat Jun 18 13:06:30 2011 +0200
+++ b/mercurial/dispatch.py	Sat Jun 18 13:08:36 2011 +0200
@@ -126,8 +126,8 @@
     except error.MissingRequirementError, inst:
         msg = _("abort: mercurial %s can not read this local repository!\n")
         ui.warn(_(msg % util.version()))
-        msg = _("       It requires feature '%s'.\n")
-        ui.warn(_(msg % inst.missing))
+        msg = _("       It requires features: '%s'.\n")
+        ui.warn(_(msg % "', '".join(sorted(inst.missing))))
         m = _("(see http://mercurial.selenic.com/wiki/RequiresFile for details)\n")
         ui.warn(m)
     except error.RepoError, inst:
diff -r 2adef5173ae7 -r e874fc9c2aba mercurial/scmutil.py
--- a/mercurial/scmutil.py	Sat Jun 18 13:06:30 2011 +0200
+++ b/mercurial/scmutil.py	Sat Jun 18 13:08:36 2011 +0200
@@ -696,10 +696,12 @@
     '''Reads and parses .hg/requires and checks if all entries found
     are in the list of supported features.'''
     requirements = set(opener.read("requires").splitlines())
-    for r in requirements:
-        if r not in supported:
-            if not r or not r[0].isalnum():
-                msg = _(".hg/requires file is corrupt")
-                raise error.CorruptRequirementError(msg)
-            raise error.MissingRequirementError(missing=r)
+    missing = requirements - supported
+    for r in missing:
+        if not r or not r[0].isalnum():
+            msg = _(".hg/requires file is corrupt")
+            raise error.CorruptRequirementError(msg)
+    if missing:
+        raise error.MissingRequirementError(missing=missing)
+
     return requirements
diff -r 2adef5173ae7 -r e874fc9c2aba tests/test-commit.t
--- a/tests/test-commit.t	Sat Jun 18 13:06:30 2011 +0200
+++ b/tests/test-commit.t	Sat Jun 18 13:08:36 2011 +0200
@@ -99,7 +99,7 @@
   $ echo fake >> .hg/requires
   $ hg commit -m bla
   abort: mercurial \d+.\d+.\d+[-+0-9a-f]* can not read this local repository! (re)
-         It requires feature 'fake'.
+         It requires features: 'fake'.
   (see http://mercurial.selenic.com/wiki/RequiresFile for details)
   [255]
 
diff -r 2adef5173ae7 -r e874fc9c2aba tests/test-identify.t
--- a/tests/test-identify.t	Sat Jun 18 13:06:30 2011 +0200
+++ b/tests/test-identify.t	Sat Jun 18 13:08:36 2011 +0200
@@ -108,14 +108,14 @@
   $ echo fake >> .hg/requires
   $ hg id
   abort: mercurial \d+.\d+.\d+[-+0-9a-f]* can not read this local repository! (re)
-         It requires feature 'fake'.
+         It requires features: 'fake'.
   (see http://mercurial.selenic.com/wiki/RequiresFile for details)
   [255]
 
   $ cd ..
   $ hg id test
   abort: mercurial \d+.\d+.\d+[-+0-9a-f]* can not read this local repository! (re)
-         It requires feature 'fake'.
+         It requires features: 'fake'.
   (see http://mercurial.selenic.com/wiki/RequiresFile for details)
   [255]
 
diff -r 2adef5173ae7 -r e874fc9c2aba tests/test-requires.t
--- a/tests/test-requires.t	Sat Jun 18 13:06:30 2011 +0200
+++ b/tests/test-requires.t	Sat Jun 18 13:08:36 2011 +0200
@@ -10,6 +10,12 @@
   $ echo indoor-pool > .hg/requires
   $ hg tip
   abort: mercurial \d+.\d+.\d+[-+0-9a-f]* can not read this local repository! (re)
-         It requires feature 'indoor-pool'.
+         It requires features: 'indoor-pool'.
   (see http://mercurial.selenic.com/wiki/RequiresFile for details)
   [255]
+  $ echo outdoor-pool >> .hg/requires
+  $ hg tip
+  abort: mercurial \d+.\d+.\d+[-+0-9a-f]* can not read this local repository! (re)
+         It requires features: 'indoor-pool', 'outdoor-pool'.
+  (see http://mercurial.selenic.com/wiki/RequiresFile for details)
+  [255]


More information about the Mercurial-devel mailing list