[meld] Pre-fill commit message dialog from VC when appropriate (bgo#699400)



commit cb2838b66f94f32d3a4fc253a6e807511c85cc27
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sat May 4 06:28:54 2013 +1000

    Pre-fill commit message dialog from VC when appropriate (bgo#699400)

 meld/vc/_vc.py |    3 +++
 meld/vc/git.py |   12 ++++++++++++
 meld/vcview.py |    6 ++++++
 3 files changed, 21 insertions(+), 0 deletions(-)
---
diff --git a/meld/vc/_vc.py b/meld/vc/_vc.py
index d21ed69..a6c5064 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_commit_message_prefill(self):
+        return None
+
     def push(self, runner):
         raise NotImplementedError()
 
diff --git a/meld/vc/git.py b/meld/vc/git.py
index 666d33d..13420ad 100644
--- a/meld/vc/git.py
+++ b/meld/vc/git.py
@@ -97,6 +97,18 @@ class Vc(_vc.CachedVc):
 
     # Prototyping VC interface version 2
 
+    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")
+        if os.path.exists(commit_path):
+            # If I have to deal with non-ascii, non-UTF8 pregenerated commit
+            # messages, I'm taking up pig farming.
+            with open(commit_path) as f:
+                message = f.read().decode('utf8')
+            return "\n".join(
+                (l for l in message.splitlines() if not l.startswith("#")))
+        return None
+
     def update(self, runner, files):
         command = [self.CMD, 'pull']
         runner(command, [], refresh=True, working_dir=self.root)
diff --git a/meld/vcview.py b/meld/vcview.py
index 20958be..67d3844 100644
--- a/meld/vcview.py
+++ b/meld/vcview.py
@@ -89,8 +89,14 @@ class CommitDialog(gnomeglade.Component):
         selected = ["\t" + s[len(topdir) + 1:] for s in selected]
         self.changedfiles.set_text("(in %s)\n%s" %
                                    (topdir, "\n".join(selected)))
+
         fontdesc = pango.FontDescription(self.parent.prefs.get_current_font())
         self.textview.modify_font(fontdesc)
+        commit_prefill = self.parent.vc.get_commit_message_prefill()
+        if commit_prefill:
+            buf = self.textview.get_buffer()
+            buf.set_text(commit_prefill)
+            buf.place_cursor(buf.get_start_iter())
 
         # Try and make the textview wide enough for a standard 80-character
         # commit message.


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