obsolete: add a `commonversion` function
authorPierre-Yves David <pierre-yves.david@fb.com>
Tue, 26 Aug 2014 11:36:23 +0200
changeset 22345 cf7014c5f087
parent 22344 9829b7948100
child 22346 a76660f85200
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.
mercurial/obsolete.py
--- 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: