May 2, 2013

Bash script to get a diff with all the changes from the provided SVN branch

Despite there are numerous user friendly and feature-rich tools for doing code reviews, Crucible being the first one that comes to my mind, when I have to focus solely on the changes I personally prefer to resort to old-school vim with just syntax highlighting.

If you have the same preference, below is a short bash script that might be useful to you, given an SVN branch it will output all the changes from this branch.


#!/bin/bash
test $# -ne 1 && echo "Usage: $0 SVN_URL" && exit 1

svn="$1"
log=`mktemp svn_log.XXXXX`

svn log --stop-on-copy "$svn" > $log
first="`grep '^r[0-9]* | .* | .* |' $log | cut -c2- | cut -d\  -f1 | head -1`"
last="`grep '^r[0-9]* | .* | .* |' $log | cut -c2- | cut -d\  -f1 | tail -1`"

rm $log

svn diff -x "-w --ignore-eol-style" -r "${first}:${last}" $svn

So if you run this script against e.g. https://svn.apache.org/repos/asf/wicket/branches/wicket-1.5.0 you will get:

Index: wicket-guice/pom.xml
===================================================================
--- wicket-guice/pom.xml (revision 1164579)
+++ wicket-guice/pom.xml (revision 1164571)
@@ -23,7 +23,7 @@
  <parent>
   <groupId>org.apache.wicket</groupId>
   <artifactId>wicket-parent</artifactId>
-  <version>1.5.0</version>
+  <version>1.5-RC7</version>
   <relativePath>../pom.xml</relativePath>
  </parent>

Index: wicket-datetime/pom.xml
===================================================================
--- wicket-datetime/pom.xml (revision 1164579)
+++ wicket-datetime/pom.xml (revision 1164571)
@@ -21,7 +21,7 @@
...

No comments:

Post a Comment