You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by kb...@gte.net on 2002/12/09 09:43:47 UTC

graphical diff'ing script

Here's a quick script I put together to help with graphical diff'ing.  It 
doesn't handle "-r" kind of stuff, but I rarely need that; and it probably 
wouldn't be that hard to add.  I'll toss it to the list in case others may 
find it useful.  I call it "svndiff"; it's a shell script you should put 
somewhere in your PATH.  Just put a filename after the command and enjoy. :-)

A big thanks to Vladimir for the "svn cat" code!

Kevin

-----

#!/bin/bash
# also works with ksh
#
# usage:  svndiff file
# graphically show the diff between our file and that last thing
#   in the repository
# uses the program in the env.var. $DIFF, or "xxdiff" by default
# tested with:  xxdiff, mgdiff, tkdiff

###################################### start configurable stuff
# default graphical diff program
dif=${DIFF:-xxdiff}
# default geometry, works for the average X program
geometry="-geometry 1000x400+0+0"
# handle tkdiff not liking geometries
[[ $dif = tkdiff ]] && geometry=""
###################################### end configurable stuff

if [[ ! -d .svn ]]
then
         echo ERROR:  You are not in a SVN working copy directory.
         exit 1
fi
file=$1
last=${file}_LasT

trap "rm -f $last" 2 3 15

svn cat $file > $last 2>/dev/null
${DIFF:-xxdiff} $geometry $last $file
rm -f $last

#end


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: graphical diff'ing script

Posted by Ben Collins-Sussman <su...@collab.net>.
kbrannen@gte.net writes:

>  I call it "svndiff"

Heh, that's also the name of the encoding for our vdelta (binary diff)
data.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: graphical diff'ing script

Posted by Daniele Nicolodi <da...@grinta.net>.
On Tue, Dec 10, 2002 at 11:36:19AM -0600, kbrannen@gte.net wrote:

> Good thought, but it unfortunately doesn't work for everyone.  Some 
> programs can take STDIN as an arg, others can't, so an actual file is 
> required. Putting it in the current WD seems as good a place as any, 
> because if there was an error, it should be pretty obvious what that file 
> is.  If you're concerned about "hitting a real file", change the "_LasT" so 
> something weirder. :-)

What about my pach (that i have send to you personally) about use mktemp
shell command ? I don't know if it is installed everywere but i have it
in my debian box.

Ciao
-- 
Daniele
		    --- http://www.grinta.net ---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: graphical diff'ing script

Posted by kb...@gte.net.
Ulrich Drepper wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> kbrannen@gte.net wrote:
...
>>BTW, the "<(svn cat $file 2>/dev/null)" construct does NOT work for me
>>in either bash or ksh.  Bash says:  "Error: not an ordinary file or a
>>directory",
> 
> 
> I don't know what kind of version of bash you're using.  It definitely
> works in general.  I use it every day.  Does
> 
>   cat <(cat /etc/issue)
> 
> work for you (assuming you have an /etc/issue file)?  If not, you 're
> either using your shell as /bin/sh it's broken or very old.

A script of:

#!/bin/bash
cat <(cat /etc/issue)

seems to work.  Maybe I had a typo before?  OTOH, you are correct that if I 
change that to /bin/sh it does fail.  Asking for version gives me:

GNU bash, version 2.05.0(1)-release (i386-suse-linux)

I wouldn't know if it's old or not.  As I said before, I live in a ksh world, 
but do try to write to bash standards too as a help to others.  I'll try your 
suggestion again and see what happens.

It still fails.  If I echo the command out, I see:

xxdiff -geometry 1000x400+0+0 /dev/fd/63 README

so there's the special file you were talking about.  I'll interpret this to 
mean that xxdiff can't handle it.  In fact, with some further testing, all 3 
of my graphical diffs fail; but regular "diff" can handle it.  Do you have any 
idea why?  (Maybe because the graphical programs don't read the file 
themselves but create a diff child process which then doesn't have access to 
the special file?)

Maybe Daniele's idea of doing:

last=$(mktemp "/tmp/$file.XXXXXX") || exit 1

to create a real file is the best all-around answer after all.

Kevin


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: graphical diff'ing script

Posted by Ulrich Drepper <dr...@redhat.com>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

kbrannen@gte.net wrote:

>> $dif $geometry <(svn cat $file 2>/dev/null) $file
>>
>>
>> No need to create a temporary file which has to be destroyed.  And
>> especially no need to create it in the working directory.  Just imagine
>> you want to figure out what changes a coworker of yours changed.
> 
> 
> Good thought, but it unfortunately doesn't work for everyone.  Some
> programs can take STDIN as an arg, others can't, so an actual file is
> required.

This is an actual file.  Try it.  What gets passed to the diff program
is on Linux someting like /dev/fd/62


> Putting it in the current WD seems as good a place as any,
> because if there was an error, it should be pretty obvious what that
> file is.  If you're concerned about "hitting a real file", change the
> "_LasT" so something weirder. :-)

This is not what I'm concerned about.  Read my comment again.  The
script requires to be in the source directory.  Now assume it is
somebody else's source directoy and you have no write access (but read
access).  You should be allowed to use diff.


> BTW, the "<(svn cat $file 2>/dev/null)" construct does NOT work for me
> in either bash or ksh.  Bash says:  "Error: not an ordinary file or a
> directory",

I don't know what kind of version of bash you're using.  It definitely
works in general.  I use it every day.  Does

  cat <(cat /etc/issue)

work for you (assuming you have an /etc/issue file)?  If not, you 're
either using your shell as /bin/sh it's broken or very old.



> Now this does work for some programs:
> 
> svn cat $file | $dif $geometry $file -

You can do this.  To be more portable, you should use /dev/stdin (that's
the POSIX mandated name many utilities have to know and on Linux it just
magically works).

- -- 
- --------------.                        ,-.            444 Castro Street
Ulrich Drepper \    ,-----------------'   \ Mountain View, CA 94041 USA
Red Hat         `--' drepper at redhat.com `---------------------------
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE99rdA2ijCOnn/RHQRAlkDAJ9/iXOK+osGPTQWktU66AtAKnlxVQCfTFyy
TQCmJUa2B8FZT0HZpQVcANY=
=qE7u
-----END PGP SIGNATURE-----


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: graphical diff'ing script

Posted by kb...@gte.net.
Ulrich Drepper wrote:
> Stepping in out of the blue, but I cannot resist seeing such a
> potentially important part not being writtencorrectly:
> 
> -----BEGIN PGP SIGNED MESSAGE-----
...
>>>>[[ $dif = tkdiff ]] && geometry=""
>>>
>>[[ $dif = meld ]] && geometry=""
> 
> 
> Why the [[ ]] variant instead of plain [ ]?  You're not using the
> special features of this code.  Besides, you want to write it like this:
> 
> case "${dif##*/}" in
>   tkdiff|meld) geometry="" ;;
>   *)           geometry="-geometry 1000x400+0+0" ;;
> esac

Because I come from the ksh world, and [[ ]] is the norm there? :-)  OTOH, the 
case construct is a good thing; especially if more programs are found that 
don't take X Window options (because they aren't X based).

...
> 
> 
> Replace the following lines
> 
> 
>>>>last=${file}_LasT
>>>>
>>>>trap "rm -f $last" 2 3 15
>>>>
>>>>svn cat $file > $last 2>/dev/null
>>>>${DIFF:-xxdiff} $geometry $last $file
>>>
>>$dif $geometry $last $file
>>
>>
>>>>rm -f $last
>>>
> 
> with
> 
> $dif $geometry <(svn cat $file 2>/dev/null) $file
> 
> 
> No need to create a temporary file which has to be destroyed.  And
> especially no need to create it in the working directory.  Just imagine
> you want to figure out what changes a coworker of yours changed.

Good thought, but it unfortunately doesn't work for everyone.  Some programs 
can take STDIN as an arg, others can't, so an actual file is required. 
Putting it in the current WD seems as good a place as any, because if there 
was an error, it should be pretty obvious what that file is.  If you're 
concerned about "hitting a real file", change the "_LasT" so something 
weirder. :-)

BTW, the "<(svn cat $file 2>/dev/null)" construct does NOT work for me in 
either bash or ksh.  Bash says:  "Error: not an ordinary file or a directory", 
and ksh says:  "/home/kevin/bin/scripts/svndiff[36]: syntax error: `(' 
unexpected".  Now this does work for some programs:

svn cat $file | $dif $geometry $file -

but as I said, only some (e.g. mgdiff and tkdiff both fail with this as they 
can't take a file from STDIN).

Kevin


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: graphical diff'ing script

Posted by Ulrich Drepper <dr...@redhat.com>.
Stepping in out of the blue, but I cannot resist seeing such a
potentially important part not being writtencorrectly:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


>>> dif=${DIFF:-xxdiff}
>>> # default geometry, works for the average X program
>>> geometry="-geometry 1000x400+0+0"
>>> # handle tkdiff not liking geometries
>>> [[ $dif = tkdiff ]] && geometry=""
> 
> [[ $dif = meld ]] && geometry=""

Why the [[ ]] variant instead of plain [ ]?  You're not using the
special features of this code.  Besides, you want to write it like this:

case "${dif##*/}" in
  tkdiff|meld) geometry="" ;;
  *)           geometry="-geometry 1000x400+0+0" ;;
esac


Important here is the readability of the exception handling and
comparing with the basename of $dif.  The programs might be specified
with an absolute path.


> 
>>> ###################################### end configurable stuff
>>>
>>> if [[ ! -d .svn ]]
>>> then
>>>         echo ERROR:  You are not in a SVN working copy directory.
>>>         exit 1
>>> fi
>>> file=$1


Replace the following lines

>>> last=${file}_LasT
>>>
>>> trap "rm -f $last" 2 3 15
>>>
>>> svn cat $file > $last 2>/dev/null
>>> ${DIFF:-xxdiff} $geometry $last $file
> 
> $dif $geometry $last $file
> 
>>> rm -f $last

with

$dif $geometry <(svn cat $file 2>/dev/null) $file


No need to create a temporary file which has to be destroyed.  And
especially no need to create it in the working directory.  Just imagine
you want to figure out what changes a coworker of yours changed.

- -- 
- --------------.                        ,-.            444 Castro Street
Ulrich Drepper \    ,-----------------'   \ Mountain View, CA 94041 USA
Red Hat         `--' drepper at redhat.com `---------------------------
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE99YJz2ijCOnn/RHQRApVOAJ9we94n1LGKq3bjCyp3eZTX7/Pe6QCfamZs
g+9OI6RlMWDLT4yC/jS4p1Y=
=GvQm
-----END PGP SIGNATURE-----


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: graphical diff'ing script

Posted by kb...@gte.net.
Timothee Besset wrote:
> Awesome!
> 
> This doesn't quite work with xxdiff here though.
> $ svndiff neo/sys/linux/ChangeLog 
> xxdiff: invalid option -- g
> xxdiff (cmdline.cpp:616): 
> Argument error.
> Use 'xxdiff --help' for more information.
> 
> (regular xxdiff on a Debian Sid box)

Most interesting.  Unfortunately, I have a typo in the "diff" call.  ARGH!!! 
Maybe that affected you.  See below...  (Thanks Daniele for the catch!)

> 
> But .. I got it working with meld (needed to remove the -geometry part as
> well) http://meld.sf.net/

OK, 1 extra line below for you.  I've never heard of meld, I'll have to check 
it out.

> 
> Again, great work..

Thanks! :-)

> 
> TTimo
> 
> On Mon, 09 Dec 2002 03:43:47 -0600
> kbrannen@gte.net wrote:

>>-----
>>
>>#!/bin/bash
>># also works with ksh
>>#
>># usage:  svndiff file
>># graphically show the diff between our file and that last thing
>>#   in the repository
>># uses the program in the env.var. $DIFF, or "xxdiff" by default
>># tested with:  xxdiff, mgdiff, tkdiff
>>
>>###################################### start configurable stuff
>># default graphical diff program
>>dif=${DIFF:-xxdiff}
>># default geometry, works for the average X program
>>geometry="-geometry 1000x400+0+0"
>># handle tkdiff not liking geometries
>>[[ $dif = tkdiff ]] && geometry=""
[[ $dif = meld ]] && geometry=""
>>###################################### end configurable stuff
>>
>>if [[ ! -d .svn ]]
>>then
>>         echo ERROR:  You are not in a SVN working copy directory.
>>         exit 1
>>fi
>>file=$1
>>last=${file}_LasT
>>
>>trap "rm -f $last" 2 3 15
>>
>>svn cat $file > $last 2>/dev/null
>>${DIFF:-xxdiff} $geometry $last $file
$dif $geometry $last $file
>>rm -f $last
>>
>>#end


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: graphical diff'ing script

Posted by Timothee Besset <tt...@idsoftware.com>.
Awesome!

This doesn't quite work with xxdiff here though.
$ svndiff neo/sys/linux/ChangeLog 
xxdiff: invalid option -- g
xxdiff (cmdline.cpp:616): 
Argument error.
Use 'xxdiff --help' for more information.

(regular xxdiff on a Debian Sid box)

But .. I got it working with meld (needed to remove the -geometry part as
well) http://meld.sf.net/

Again, great work..

TTimo

On Mon, 09 Dec 2002 03:43:47 -0600
kbrannen@gte.net wrote:

> Here's a quick script I put together to help with graphical diff'ing.  It 
> doesn't handle "-r" kind of stuff, but I rarely need that; and it probably 
> wouldn't be that hard to add.  I'll toss it to the list in case others may 
> find it useful.  I call it "svndiff"; it's a shell script you should put 
> somewhere in your PATH.  Just put a filename after the command and enjoy. :-)
> 
> A big thanks to Vladimir for the "svn cat" code!
> 
> Kevin
> 
> -----
> 
> #!/bin/bash
> # also works with ksh
> #
> # usage:  svndiff file
> # graphically show the diff between our file and that last thing
> #   in the repository
> # uses the program in the env.var. $DIFF, or "xxdiff" by default
> # tested with:  xxdiff, mgdiff, tkdiff
> 
> ###################################### start configurable stuff
> # default graphical diff program
> dif=${DIFF:-xxdiff}
> # default geometry, works for the average X program
> geometry="-geometry 1000x400+0+0"
> # handle tkdiff not liking geometries
> [[ $dif = tkdiff ]] && geometry=""
> ###################################### end configurable stuff
> 
> if [[ ! -d .svn ]]
> then
>          echo ERROR:  You are not in a SVN working copy directory.
>          exit 1
> fi
> file=$1
> last=${file}_LasT
> 
> trap "rm -f $last" 2 3 15
> 
> svn cat $file > $last 2>/dev/null
> ${DIFF:-xxdiff} $geometry $last $file
> rm -f $last
> 
> #end
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
> For additional commands, e-mail: dev-help@subversion.tigris.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org