# HG changeset patch
# User Thomas Arendsen Hein <thomas@intevation.de>
# Date 2012-07-19 19:20:56
# Node ID d1b49b02bc161faed1f397cb8fe13a38299bbc01
# Parent  7af38fe1f829eafdd02d19ece4c5276f23ead9f3

dispatch: fix traceback when extension was tested with newer versions only

The "worst" extension still is the one tested with the lowest tested version
below the current version of Mercurial, but if an extension with was only
tested with newer versions, it is considered a candidate for a bad extension,
too. In this case extensions which have been tested with higher versions of
Mercurial are considered better. This allows finding the oldest extension if
ct can't be calculated correctly and therefore defaults to an empty tuple, and
it involves less changes to the comparison logic during the current code
freeze.

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -225,8 +225,9 @@ def _runcatch(req):
                 break
             if compare not in testedwith.split() and testedwith != 'internal':
                 tested = [tuplever(v) for v in testedwith.split()]
-                nearest = max([t for t in tested if t < ct])
-                if nearest < worst[1]:
+                lower = [t for t in tested if t < ct]
+                nearest = max(lower or tested)
+                if worst[0] is None or nearest < worst[1]:
                     worst = name, nearest, report
         if worst[0] is not None:
             name, testedwith, report = worst
diff --git a/tests/test-extension.t b/tests/test-extension.t
--- a/tests/test-extension.t
+++ b/tests/test-extension.t
@@ -522,7 +522,31 @@ If the extensions declare outdated versi
   ** Please disable older and try your action again.
   ** If that fixes the bug please report it to the extension author.
   ** Python * (glob)
-  ** Mercurial Distributed SCM (*) (glob)
+  ** Mercurial Distributed SCM (version 2.2)
+  ** Extensions loaded: throw, older
+One extension only tested with older, one only with newer versions:
+  $ echo "util.version = lambda:'2.1.0'" >> older.py
+  $ rm -f older.pyc older.pyo
+  $ hg --config extensions.throw=throw.py --config extensions.older=older.py \
+  >   throw 2>&1 | egrep '^\*\*'
+  ** Unknown exception encountered with possibly-broken third-party extension older
+  ** which supports versions 1.9.3 of Mercurial.
+  ** Please disable older and try your action again.
+  ** If that fixes the bug please report it to the extension author.
+  ** Python * (glob)
+  ** Mercurial Distributed SCM (version 2.1.0)
+  ** Extensions loaded: throw, older
+Older extension is tested with current version, the other only with newer:
+  $ echo "util.version = lambda:'1.9.3'" >> older.py
+  $ rm -f older.pyc older.pyo
+  $ hg --config extensions.throw=throw.py --config extensions.older=older.py \
+  >   throw 2>&1 | egrep '^\*\*'
+  ** Unknown exception encountered with possibly-broken third-party extension throw
+  ** which supports versions 2.1.1 of Mercurial.
+  ** Please disable throw and try your action again.
+  ** If that fixes the bug please report it to http://example.com/bts
+  ** Python * (glob)
+  ** Mercurial Distributed SCM (version 1.9.3)
   ** Extensions loaded: throw, older
 
 Declare the version as supporting this hg version, show regular bts link: