Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I exclude certain files from a svn diff?

Tags:

diff

svn

I'm using svn diff -c 789 to show the changes made in revision 789 of our software, but it's showing a lot of files I don't care about, in particular test files. How can I exclude certain files from the diff, for example all files which match the pattern *Test.java?

I'm using Cygwin on Windows, if that's important.

like image 720
MikeFHay Avatar asked May 07 '13 08:05

MikeFHay


2 Answers

By the way, remember that the svn diff commands works as others commands following the in Unix modular philosophy where each command has a standard input and ouput. You can genare your own customize script for listing files you want to include redirect the output of that script to the svn diff commands via the use of pipes and then redirect your output of diff to the desired file you want to create. Just to be more clear : follow this example

svn diff `cat change_list.txt` > patch.diff

in change_list.txt the are the files you want to include in the diff separated by space. For example, the content of the file could be this :

"domain/model/entity.java"

"web_app/controllers/controller.java"

So following this approach, the only dificult of your problem is reduced to implement a script that like Adam generously wrote above.

Hope it helps!

Vic.

like image 31
Victor Avatar answered Oct 05 '22 06:10

Victor


As svn diff does not allow to exclude specific files from the output, below is a BASH script that can be used to achieve that.

It takes two arguments:

  • file with an svn diff output
  • pattern of the files to be excluded (e.g. test/*)

and prints the content of the file without the changes from the files matching pattern.

#!/bin/bash

test $# -ne 2 && echo "Usage: $0 svn_diff_file exclude_pattern" && exit 1

ignore=0
while IFS= read -r line; do
    echo $line | grep -q -e "^Index: " && ignore=0
    echo $line | grep -e "^Index: " | grep -q -e "^Index: $2" && ignore=1
    test $ignore -eq 0 && echo "$line"
done < $1

Update

I just came across a tool that does this job: filterdiff. It's usage is very similar to the above script:

filterdiff svn_diff_file -x exclude_pattern

like image 129
Adam Siemion Avatar answered Oct 05 '22 06:10

Adam Siemion