[meld] Add --auto-merge option
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld] Add --auto-merge option
- Date: Tue, 25 Sep 2012 20:44:36 +0000 (UTC)
commit d3787b5b4d9de16652495cf983627e3bb3bdfad3
Author: Piotr Piastucki <the_leech users berlios de>
Date: Wed Sep 19 22:35:25 2012 +0200
Add --auto-merge option
This commit adds a new --auto-merge switch and changes the way conflict
solver mode is invoked. It also slightly simplifies and fixes the code
in filemerge module.
meld/filemerge.py | 25 ++++++++++---------------
meld/meldapp.py | 18 ++++++++++--------
meld/meldwindow.py | 24 +++++++++++++++---------
3 files changed, 35 insertions(+), 32 deletions(-)
---
diff --git a/meld/filemerge.py b/meld/filemerge.py
index 8646166..5eeb0d9 100644
--- a/meld/filemerge.py
+++ b/meld/filemerge.py
@@ -17,7 +17,9 @@
import filediff
from gettext import gettext as _
import gtk
+import meldbuffer
import merge
+import os
MASK_SHIFT, MASK_CTRL = 1, 2
@@ -28,41 +30,33 @@ class FileMerge(filediff.FileDiff):
def __init__(self, prefs, num_panes):
filediff.FileDiff.__init__(self, prefs, num_panes)
- self.hidden_textbuffer = gtk.TextBuffer()
+ self.hidden_textbuffer = meldbuffer.MeldBuffer()
def _connect_buffer_handlers(self):
filediff.FileDiff._connect_buffer_handlers(self)
self.textview[0].set_editable(0)
self.textview[2].set_editable(0)
- def set_files(self, files):
- if len(files) == 4:
- self.ancestor_file = files[1]
- self.merge_file = files[3]
- files[1] = files[3]
- files = files[:3]
- filediff.FileDiff.set_files(self, files)
+ def set_merge_output_file(self, filename):
+ filediff.FileDiff.set_merge_output_file(self, filename)
+ self.textbuffer[1].data.set_label(filename)
+ self.fileentry[1].set_filename(os.path.abspath(filename))
+ self.recompute_label()
def _set_files_internal(self, files):
textbuffers = self.textbuffer[:]
textbuffers[1] = self.hidden_textbuffer
- files[1] = self.ancestor_file
for i in self._load_files(files, textbuffers):
yield i
for i in self._merge_files():
yield i
for i in self._diff_files():
yield i
+ filediff.FileDiff.set_buffer_writable(self, self.textbuffer[1], True)
def _get_custom_status_text(self):
return " Conflicts: %i" % (self.linediffer.get_unresolved_count())
- def set_buffer_writable(self, buf, yesno):
- if buf == self.hidden_textbuffer:
- buf = self.textbuffer[1]
- yesno = True
- filediff.FileDiff.set_buffer_writable(self, buf, yesno)
-
def _merge_files(self):
yield _("[%s] Computing differences") % self.label_text
panetext = []
@@ -87,3 +81,4 @@ class FileMerge(filediff.FileDiff):
self.textbuffer[1].data.modified = True
self.recompute_label()
yield 1
+
diff --git a/meld/meldapp.py b/meld/meldapp.py
index 7a944a6..4b3c8e2 100644
--- a/meld/meldapp.py
+++ b/meld/meldapp.py
@@ -147,7 +147,7 @@ class MeldApp(gobject.GObject):
diff_files_args.append(arg)
del parser.rargs[0]
- if len(diff_files_args) not in (1, 2, 3, 4):
+ if len(diff_files_args) not in (1, 2, 3):
raise optparse.OptionValueError(
_("wrong number of arguments supplied to --diff"))
parser.values.diff.append(diff_files_args)
@@ -176,14 +176,18 @@ class MeldApp(gobject.GObject):
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("--auto-merge", None, action="store_true", default=False,
+ help=_("Automatically merge files"))
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."))
options, args = parser.parse_args(rawargs)
- if len(args) > 4:
- parser.error(_("too many arguments (wanted 0-4, got %d)") % len(args))
- elif len(args) == 4 and any([os.path.isdir(f) for f in args]):
- parser.error(_("can't compare more than three directories"))
+ if len(args) > 3:
+ parser.error(_("too many arguments (wanted 0-3, got %d)") % len(args))
+ elif options.auto_merge and len(args) < 3:
+ parser.error(_("can't auto-merge less than 3 files"))
+ elif options.auto_merge and any([os.path.isdir(f) for f in args]):
+ parser.error(_("can't auto-merge directories"))
new_window = True
open_paths = self.window.open_paths
@@ -195,11 +199,9 @@ class MeldApp(gobject.GObject):
new_window = False
for files in options.diff:
- if len(files) == 4 and any([os.path.isdir(f) for f in files]):
- parser.error(_("can't compare more than three directories"))
open_paths(files)
- tab = open_paths(args, options.auto_compare)
+ tab = open_paths(args, options.auto_compare, options.auto_merge)
if options.label and tab:
tab.set_labels(options.label)
diff --git a/meld/meldwindow.py b/meld/meldwindow.py
index c3263cc..97d4014 100644
--- a/meld/meldwindow.py
+++ b/meld/meldwindow.py
@@ -639,16 +639,20 @@ class MeldWindow(gnomeglade.Component):
return doc
def append_filediff(self, files):
- assert len(files) in (1, 2, 3, 4)
- if len(files) == 4:
- doc = filemerge.FileMerge(app.prefs, 3)
- else:
- doc = filediff.FileDiff(app.prefs, len(files))
+ assert len(files) in (1, 2, 3)
+ doc = filediff.FileDiff(app.prefs, len(files))
+ self._append_page(doc, "text-x-generic")
+ doc.set_files(files)
+ return doc
+
+ def append_filemerge(self, files):
+ assert len(files) == 3
+ doc = filemerge.FileMerge(app.prefs, len(files))
self._append_page(doc, "text-x-generic")
doc.set_files(files)
return doc
- def append_diff(self, paths, auto_compare=False):
+ def append_diff(self, paths, auto_compare=False, auto_merge=False):
dirslist = [p for p in paths if os.path.isdir(p)]
fileslist = [p for p in paths if os.path.isfile(p)]
if dirslist and fileslist:
@@ -672,6 +676,8 @@ class MeldWindow(gnomeglade.Component):
return self.append_filediff(builtfilelist)
elif dirslist:
return self.append_dirdiff(paths, auto_compare)
+ elif auto_merge:
+ return self.append_filemerge(paths)
else:
return self.append_filediff(paths)
@@ -695,7 +701,7 @@ class MeldWindow(gnomeglade.Component):
doc.connect("create-diff", lambda obj,arg: self.append_diff(arg))
doc.run_diff([path])
- def open_paths(self, paths, auto_compare=False):
+ def open_paths(self, paths, auto_compare=False, auto_merge=False):
tab = None
if len(paths) == 1:
a = paths[0]
@@ -704,8 +710,8 @@ class MeldWindow(gnomeglade.Component):
else:
tab = self.append_vcview(a, auto_compare)
- elif len(paths) in (2, 3, 4):
- tab = self.append_diff(paths, auto_compare)
+ elif len(paths) in (2, 3):
+ tab = self.append_diff(paths, auto_compare, auto_merge)
return tab
def current_doc(self):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]