Commit f48e05bf authored by Kai Willadsen's avatar Kai Willadsen

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.
parent b98efd8a
......@@ -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
......
......@@ -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():
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment