[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: Export entire changed files for zip patch

From: Scott Pederick <scott_at_solidstrategies.com.au>
Date: 2007-06-28 12:37:58 CEST

>> I'm working on a number of php projects that I want to generate a zip
>> that contains the files changed from one version to another. This
>> makes it easy to apply, especially when you only have ftp access.
>>
>> So far I've been able to generate a list of the files that have changed:
>>
>> svn diff -r PREV:HEAD --summarize | sed -e "s/^[AM].*//pi" | sort |
>> uniq > files.txt
>>
>> I then loop through the list to export the files from svn to a
>> temporary location so I can zip it up. I can export the files into
>> one directory but I'm having trouble re-creating the directory
>> structure to start with.
>
> Oh? How so? "basename" and "mkdir -p" should be your friend...
Ah ha ha. Of course! I'm spending most of my time in Windows using
compiled unix tools - all my command-line intelligence has atrophied in
the face of batch files. :)
>
> Your sed is surely wrong, though; it looks like you're asking it to
> match lines that begin with "A" or "M", delete the entire contents
> line, and print the blank line, which is surely not what you want...
>
> I'd say you probably want something more like:
>
> sed -n -E -e "s/^[AM].{6}//p"
>
> -n: don't print by default
> -E: use modern regex syntax
> -e: use the following regex
>
> (At least, those flags are accurate for my BSD sed. With GNU sed it
> may be different.)
>
> Then search for lines starting with "A" or "M", followed by any 6
> characters, delete those 7 characters, and print the rest of the line.
Much better - thanks again.
>> Before I continue to bang my head against this one, does anyone know
>> of any pre-existing scripts of the like that solve this problem? I
>> know I'm not alone in this but I can't find any solutions that help
>> with this bit. At this point I'm assuming that I'm looking for the
>> wrong thing or in the wrong direction.
>
> Not aware of any existing script, but people do ask for this
> functionality on this list with surprising regularity, so probably
> someone has already written a script.
>
> How were you planning on handling deletions, by the way?
Aside from a changleog, there's no particularly good way to handle
deletions using this method. The gain in simplicity of distribution
unfortunately loses functionality. The ultimate solution would be to use
svn itself as a distribution method but that's not an option.

Thanks again for your help - it was driving me crazy.

If anyone else wants a windows batch file to do this, the following
worked for me (with great help from sed, sort and uniq):

@ECHO OFF
SETLOCAL DISABLEDELAYEDEXPANSION

REM Location of sed, sort and uniq
SET TOOLS=d:\utils\unix\usr\local\wbin

REM SVN root
SET SVN=svn://localhost/myproject/trunk/public

REM Patch path
SET PATCH=.\temp

REM Working copy root
SET WC=d:\projects\web\myproject\public

REM Convert backslashes to double backslahes for quoted sed expression
SET WCQ=%WC:\=\\%

echo Creating changed files list
REM Remove lines without an filename extension (assumed to be directories)
REM Extract the root path from the filename
svn diff -r PREV:HEAD --summarize %WC% | %TOOLS%\sed -e "/[.]/!d" |
%TOOLS%\sed -e "s/^[AM].* %WCQ%//pi" | %TOOLS%\sort | %TOOLS%\uniq >
files.txt

echo Creating directory listing
%TOOLS%\sed -e "s,[^\\]*$,,;s,\\$,,;s,^$,.," files.txt | %TOOLS%\sort |
%TOOLS%\uniq > directories.txt

echo Clearing patch directory
IF NOT EXIST %PATCH% GOTO NOPATCHDIR
rmdir /q /s %PATCH%
:NOPATCHDIR

echo Creating patch directories
REM Enable auto-creation of parent directories
SETLOCAL ENABLEEXTENSIONS
FOR /F %%B in (directories.txt) do (
mkdir %PATCH%\%%B
)
ENDLOCAL

echo Exporting changed files
SETLOCAL ENABLEDELAYEDEXPANSION

FOR /F %%A in (files.txt) do (
REM Changes the backslashes to forward slashes for the svn:// url
SET FILE=%%A%
SET URL=!FILE:\=/!

REM Export the file from the repository to the patch directory
svn export %SVN%/%URL% %PATCH%\%%A
)

ENDLOCAL

echo Cleaning up...
del files.txt
del directories.txt

:end
echo Done.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org
Received on Thu Jun 28 12:39:14 2007

This is an archived mail posted to the Subversion Users mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.