[Yum-devel] [PATCH 1/2] Support meld as well as vimdiff for merging

rocketraman at fastmail.fm rocketraman at fastmail.fm
Fri Jun 17 16:30:19 UTC 2011


From: Raman Gupta <raman at rocketraman.com>

When using meld, the left side has the "other file" i.e. the file with
the .rpmnew or .rpmsave extension. The right side has the "final file"
i.e. the target file into which changes have to be merged.

If the rpm action was to save the existing conf file, then the left side
will be the original conf file (.rpmsave) and the right side will be the
new rpm-based configuration. The user should merge any changes they want
to keep from their old .rpmsave from left to right.

If the rpm action was to keep the existing conf file, then the left side
will be the new conf file (.rpmnew) and right side will be the current
local configuration. The user should merge any changes in the new rpm
file into their local config from left to right.

Ideally these operations would be 3-way diffs between the local file and
the new rpm config, using the original rpm config as the common merge base.
However, the original rpm config is not available to yum and therefore a
3-way diff is not possible. Perhaps a future enhancement would be to use a
.orig file, if present, as the merge base for meld.

When using vimdiff, the order has not changed. The first parameter to
vimdiff is the "final: file i.e. the target file, and the second parameter
is the "other" file i.e. the .rpmnew or .rpmsave file.
---
 plugins/merge-conf/merge-conf.py |   24 ++++++++++++++++--------
 1 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/plugins/merge-conf/merge-conf.py b/plugins/merge-conf/merge-conf.py
index b26cd25..634f781 100644
--- a/plugins/merge-conf/merge-conf.py
+++ b/plugins/merge-conf/merge-conf.py
@@ -50,10 +50,13 @@ def posttrans_hook(conduit):
     if conf.assumeyes:
         return    
         
-    has_vimdiff = False
+    has_prog = {"meld": False, "vimdiff": False}
     for d in os.getenv("PATH", "").split(":"):
-        if os.path.exists(os.path.join(d, "vimdiff")):
-            has_vimdiff = True
+        for prog in has_prog.keys():
+            if os.path.exists(os.path.join(d, prog)):
+                has_prog[prog] = True
+        # short circuit the search if all binaries are found
+        if not False in has_prog.values():
             break
     ts = conduit.getTsInfo()
     for tsmem in ts.getMembers():
@@ -78,11 +81,11 @@ def posttrans_hook(conduit):
             for fn, mode, flags in filetuple:
                 if flags & RPMFILE_CONFIG:
                     if flags & RPMFILE_NOREPLACE:
-                        mergeConfFiles(tsmem.po.name, fn, True, conduit, has_vimdiff)
+                        mergeConfFiles(tsmem.po.name, fn, True, conduit, has_prog)
                     else:
-                        mergeConfFiles(tsmem.po.name, fn, False, conduit, has_vimdiff)
+                        mergeConfFiles(tsmem.po.name, fn, False, conduit, has_prog)
 
-def mergeConfFiles(pkg, fn, noreplace, conduit, has_vimdiff):
+def mergeConfFiles(pkg, fn, noreplace, conduit, has_prog):
     if noreplace:
         local_file = fn
         pkg_file = "%s.rpmnew" % fn
@@ -127,7 +130,9 @@ def mergeConfFiles(pkg, fn, noreplace, conduit, has_vimdiff):
             print " - install the package's version (i)"
         else:
             print " - keep your version (n)"
-        if has_vimdiff:
+        if has_prog["meld"]:
+            print " - merge interactively with meld (m)"
+        if has_prog["vimdiff"]:
             print " - merge interactively with vim (v)"
         print " - background this process and examine manually (z)"
         sys.stdout.write("Your answer ? ")
@@ -154,7 +159,10 @@ def mergeConfFiles(pkg, fn, noreplace, conduit, has_vimdiff):
             os.system(os.getenv("SHELL", "bash"))
         elif answer == "q":
             print "Choosing RPM's default action."
-        elif answer == "v" and has_vimdiff:
+        elif answer == "m" and has_prog["meld"]:
+            os.system("""meld '%s' '%s'""" % (other_file, final_file))
+            break
+        elif answer == "v" and has_prog["vimdiff"]:
             os.system("""vimdiff '%s' '%s'""" % (final_file, other_file))
             break
         else:
-- 
1.7.4.4



More information about the Yum-devel mailing list