changeset 22345:cf7014c5f087

obsolete: add a `commonversion` function This function returns the highest common version between the locally known formats and a list of remotely known formats. This is going to be useful to know what format should be used for exchange.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Tue, 26 Aug 2014 11:36:23 +0200
parents 9829b7948100
children a76660f85200
files mercurial/obsolete.py
diffstat 1 files changed, 11 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/obsolete.py	Tue Aug 26 11:48:26 2014 +0200
+++ b/mercurial/obsolete.py	Tue Aug 26 11:36:23 2014 +0200
@@ -455,6 +455,17 @@
             seennodes |= pendingnodes
         return seenmarkers
 
+def commonversion(versions):
+    """Return the newest version listed in both versions and our local formats.
+
+    Returns None if no common version exists.
+    """
+    versions.sort(reverse=True)
+    # search for highest version known on both side
+    for v in versions:
+        if v in formats:
+            return v
+    return None
 
 # arbitrary picked to fit into 8K limit from HTTP server
 # you have to take in account: