How to export modified files between two versions of SVN

How to export modified files to SVN that have changed between two versions. I need a solution either through the command line, or using any scripts (with the correct folder structure). Also, I need a windows based solution.

eg. sth like:

export {svn diff --summarize -r 50:HEAD} 

I want a directory tree with a copy of files that have been changed in any version from 50 to

+6
source share
5 answers

As far as I know, svn does not provide such a function. But you can write a simple C # program using SharpSVN . Here is an example you can use. In this example, I get the entire modified file from version 100 to 200.

 using SharpSvn; using System.IO; using System.Collections.ObjectModel; using Microsoft.VisualBasic; namespace SvnDiffExporter { class Program { static void Main(string[] args) { SvnClient client = new SvnClient(); SvnRevisionRange range = new SvnRevisionRange(100, 200); MemoryStream result = new MemoryStream(); Collection<SvnLogEventArgs> items; SvnLogArgs logargs = new SvnLogArgs(range); client.GetLog(@"e:\Artifacts", logargs, out items); int i = 0; string [] path = new string[255]; foreach (SvnLogEventArgs ar in items) { foreach (SvnChangeItem changeitem in ar.ChangedPaths) { if (changeitem.Action != SvnChangeAction.Delete) { path[i] = changeitem.Path; i++; } } } string localpath = @"c:\data"; foreach (string str in path) client.Export(str, localpath); } } } 
+10
source

Here is a great step-by-step tutorial that does this with TortoiseSVN Version Comparison and Export Selection in ... functions:

http://www.electrictoolbox.com/tortoisesvn-exporting-changed-files/

+11
source

I created a batch file that will work to export files changed between versions.

 @echo off FOR /F "tokens=1,2" %%I IN ('svn diff --summarize -r %1') DO ( IF NOT %%I == D ( IF NOT EXIST %2\%%J\.. mkdir %2\%%J\.. svn export --depth empty -q --force %%J %2\%%J echo %2\%%J ) ) 

To use it, you simply specify the range of revisions or revisions on the command line and the destination for the exported files.

 C:\YourRepository>svnexport.bat 1:10 C:\Export 
+4
source

Here is another option written in a bash script:

 #!/bin/bash ############################## # settings and inicilization # ############################## SVN_SOURCE="https://svn.example.com/trunk/" REV_PATH="/var/www/revisions/example.com/" TIME_SPENT=$(date +%s) REV=$(svn info $SVN_SOURCE | grep Revision | cut -d ' ' -f 2) PREV=0 VERBOSIVE=0 USAGE_INFO="$(basename "$0") [-r REVISION_NUM] [-i PREVIOUS_REVISION_NUM] -- make an incremental svn export where: -i previous revision (default: 0) -h show this help text -r revision to export (default: $REV) -v verbosive mode. show fetched files current settins: SVN_SOURCE: $SVN_SOURCE REV_PATH: $REV_PATH " while getopts r:i:hv option; do case "$option" in i) PREV=$OPTARG ;; h) echo "$USAGE_INFO" exit ;; r) REV=$OPTARG ;; v) VERBOSIVE=1 ;; esac done EV_PATH=$REV_PATH$REV"/" ############################## # functions # ############################## promtYesOrDie(){ while true; do read -e -p "$1 (y/n): " -i "y" yn case $yn in [Yy] ) break;; [Nn] ) echo "spent: "$((`date +%s` - $TIME_SPENT))"s" echo "bye bye" exit ;; * ) echo "Please answer (y)es or (n)o.";; esac done } doIncrementalExport(){ PREV_PATH=$REV_PATH$PREV"/" if [ -d $PREV_PATH ]; then echo "copying files from: $PREV_PATH" cp -f -r "$PREV_PATH." $EV_PATH echo "fetching added and modified files since revision $PREV..." for FILE_SRC in $(svn diff --summarize -r $PREV:$REV $SVN_SOURCE | awk '/[AM]/ {print $2}'); do FILE_PATH=$(echo $FILE_SRC | sed -e "s{$SVN_SOURCE{{"); if [ ! -d "$EV_PATH$FILE_PATH" ]; then TRG_DIR="$EV_PATH$(dirname $FILE_PATH)" mkdir -p $TRG_DIR svn export -r$REV -q --force $FILE_SRC "$EV_PATH$FILE_PATH" if [ $VERBOSIVE -eq 1 ]; then echo "$EV_PATH$FILE_PATH" fi fi done echo "removing deleted files and folders since revision $PREV ..." for FILE_SRC in $(svn diff --summarize -r $PREV:$REV $SVN_SOURCE | awk '/D/ {print $2}'); do FILE_PATH=$(echo $FILE_SRC | sed -e "s{$SVN_SOURCE{{"); rm -r "$EV_PATH$FILE_PATH" if [ $VERBOSIVE -eq 1 ]; then echo "$EV_PATH$FILE_PATH" fi done else echo "previous revision does not exist at: $PREV_PATH" exit; fi } ############################## # main function # ############################## if [ $PREV -eq 0 ]; then promtYesOrDie "Do you want to do full export instead of incremental, for revision $REV of repo: [$SVN_SOURCE]" echo "fatching source ..." if [ $VERBOSIVE -eq 1 ]; then svn export -r$REV --force $SVN_SOURCE $EV_PATH else svn export -r$REV -q --force $SVN_SOURCE $EV_PATH fi else promtYesOrDie "Do you want to do incremental export, for revision renge $PREV:$REV of repo: [$SVN_SOURCE]" doIncrementalExport fi echo "spent: "$((`date +%s` - $TIME_SPENT))"s" echo [done] 

I am using a complete script to do incremental svn export in a LAMP production environment.

+1
source

If I understand your question correctly, you are not interested in the global patch between versions. In this case, you need to export each revision to a separate directory, and then use a tool like Beyond Compare (or something like WinMerge) to identify the modified files.

But if your build directory is under version control, then you better create a patch and apply it on it.

0
source

Source: https://habr.com/ru/post/896794/


All Articles