[meld] Improve list of to-be-commited files for commit dialog (bgo#699182)



commit 1abccc425ca423cc85d95df126df360a090d657d
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sat May 4 08:44:28 2013 +1000

    Improve list of to-be-commited files for commit dialog (bgo#699182)
    
    Previously directories were displayed simply as the directory name.
    This commit adds a small additional API so that VCs can tell the
    commit dialog what they intend to commit from a given set of paths.

 meld/vc/_vc.py |    3 ++
 meld/vc/git.py |   61 +++++++++++++++++++++++++++++++++++--------------------
 meld/vcview.py |   12 ++++++++--
 3 files changed, 51 insertions(+), 25 deletions(-)
---
diff --git a/meld/vc/_vc.py b/meld/vc/_vc.py
index 1011b68..46ee155 100644
--- a/meld/vc/_vc.py
+++ b/meld/vc/_vc.py
@@ -134,6 +134,9 @@ class Vc(object):
 
     # Prototyping VC interface version 2
 
+    def get_files_to_commit(self, paths):
+        raise NotImplementedError()
+
     def get_commit_message_prefill(self):
         return None
 
diff --git a/meld/vc/git.py b/meld/vc/git.py
index 06fdcb6..a145934 100644
--- a/meld/vc/git.py
+++ b/meld/vc/git.py
@@ -97,6 +97,17 @@ class Vc(_vc.CachedVc):
 
     # Prototyping VC interface version 2
 
+    def get_files_to_commit(self, paths):
+        files = []
+        for p in paths:
+            if os.path.isdir(p):
+                entries = self._get_modified_files(p)
+                names = [self.diff_re.search(e).groups()[3] for e in entries]
+                files.extend(names)
+            else:
+                files.append(os.path.relpath(p, self.root))
+        return sorted(list(set(files)))
+
     def get_commit_message_prefill(self):
         """This will be inserted into the commit dialog when commit is run"""
         commit_path = os.path.join(self.root, ".git", "MERGE_MSG")
@@ -192,26 +203,38 @@ class Vc(_vc.CachedVc):
         else:
             return ''
 
+    def _get_modified_files(self, path):
+        # Update the index before getting status, otherwise we could
+        # be reading stale status information
+        _vc.popen([self.CMD, "update-index", "--refresh"],
+                  cwd=self.location)
+
+        # Get the status of files that are different in the "index" vs
+        # the HEAD of the git repository
+        proc = _vc.popen([self.CMD, "diff-index",
+                          "--cached", "HEAD", path], cwd=self.location)
+        entries = proc.read().split("\n")[:-1]
+
+        # Get the status of files that are different in the "index" vs
+        # the files on disk
+        proc = _vc.popen([self.CMD, "diff-files",
+                          "-0", path], cwd=self.location)
+        entries += (proc.read().split("\n")[:-1])
+
+        # An unmerged file or a file that has been modified, added to
+        # git's index, then modified again would result in the file
+        # showing up in both the output of "diff-files" and
+        # "diff-index".  The following command removes duplicate
+        # file entries.
+        entries = list(set(entries))
+
+        return entries
+
     def _update_tree_state_cache(self, path, tree_state):
         """ Update the state of the file(s) at tree_state['path'] """
         while 1:
             try:
-                # Update the index before getting status, otherwise we could
-                # be reading stale status information
-                _vc.popen([self.CMD, "update-index", "--refresh"],
-                          cwd=self.location)
-
-                # Get the status of files that are different in the "index" vs
-                # the HEAD of the git repository
-                proc = _vc.popen([self.CMD, "diff-index", \
-                    "--cached", "HEAD", path], cwd=self.location)
-                entries = proc.read().split("\n")[:-1]
-
-                # Get the status of files that are different in the "index" vs
-                # the files on disk
-                proc = _vc.popen([self.CMD, "diff-files", \
-                    "-0", path], cwd=self.location)
-                entries += (proc.read().split("\n")[:-1])
+                entries = self._get_modified_files(path)
 
                 # Identify ignored files
                 proc = _vc.popen([self.CMD, "ls-files", "--others", \
@@ -223,12 +246,6 @@ class Vc(_vc.CachedVc):
                     "--exclude-standard", path], cwd=self.location)
                 unversioned_entries = proc.read().split("\n")[:-1]
 
-                # An unmerged file or a file that has been modified, added to
-                # git's index, then modified again would result in the file
-                # showing up in both the output of "diff-files" and
-                # "diff-index".  The following command removes duplicate
-                # file entries.
-                entries = list(set(entries))
                 break
             except OSError as e:
                 if e.errno != errno.EAGAIN:
diff --git a/meld/vcview.py b/meld/vcview.py
index 67d3844..39192ac 100644
--- a/meld/vcview.py
+++ b/meld/vcview.py
@@ -85,10 +85,16 @@ class CommitDialog(gnomeglade.Component):
         self.parent = parent
         self.widget.set_transient_for(parent.widget.get_toplevel())
         selected = parent._get_selected_files()
-        topdir = _commonprefix(selected)
-        selected = ["\t" + s[len(topdir) + 1:] for s in selected]
+
+        try:
+            to_commit = parent.vc.get_files_to_commit(selected)
+            topdir = parent.vc.root
+            to_commit = ["\t" + s for s in to_commit]
+        except NotImplementedError:
+            topdir = _commonprefix(selected)
+            to_commit = ["\t" + s[len(topdir) + 1:] for s in selected]
         self.changedfiles.set_text("(in %s)\n%s" %
-                                   (topdir, "\n".join(selected)))
+                                   (topdir, "\n".join(to_commit)))
 
         fontdesc = pango.FontDescription(self.parent.prefs.get_current_font())
         self.textview.modify_font(fontdesc)


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