Package: dirdiff
Version: 2.1-7.2
Severity: wishlist
Tags: patch

It'd be nice if it'd be possible to also view n-way diffs in external
viewers (here: in vimdiff). That's just what the attached patch does:
if set then the configured external viewer is also used for n-way diffs.

There's one aspect of this patch, that's a bit ugly: the patch is pretty
much an exact copy of the code of the "proc diff2" code part, that calls
the external viewer.

This results in the params given to the external viewer being a bit
"weird". Namely what the external viewer gets as parameters is:

    dir1 dir2 dir3 ... file_path

That means that the external viewer needs to check the number of
parameters and if there's more than two, then it needs to construct the
filepaths like this:

    dir1/file_path dir2/file_path dir3/file_path ...

I've implemented a wrapper for vimdiff that does that. It's using
`konsole` as a terminal, but that can be changed easily:

    $ cat ~/bin/dirdiff_vimdiff 
    #!/bin/bash
    #
    if [ $# -gt 2 ]; then
            # dirdiff calls us with parameters:
            #
            #    dir1 dir2 dir3 ... file_name_to_diff
    
            # the file is the last parameter given
            file_to_diff="${@:$#:1}"
    
            # iterate over all parameters and construct
            # the full_path=dir+file_to_diff
            for i in $(seq 0 $(( $# - 1))); do
                    j=$(( $i + 1 ))
                    full_paths[$i]="${@:$j:1}/$file_to_diff"
            done

            # delete last element, since that's the file
            # itself:
            unset 'full_paths[-1]'
    
            konsole --workdir `pwd` -e vimdiff "${full_paths[@]}"
    else
            konsole --workdir `pwd` -e vimdiff "$1" "$2"
    fi

Alternatively the patch could be changed to do the path construction
inside dirdiff before calling the external program. I'll leave that
as a challenge ;-)

Thanks,
*t

-- System Information:
Debian Release: 9.5
  APT prefers stable
  APT policy: (990, 'stable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 4.9.0-8-amd64 (SMP w/8 CPU cores)
Locale: LANG=de_CH.utf8, LC_CTYPE=de_CH.utf8 (charmap=UTF-8), LANGUAGE=de_CH:de 
(charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages dirdiff depends on:
ii  libc6      2.24-11+deb9u3
ii  libtcl8.6  8.6.6+dfsg-1+b1
ii  tk8.6      8.6.6-1+b1

dirdiff recommends no packages.

dirdiff suggests no packages.

-- no debconf information
--- /usr/bin/dirdiff    2018-04-29 09:19:39.000000000 +0200
+++ /tmp/dirdiff        2018-10-05 20:55:45.192961740 +0200
@@ -2517,6 +2517,7 @@
 }
 
 proc diffn {dirlist f {orig 1}} {
+    global diffprogram
     global diffing diffdirs difffile difffds diffrel allf
     global difflnos diffndirs diffstate difflnum nextdiffhdr diffhdr
     global diffiflag diffwflag diffbflag diffdflag incline
@@ -2547,6 +2548,12 @@
     catch {unset incline}
 
     set diffopts "-u $diffiflag $diffwflag $diffbflag $diffdflag"
+
+    if { [llength $diffprogram] > 0} {
+       exec $diffprogram {*}$dirlist $f &
+       return
+    }
+
     set d [lindex $dirlist 0]
     set p [joinname $d $f]
     set diffrel(0) 0

Reply via email to