Skip to content

Instantly share code, notes, and snippets.

@michal-m
Created February 9, 2012 16:42
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save michal-m/1780997 to your computer and use it in GitHub Desktop.
Save michal-m/1780997 to your computer and use it in GitHub Desktop.
SVN Export of files changed between two revisions

svn-rev-diff-export

svn-rev-diff-export is a handy bash snippet that allows you to export files changed between two revisions.

Usage

svn-rev-diff-export.sh -u <path> -f revFROM -t revTO -o <path>

Options

-f, --rev-from revFROM
                    First revision number to compare.
-t, --rev-to revTO  Second revision number to compare.
-u, --url <path>    URL/path to repository.
-o, --output-dir <path>
                    The path to directory where the export will be placed.
                    Default: .

Requirements

svn and awk have to be available in current $PATH

#
# Fork me on github:
# http://github.com/michal-m/svn-rev-diff-export
#
# Author:
# Michał Musiał <michal.j.musial@gmail.com>
# Copyright 2012, no rights reserved.
# Exit on errors
set -e
# Initial variable definitions
OUTPUT_DIR="."
# Parse commandline options first
while :
do
case "$1" in
-f | --rev-from)
if [ -z "$2" -o "$2" -le 0 ]; then echo "Error: --rev-from parameter not specified or invalid" >&2; exit 1; fi
REV_FROM=$2
shift 2
;;
-o | --output-dir)
if [ -z "$2" ]; then echo "Error: Output directory not specified" >&2; exit 1; fi
OUTPUT_DIR=$2
shift 2
;;
-t | --rev-to)
if [ -z "$2" -o "$2" -le 0 ]; then echo "Error: --rev-to parameter not specified or invalid" >&2; exit 1; fi
REV_TO=$2
shift 2
;;
-u | --url)
if [ -z "$2" ]; then echo "Error: SVN Repository URL/path not specified" >&2; exit 1; fi
REPO_PATH=$2
shift 2
;;
# --) # End of all options
# shift
# break;
-*)
echo "Error: Unknown option: $1" >&2
exit 1
;;
*) # No more options
break
;;
esac
done
# Checking if other required parameters are present and valid
if [ ! -d "$OUTPUT_DIR" ]; then echo "Error: Specified output is not a directory" >&2; exit 1; fi
if [ ! -w "$OUTPUT_DIR" ]; then echo "Error: Output directory is not writable" >&2; exit 1; fi
last_char=${OUTPUT_DIR:${#OUTPUT_DIR}-1:1}
if [[ $last_char != '/' ]]; then
OUTPUT_DIR=${OUTPUT_DIR}"/";
fi
for i in $(svn diff --summarize -r ${REV_FROM}:${REV_TO} $REPO_PATH | awk '{ print $2 }');
do
f=${OUTPUT_DIR}$(echo ${i#$REPO_PATH});
mkdir -p $(dirname $f);
svn export $i $f;
done
@artseld
Copy link

artseld commented Oct 1, 2015

Thank you, @michal-m.
I added changes in line 65 to skip deleted files:

svn export $i $f || echo "File $i is not found, skipped";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment