[meld] Add and use sorting criteria for VC systems (closes bgo#663055)



commit 8c33be86e2088afd78b19df2db5e831dba3aef0c
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Tue Nov 29 06:21:24 2011 +1000

    Add and use sorting criteria for VC systems (closes bgo#663055)
    
    This fixes the problem of not knowing which VC the user wants to see
    when a directory is under revision control by multiple different
    systems.
    
    The sort order is in rough order of popularity, with distributed
    version control systems coming first. The reasoning for this is that
    if we find e.g., SVN and Git in a single directory, the likelihood is
    that there is an organisation SVN repository and the Git copy is the
    user's local working repository. Therefore, we show the Git copy.

 meld/vc/__init__.py |   27 ++++++++++++++++++++++++++-
 1 files changed, 26 insertions(+), 1 deletions(-)
---
diff --git a/meld/vc/__init__.py b/meld/vc/__init__.py
index ce2896a..bca7967 100644
--- a/meld/vc/__init__.py
+++ b/meld/vc/__init__.py
@@ -45,6 +45,22 @@ def get_plugins_metadata():
             ret.extend(p.Vc.VC_METADATA)
     return ret
 
+vc_sort_order = (
+    "Git",
+    "Bazaar-NG",
+    "Mercurial",
+    "Fossil",
+    "Monotone",
+    "Darcs",
+    "Arch",
+    "Codeville",
+    "SVK",
+    "Subversion",
+    "Subversion 1.7",
+    "CVS",
+    "RCS",
+)
+
 def get_vcs(location):
     """Pick only the Vcs with the longest repo root
     
@@ -73,6 +89,15 @@ def get_vcs(location):
 
     if not vcs:
         # No plugin recognized that location, fallback to _null
-        vcs.append(_null.Vc(location))
+        return [_null.Vc(location)]
+
+    vc_comp = lambda a, b: cmp(vc_sort_order.index(a), vc_sort_order.index(b))
+    vc_name = lambda x: x.NAME
+    vcs.sort(cmp=vc_comp, key=vc_name)
+
+    # Simplistic hack so that we don't offer both 1.7 and <1.6 SVN
+    vc_names = [plugin.NAME for plugin in vcs]
+    if "Subversion" in vc_names and "Subversion 1.7" in vc_names:
+        vcs = [plugin for plugin in vcs if plugin.NAME != "Subversion 1.7"]
 
     return vcs



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]