开发者

script to generate diffs between consecutive commits, and writing them to file

In order to view changes or diffs between commits, i use the following from the command line:

svn diff -r 3000:3025 > daychanges.diff

I want to modify the command so that it generates diffs between s开发者_JAVA技巧uccessive commits, concatenates them and outputs to file, something like

svn diff -r 3000:3001 > daychanges.diff
svn diff -r 3001:3002 >> daychanges.diff
svn diff -r 3002:3003 >> daychanges.diff
...
svn diff -r 3019:3020 >> daychanges.diff

how can i write such a script?


You can write for loops in bash:

http://www.cyberciti.biz/tips/how-to-generating-print-range-sequence-of-numbers.html

Given that, it shouldn't be all that difficult to write a script that calls svn diff over a range of commits.

In a single line command, that could be run from the CLI:

for ((start=3000,finish=3001; finish<=3025; start++,finish++)); do svn diff -r $start:$finish; done > out.file

or if you prefer, the shorter version,

for ((i=3000; i<3025; i++)); do svn diff -r $i:$(($i + 1)); done > out.file

In a multi-line script:

#!/bin/bash
$begin=$1
$end=$2
$outfile=$3

for ((start=$begin,finish=$begin+1; finish <= $end; start++,finish++))
do
    svn diff -r $start:$finish
done > $outfile

(Omit the > $outfile if you just want to manually direct the output of the script.)


Should be something like:

diffs.sh:

#!/bin/bash
first=$(($1 + 1))
last=${2}
for a in `seq $first $last`; do
    svn diff -r $(($a - 1)):$a
done > daychanges.diff

then:

./diffs.sh 3000 3020


This script will parse the 'svn log' output for the commit numbers and diff the whole shebang (pardon the pun).. if you want to limit the commit range supply that in one argument eg, "-r88833:HEAD" ... no spaces:

#!/bin/bash
unset last;
for r in `svn log $1|grep '^r'|awk '{print$1}'|sed -e 's/r//g'|sort`;do 
    if [ ! -v last ]; then 
        last=$r;
        continue; 
    fi;
    echo ------------------------;
    echo diff  $last:$r ; 
    echo ------------------------; 
    svn diff -r$last:$r;last=$r;
done>diffs
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜