[meld] Add --output option to specify merge result filename (closes bgo#321290)



commit f48e05bf4e7532996a19376fd754f2cce4eaf7d5
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Fri Sep 24 06:05:42 2010 +1000

    Add --output option to specify merge result filename (closes bgo#321290)
    
    This patch allows a file (specifically, the second pane) to read from
    one file and save to a different one. This allows easier handling of,
    for example, three-way merges for certain VC tool integration.

 meld/filediff.py |   15 ++++++++++++---
 meld/meldapp.py  |    6 ++++++
 2 files changed, 18 insertions(+), 3 deletions(-)
---
diff --git a/meld/filediff.py b/meld/filediff.py
index 218e269..ebce01e 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -771,6 +771,11 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
         for l,d in zip(lst,self.bufferdata):
             if len(l): d.label = l
 
+    def set_merge_output_file(self, filename):
+        if len(self.bufferdata) < 2:
+            return
+        self.bufferdata[1].savefile = os.path.abspath(filename)
+
     def recompute_label(self):
         filenames = []
         for i in range(self.num_panes):
@@ -1143,8 +1148,10 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
                     _("'%s' contains characters not encodable with '%s'\nWould you like to save as UTF-8?") % (bufdata.label, bufdata.encoding),
                     self, gtk.MESSAGE_ERROR, gtk.BUTTONS_YES_NO) != gtk.RESPONSE_YES:
                     return melddoc.RESULT_ERROR
-        if self._save_text_to_filename(bufdata.filename, text):
-            self.emit("file-changed", bufdata.filename)
+
+        save_to = bufdata.savefile or bufdata.filename
+        if self._save_text_to_filename(save_to, text):
+            self.emit("file-changed", save_to)
             self.undosequence.checkpoint(buf)
             return melddoc.RESULT_OK
         else:
@@ -1547,11 +1554,13 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
 ################################################################################
 
 class MeldBufferData(object):
-    __slots__ = ("modified", "writable", "filename", "label", "encoding", "newlines")
+    __slots__ = ("modified", "writable", "filename", "savefile", "label",
+                 "encoding", "newlines")
     def __init__(self, filename=None):
         self.modified = 0
         self.writable = 1
         self.filename = filename
+        self.savefile = None
         self.label = filename
         self.encoding = None
         self.newlines = None
diff --git a/meld/meldapp.py b/meld/meldapp.py
index e50ed6a..269bddc 100644
--- a/meld/meldapp.py
+++ b/meld/meldapp.py
@@ -614,6 +614,9 @@ class MeldApp(gnomeglade.Component):
             help=_("Set label to use instead of file name"))
         parser.add_option("-a", "--auto-compare", action="store_true", default=False,
             help=_("Automatically compare all differing files on startup"))
+        parser.add_option("-o", "--output", action="store", type="string",
+            dest="outfile", default=None,
+            help=_("Set the target file for saving a merge result"))
         parser.add_option("", "--diff", action="callback", callback=self.diff_files_callback,
                           dest="diff", default=[],
                           help=_("Creates a diff tab for up to 3 supplied files or directories."))
@@ -628,6 +631,9 @@ class MeldApp(gnomeglade.Component):
         if tab:
             tab.set_labels(options.label)
 
+        if options.outfile and tab and isinstance(tab, filediff.FileDiff):
+            tab.set_merge_output_file(options.outfile)
+
     def _single_file_open(self, path):
         doc = vcview.VcView(self.prefs)
         def cleanup():



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