Patch for meld to handle multiple diffs from command line



Hello. I think I've developed a patch for meld that would allow it to handle multiple comparisons from one command line execution. The idea is that the current usage is kept the same, but multiple diffs can be specified by separating each one with a "-" in the argument list. So for example, you could run:

    meld file1.orig file1.mine - file2.orig file2.mine - file3.orig file3.mine

And it would show up with a tab for each of those comparisons.

Patch is attached. Feedback is welcome; just thought I would share my contribution.

-Ken
diff -u -r meld.orig/meldapp.py meld/meldapp.py
--- meld.orig/meldapp.py	2009-09-16 17:19:16.000000000 -0600
+++ meld/meldapp.py	2009-09-16 18:15:40.000000000 -0600
@@ -842,7 +842,10 @@
     %prog <dir>                 Start with VC browser in 'dir'
     %prog <file>                Start with VC diff of 'file'
     %prog <file> <file> [file]  Start with 2 or 3 way file comparison
-    %prog <dir>  <dir>  [dir]   Start with 2 or 3 way directory comparison""",
+    %prog <dir>  <dir>  [dir]   Start with 2 or 3 way directory comparison
+    
+    Multiple diffs may be separated with "-".
+    """,
     description="""Meld is a file and directory comparison tool.""",
     version="%prog "+version)
     parser.add_option("-L", "--label", action="append", default=[], help=_("Set label to use instead of file name"))
@@ -854,30 +857,42 @@
 
     app = MeldApp()
     tab = None
-
-    if len(args) == 0:
-        pass
-
-    elif len(args) == 1:
-        a = args[0]
-        if os.path.isfile(a):
-            doc = vcview.VcView(app.prefs)
-            def cleanup():
-                app.scheduler.remove_scheduler(doc.scheduler)
-            app.scheduler.add_task(cleanup)
-            app.scheduler.add_scheduler(doc.scheduler)
-            doc.set_location( os.path.dirname(a) )
-            doc.connect("create-diff", lambda obj,arg: app.append_diff(arg) )
-            doc.run_diff([a])
-        else:
-            tab = app.append_vcview( [a] )
-                
-    elif len(args) in (2,3):
-        tab = app.append_diff(args)
+    
+    if '-' in args:
+        ##
+        ## There are multiple diffs, separated by '-'
+        argParts = []
+        working = args
+        while '-' in working:
+            argParts.append(working[:working.index('-')])
+            working = working[working.index('-')+1:]
+        argParts.append(working)
     else:
-        app.usage( _("Wrong number of arguments (Got %i)") % len(args))
-
-    if tab:
-        tab.set_labels( options.label )
+        argParts = [args]
+    
+    for args in argParts:
+        if len(args) == 0:
+            pass
+        elif len(args) == 1:
+            a = args[0]
+            if os.path.isfile(a):
+                doc = vcview.VcView(app.prefs)
+                def cleanup():
+                    app.scheduler.remove_scheduler(doc.scheduler)
+                app.scheduler.add_task(cleanup)
+                app.scheduler.add_scheduler(doc.scheduler)
+                doc.set_location( os.path.dirname(a) )
+                doc.connect("create-diff", lambda obj,arg: app.append_diff(arg) )
+                doc.run_diff([a])
+            else:
+                tab = app.append_vcview( [a] )
+                    
+        elif len(args) in (2,3):
+            tab = app.append_diff(args)
+        else:
+            app.usage( _("Wrong number of arguments (Got %i)") % len(args))
+    
+        if tab:
+            tab.set_labels( options.label )
     app.main()
 
Binary files meld.orig/meldapp.pyc and meld/meldapp.pyc differ


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