[suggest] colordiff added to repo

Michael Mansour mic at npgx.com.au
Sat Nov 17 00:55:30 CET 2007


Hi Dag,

> On Sat, 17 Nov 2007, Michael Mansour wrote:
> 
> > Could colordiff:
> >
> > http://colordiff.sourceforge.net/
> >
> > please be added to the repo? as you have cdiff (which I can't get to work at
> > all) and colordiff pulled from Fedora (I use SL4.5 so need the FC5 RPM):
> >
> > http://download.fedora.redhat.com/pub/fedora/linux/extras/5/i386/
> >
> > works fine and contains cdiff already:
> 
> cdiff colors the output from diff, so it is not a diff tool, it 
> colors the output.
> 
> 	diff -u filea.txt fileb.txt | cdiff

I tried the above and it works fine (the output is actually easier to follow
than colordiff). 

All colordiff eseentially does is give exactly the same diff output but in
colour, while cdiff does some re-ordering with colours.

BTW, I read the man page several times to try and figure out how to use cdiff,
it can really use an "EXAMPLES" section in the man page.

> > # rpm -ql colordiff
> > /etc/colordiffrc
> > /usr/bin/cdiff
> > /usr/bin/colordiff
> > /usr/share/doc/colordiff-1.0.5
> > /usr/share/doc/colordiff-1.0.5/BUGS
> > /usr/share/doc/colordiff-1.0.5/CHANGES
> > /usr/share/doc/colordiff-1.0.5/COPYING
> > /usr/share/doc/colordiff-1.0.5/README
> > /usr/share/doc/colordiff-1.0.5/colordiffrc-darkbg
> > /usr/share/doc/colordiff-1.0.5/colordiffrc-lightbg
> > /usr/share/man/man1/colordiff.1.gz
> >
> > Fedora 8 has colordiff as part of it's package collection now, but this is so
> > useful it would be ideal to have it for el3, el4, el5.
> >
> > Much appreciated.
> 
> I think so too that it would be useful, but given the fact that cdiff
> already is packaged in package 'cdiff' and I don't want to risk any future
> conflicts on this one, I prefer not to package it.

You're right, since trying to install colordiff over cdiff gives:

# rpm -Uvh colordiff-1.0.5-1.noarch.rpm
warning: colordiff-1.0.5-1.noarch.rpm: V3 DSA signature: NOKEY, key ID 1ac70ce6
Preparing...                ########################################### [100%]
        file /usr/bin/cdiff from install of colordiff-1.0.5-1 conflicts with
file from package cdiff-1.5-1.el4.rf

But it would also make sense that if colordiff contains both cdiff and
colordiff (and since Fedora 8 has colordiff in place, which would cause
problems for people that try and grab cdiff from rpmforge), that you could
deprecate the cdiff package from your repo.

> Can you make a comparison of cdiff from the cdiff package and this 
> new one ? It seems to be configurable (and probably has more options 
> too.

The header of the cdiff contained in the colordiff RPM contains:

# Copyright (C) 2003-2004 Ville Skyttä <ville.skytta at iki.fi>
# Based on cdiff version 1.4 by eivind at FreeBSD.org

So the colordiff author has taken cdiff and updated it

I have successfully used:

 	diff -u filea.txt fileb.txt | cdiff

on both the original cdiff and "colordiff's cdiff" and they both produce the
same output.

The content of each follows.

cdiff from the cdiff RPM in your repo:

# cat cdiff.first
#!/bin/sh
if [ "$1" = "-m" ]; then
        shift;
        CODES="4:7:1:1"
else
        if [ "$CDIFFCOLORS" != "" ]; then
                CODES=$CDIFFCOLORS
        else
                CODES="1:34:31:35"
        fi
fi
(if [ "$1" != "" ]; then
    while [ "$1" != "" ]; do
        case $1 in
        *.bz2)
            cat="bzcat"
            ;;
        *)
            cat="zcat -f"
            ;;
        esac
        case $1 in
        http:*|https:*|ftp:*|file:*)
            if [ -z "$CDIFF_FETCH" ]; then
                # Wget doesn't do file:// URLs... :(
                if which curl >/dev/null 2>&1; then
                    CDIFF_FETCH="curl -s"
                elif which lwp-request >/dev/null 2>&1; then
                    CDIFF_FETCH="lwp-request -m GET"
                fi
                if [ -z "$CDIFF_FETCH" ]; then
                    echo "Error: no program to fetch from URLs found."
                    exit 1
                fi
            fi
            $CDIFF_FETCH $1 | $cat
            ;;
        *)
            $cat $1
            ;;
        esac
        shift;
    done
else
        cat
fi) | perl -p -mconstant=CODES,${CODES} -e '
no warnings qw(utf8);
($at, $m, $p, $c) = split /:/, CODES;
while (s/\t/" " x (8 - ((length($`)-1) % 8))/e) {}
s/^(\+.*)$/\033[${p}m$1\033[0m/o;
s/^(-.*)$/\033[${m}m$1\033[0m/o
        if !s/^(--- \d+,\d+ ----.*)$/\033[1m$1\033[0m/o;
s/^(\*\*\* \d+,\d+ *\*\*\*.*)$/\033[1m$1\033[0m/o;
s/^(\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*)$/\033[1m$1\033[0m/o;
s/^(!.*)$/\033[${c}m$1\033[0m/o;
s/^(@@.*$)/\033[${at}m$1\033[0m/o;
if (/^1.(\d+)(\s+\(\w+\s+\d{2}-\w{3}-\d{2}\):\s)(.*)/) {
        $lastcol = $lastcol || 0;
        $lastcol++ if defined($lastrev) && $lastrev != $1;
        $lastrev = $1;
        $lastcol %= 6;
        $_ = "\033[3" . ($lastcol + 1) . "m1.$1$2\033[0m$3\n";
}
' | less -R

cdiff from the colordiff RPM (from FC5 - Fedora 8 may have a more updated one):

# cat cdiff
#!/bin/sh

# cdiff.sh - Convenience wrapper for colordiff
#
# Copyright (C) 2003-2004 Ville Skyttä <ville.skytta at iki.fi>
# Based on cdiff version 1.4 by eivind at FreeBSD.org
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

(if [ "$1" != "" ]; then
    while [ "$1" != "" ]; do
        file=`echo "$1" | perl -pe 's|^file:/+|/|i'`
        case "$file" in
        *.bz2)
            cat="bzcat"
            ;;
        *)
            cat="zcat -f"
            ;;
        esac
        case `echo "$file" | perl -ne 'print lc $_'` in
        http:*|https:*|ftp:*)
            if [ -z "$CDIFF_FETCH" ]; then
                if which wget >/dev/null 2>&1; then
                    CDIFF_FETCH="wget -qO -"
                elif which curl >/dev/null 2>&1; then
                    CDIFF_FETCH="curl -s"
                elif which lwp-request >/dev/null 2>&1; then
                    CDIFF_FETCH="lwp-request -m GET"
                elif which lynx >/dev/null 2>&1; then
                    CDIFF_FETCH="lynx -source"
                elif which elinks >/dev/null 2>&1; then
                    CDIFF_FETCH="elinks -source"
                fi
                if [ -z "$CDIFF_FETCH" ]; then
                    echo "Error: no program to fetch from URLs found."
                    exit 1
                fi
            fi
            $CDIFF_FETCH "$file" | $cat
            ;;
        *)
            $cat "$file"
            ;;
        esac
        shift;
    done
else
    cat
fi) | colordiff | less -R

I also like the fact that when using the colordiff RPM, I have a choice to use
either cdiff or colordiff.

Regards,

Michael.

> -- 
> --   dag wieers,  dag at wieers.com,  http://dag.wieers.com/   --
> [Any errors in spelling, tact or fact are transmission errors]
------- End of Original Message -------




More information about the users mailing list