[PATCH/RFC] Fix scanning of entire VC repository for single-file diff



Previously, running meld on one file in a version-controlled directory
would result in meld scanning the entire repository for modifications.
The scanning of the entire repository was unnecessary and could hog
system resources, especially on larger repositories.

Signed-off-by: Peter Tyser <ptyser gmail com>
---
I don't know if the logic added to _set_location() is the best way to
prevent repository-wide searching, so comments are more than welcome.

This patch was in response to http://mail.gnome.org/archives/meld-list/2010-April/msg00017.html
---
 meld/meldapp.py |    2 +-
 meld/vc/_vc.py  |   13 +++++++++----
 meld/vcview.py  |    6 +++++-
 3 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/meld/meldapp.py b/meld/meldapp.py
index b55afe4..148461e 100644
--- a/meld/meldapp.py
+++ b/meld/meldapp.py
@@ -915,7 +915,7 @@ class MeldApp(gnomeglade.Component):
             self.scheduler.remove_scheduler(doc.scheduler)
         self.scheduler.add_task(cleanup)
         self.scheduler.add_scheduler(doc.scheduler)
-        doc.set_location(os.path.dirname(path))
+        doc.set_location(path)
         doc.connect("create-diff", lambda obj,arg: self.append_diff(arg))
         doc.run_diff([path])
 
diff --git a/meld/vc/_vc.py b/meld/vc/_vc.py
index ba5d49e..52071de 100644
--- a/meld/vc/_vc.py
+++ b/meld/vc/_vc.py
@@ -76,15 +76,20 @@ class Vc(object):
     VC_METADATA = None
 
     def __init__(self, location):
-        # Save the requested diff directory.  It may be a sub-directory
+        # Save the requested diff directory/file.  It may be a sub-directory
         # of the repository we are diffing and can be useful in limiting meld's
-        # output to the requested location.
+        # output to the requested location.  It can also be used to determine
+        # if the user is requesting a single-file diff or a diretcory diff.
         self.location = location
 
+        if not os.path.isdir(location):
+            path = os.path.dirname(self.location)
+        else:
+            path = location
         if self.VC_ROOT_WALK:
-            self.root = self.find_repo_root(location)
+            self.root = self.find_repo_root(path)
         else:
-            self.root = self.check_repo_root(location)
+            self.root = self.check_repo_root(path)
 
     def commit_command(self, message):
         raise NotImplementedError()
diff --git a/meld/vcview.py b/meld/vcview.py
index 23002c2..9f93a91 100644
--- a/meld/vcview.py
+++ b/meld/vcview.py
@@ -262,7 +262,11 @@ class VcView(melddoc.MeldDoc, gnomeglade.Component):
         self.model.set_state(it, 0, tree.STATE_NORMAL, isdir=1)
         self.recompute_label()
         self.scheduler.remove_all_tasks()
-        self.scheduler.add_task( self._search_recursively_iter(self.model.get_iter_root()).next )
+
+        # If the user is just diffing a file (ie not a directory), there's no
+        # need to scan the rest of the repository
+        if os.path.isdir(self.vc.location):
+            self.scheduler.add_task(self._search_recursively_iter(self.model.get_iter_root()).next)
 
     def recompute_label(self):
         self.label_text = os.path.basename(self.location)
-- 
1.6.2-rc2.GIT



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