I have two revisions r1 and r2. r1 added different lines to different files(and did other modifications too). r2 deleted some of the lines introduced by r1 from some of the files. Is there any way to get a list of those files from which r2 deleted lines that were introduced by r1?
Yes.
svn diff
gives you a unified diff between two revisions. Using the --summarize
flag lists just the file names.
So, svn diff -rR1:R2 --summarize
will give a list of all affected files between revisions R1
and R2
.
Now, for each of those files, you can use grep to get a list of deleted lines via searching against "^-"
(ie: lines that begin with the -
character).
The overall command would be:
R1="your first revision value"
R2="your second revision value"
for i in $(svn diff -r${R1}:${R2} --summarize | cut -c9-)
do
echo "Listing lines deleted between revisions ${R1} and ${R2} in file:${i}"
echo "===================================================================="
svn diff -r${R1}:${R2} ${i} | grep -in "^-"
echo "===================================================================="
done
The cut
command is used to remove the leading status flags and spaces from the output of svn -diff --summarize
, while the grep command is searching for lines marked as deleted between the revisions. The -n
argument to grep also tells it to print the line number for the affected change in the diff. This is not the same as the line number in the original file, but it's in the same neighborhood.