CVS Diffing Scripts
If you use UNIX as the development platform and you use CVS for version controlling of your source code, you might be interested in reading on...
Diffing is a very common action that developers do. Many times when one does not know the exact revision number of the files that s/he wants to diff, then s/he first needs to manually find the revision numbers and then do the diff. This become unproductive or time consuming, when has to applied on several files in the repository.
Here are few shell scripts that I have developed to access the changes done in a file in CVS. After identifying what version to diff, they invoke “tkdiff” to present the file differences (if you use some other diffing tool then you can easily edit the scripts to invoke your favourite tool accordingly). Following are the description of those scripts -- it depicts the scripts and its usage:
tkndiff
#!/bin/csh -f # Brief : Generate diff between local (modified) and CVS versions of files. # Author : Copyright (C) 2009 Developer's Spicery # set findModifiedFiles=1 set filenames="" while ( ${#argv} > 0 ) set findModifiedFiles=0 set filenames="$filenames $argv[1]" shift end if ($findModifiedFiles == 1) then set filenames=`cvs -n update | & egrep '^M ' | cut -f2 -d \ ` endif foreach file ($filenames) `echo tkdiff $file` end |
tkndiff myfile.c -> It shows the diff between local version and CVS head version of myfile.c.
tkndiff -> It shows the diff of all the modified files.
tkndiff myfile1.c myfile2.c myfile3.c -> It shows the diff between local version of CVS head version of respective files.
tkvdiff
#!/bin/csh -f # Brief : Generate diff between two latest versions of files in CVS. # -vX => diff X but last revision with X+1 but last revision. # Author : Copyright (C) 2009 Developer's Spicery # set offset=0 set filenames="" while ( ${#argv} > 0 ) switch ($argv[1]) case -v[0-9]* : set offset=`echo $1 | sed 's/-v//'` breaksw case -* : echo Unknown option : $argv[1] exit 1 default : set filenames="$filenames $1" breaksw endsw shift end set offset=`expr $offset + 0` if ($offset < 1) then if ($offset != 0) then echo "Invalid revision number" exit 1 endif set offset=0 endif foreach file ($filenames) set ver=`cvs status $file | egrep "Repository revision" | cut -f2 | cut -f2 -d . ` set rev1=`expr $ver - $offset` set rev2=`expr $rev1 - 1` if ($rev2 < 1) then echo "No nothing about revision 1.$rev2 of $file." else `echo tkdiff -r1.$rev2 -r1.$rev1 $file` endif end |
tkvdiff myfile.c -> It shows the diff between last and second last versions of myfile.c file in CVS.
tkvdiff -vN myfile.c -> where N is a integer number. It shows the diff between Nth version and (N-1)th version of myfile.c file in CVS.
This can also take multiple filenames as input.
tkbdiff
#!/bin/csh -f # Brief : Generate diff between two very first version of file in the branch # with the current version in the branch. # - That means, show all the chnages done so far in the branch. # Author : Copyright (C) 2009 Developer's Spicery # set offset=0 set filenames="" while ( ${#argv} > 0 ) switch ($argv[1]) case -* : echo Unknown option : $argv[1] exit 1 default : set filenames="$filenames $1" breaksw endsw shift end if ($filenames == "") then set filenames=`cvs status | egrep "File:" | egrep "Status:" | cut -f2 -d " "` endif foreach file ($filenames) set ver=`cvs status $file | egrep "Repository revision" | cut -f2 ` set rev1=`expr $ver` set ver = `echo $rev1 | cut -f2 -d .` set rev2=`expr $ver` if ($rev1 == 1.$rev2) then echo "File $file revision $rev1 is not changed in the branch." else echo "Diffing file $file revisions 1.$rev2 and $rev1." echo `tkdiff -r1.$rev2 -r$rev1 $file` endif end |
tkbdiff myfile.c -> It shows the diff between very first version and the current version of myfile.c file in CVS branch.
tkbdiff -> It shows the diff for all files modified after CVS branching.
This can also take multiple filenames as input.
This script is intended to work with CVS branch only (not with main-trunk in CVS).
tkldiff
#! /bin/csh -f # Brief: tkldiff "search line" file(s) # Author : Copyright (C) 2009 Developer's Spicery # set filenames="" set message = $1 shift while ( ${#argv} > 0 ) switch ($argv[1]) case -* : echo Unknown option : $argv[1] exit 1 default : set filenames="$filenames $1" breaksw endsw shift end if ($filenames == "") then set filenames=`cvs status | egrep "File:" | egrep "Status:" | cut -f2 -d " "` endif foreach xxx ($filenames) set rr = `cvs log $xxx |\ awk -v search="${message}" '\ BEGIN { rev_num = 1} \ $0 ~ search { if (keepit == 0) keepit = rev_num } \ $1 ~ "revision" { rev[rev_num] = $2; rev_num = rev_num+1; } \ END { if (keepit > 0) { print "-r " rev[keepit] " -r " rev[keepit-1] }} \ '` if ("$rr" != "") then echo `tkdiff $rr $xxx` endif end |
tkldiff "my log message" myfile.c -> It shows the diff between two versions of myfile.c file that were checked-in CVS with given sub-string ("my log message") in log message.
This can also take multiple filenames as input.
CVS Diffing Scripts
Reviewed by Sourabh Soni
on
Thursday, October 22, 2009
Rating:
No comments