meld r1291 - trunk/vc



Author: vincele
Date: Thu Mar 26 21:10:13 2009
New Revision: 1291
URL: http://svn.gnome.org/viewvc/meld?rev=1291&view=rev

Log:
MultiVC don't show irrelevant repositories

This patch fixes a wrong behavior introduced by the recent multivc code.

Bug:
have a directory tree like the following

dir1/.git
dir1/.gitignore (with dir2 listed) (*)
dir1/dir2/.hg

(*) -> in fact this is not even required for the bad behavior to happen

I.e. two VC directories with one below the other.

when you launch meld in dir1/dir2, you'll have the git vc plugin active for dir1
and the multi vc combobox, will let you choose mercurial for dir2.

I think multiVC should be disabled in those cases and only display HG
in dir2, because that's what has been asked by the user.

This is even worse than that, as dir2 doesn't even have to be a direct
child of dir1, you could have:

${HOME}/work/repositories/.git
${HOME}/work/repositories/.gitignore (with hg, svn, darcs)
${HOME}/work/repositories/hg/projectone/.hg
${HOME}/work/repositories/svn/meld/trunk/.svn
${HOME}/work/repositories/svn/meld/branches/1.5.1/.svn
${HOME}/work/repositories/darcs/tailor/branch1/_darcs
${HOME}/work/repositories/scripts/

the scripts dir handled by the top level git will take fist place if you're
launching meld in the hg or the svn repositories, but second if you're
in darcs ones...

Explanation:
the introduction of the multivc code removed the default ordering function
that was used before and which chose the repository with the longest
repo.root. As some VC plugins walk from the proposed initial location
to the root of the filesystem to find their repository root directories, we
now find and propose repositories that are irrelevant to what has been
asked by the user.

Solution:
In order to only propose multiple VCs in the same directory and not those
upper in the filesystem, we should filter out those that don't have the
longest repo.root. I.e. do like before, but keep multiple choices if there are.



Modified:
   trunk/vc/__init__.py

Modified: trunk/vc/__init__.py
==============================================================================
--- trunk/vc/__init__.py	(original)
+++ trunk/vc/__init__.py	Thu Mar 26 21:10:13 2009
@@ -35,10 +35,28 @@
 _plugins = load_plugins()
 
 def get_vcs(location):
+    """Pick only the Vcs with the longest repo root
+    
+       Some VC plugins search their repository root
+       by walking the filesystem upwards its root
+       and now that we display multiple VCs in the
+       same directory, we must filter those other
+       repositories that are located in the search
+       path towards "/" as they are not relevant
+       to the user.
+    """
+
     vcs = []
+    max_len = 0
     for plugin in _plugins:
         try:
-            vcs.append(plugin.Vc(location))
+            avc = plugin.Vc(location)
+            l = len(avc.root)
+            if l == max_len:
+                vcs.append(avc)
+            elif l > max_len:
+                max_len = l
+                vcs = [avc]
         except ValueError:
             pass
 



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