You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by John Goerzen <jg...@complete.org> on 2003/04/03 03:57:47 UTC
New code: svnpatch
Hello,
After getting annoyed at the slowness of svn_load_dirs dealing with
large kernel trees, and the general cumbersomeness of applying
patches, I wrote svnpatch. It's a simple Python script that is a
wrapper around patch. It will run patch, detect what has been added
or removed, and execute appropriate svn add / svn rm commands.
You run it like this, from your working directory:
bzcat ~/kernel/patch-2.4.20.bz2 | svnpatch -p1
The -p1 (and any other arguments) get paseed to patch.
Feel free to include it in Subversion. You can get it from the file
svnpatch in the Subversion repository at
http://svn.complete.org/misc/svnpatch/head. I'm also attaching a copy
below. While it is written in Python, it does not require the
Subversion python libraries.
-- John
#!/usr/bin/env python2.2
# COPYRIGHT #
# Copyright (C) 2003 John Goerzen
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# END OF COPYRIGHT #
import os, sys, stat
def getdirlist(startdir):
retval = []
for entry in os.listdir(startdir):
if entry == '.svn':
# Ignore Subversion special data.
continue
newfile = os.path.join(startdir, entry)
retval.append(newfile)
if os.path.isdir(newfile):
retval.extend(getdirlist(newfile))
return retval
def runcommand(args, dieonerror = 1):
print("Running: " + repr(args))
pid = os.fork()
if pid == 0:
# Child
os.execvp(args[0], args)
raise ProgrammingError, "EXEC failed!"
else:
# Parent
waitval = os.waitpid(pid, 0)[1]
if not dieonerror:
return waitval
if not os.WIFEXITED(waitval):
raise ValueError, "Command did not exit successfully"
if os.WEXITSTATUS(waitval):
raise ValueError, "Command returned status %d" % \
os.WEXITSTATUS(waitval)
if not os.path.isdir(".svn"):
raise Exception, "Must be executed from within a Subversion working directory."
print "Scanning directory tree..."
existingfiles = getdirlist('.')
print "%d files" % len(existingfiles)
print "Running patch..."
runcommand(["patch"] + sys.argv[1:])
print "Scanning directory tree..."
newfiles = getdirlist('.')
print "%d files" % len(newfiles)
deletedfiles = []
addedfiles = []
for file in existingfiles:
if not file in newfiles:
deletedfiles.append(file)
for file in newfiles:
if not file in existingfiles:
addedfiles.append(file)
print "%d files deleted; %d files added." % (len(deletedfiles),
len(addedfiles))
if len(deletedfiles):
runcommand(['svn', 'rm'] + deletedfiles)
if len(addedfiles):
runcommand(['svn', 'add'] + addedfiles)
print "Successful completion. Remember to svn commit."
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Re: New code: svnpatch
Posted by John Goerzen <jg...@complete.org>.
On Thu, Apr 03, 2003 at 05:12:53PM +0200, Rafael Garcia-Suarez wrote:
> > No. Patch will exit with a nonzero status if it creates any of those,
> > and svnpatch makes no changes if this occurs. That is, running
> > svnpatch in this case is functionally identical to running patch.
>
> I think that patch still exits with a status == 0 _and_ creates .orig files
> if it succeeds to apply patches, but needs to offset some changes to do so.
> As your tool doesn't perform the actual commit this is not really important.
Ahh. In that case I will add a test to make sure to ignore those files.
I am upgrading the system anyway so that one can do something like:
svnchange start
...
do lots of stuff here like patching, etc.
...
svnchange stop # find what happend, and issue appropriate svn add/rm commands
svn commit
svnpatch will then just be a simple wrapper script that does svnchange
start, patch, svnchange stop.
-- John
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Re: New code: svnpatch
Posted by John Goerzen <jg...@complete.org>.
Rafael Garcia-Suarez <ra...@hexaflux.com> writes:
> Good first attempt at a naive implementation ;-)
Thanks, but I think you're wrong on all three counts :-)
> There are a few problems :
> It doesn't appear to handle removed/added directories. (patch(1)
> automatically deletes dirs when all files in them have been
> removed by a patch. Recursively.)
It will notice that directories are gone, and will run svn rm on them
accordingly. Same goes for svn add. Both those commands work on
directories as well as files. I tested this with early versions of
the 2.4.0 Linux kernel tree where they added a new directory for
ReiserFS. It worked fine.
As far as patch removing directories, I don't think it will actually
do this because of the .svn directory in each one. So that is a known
weak spot of this system.
> It doesn't check the exit status of patch(1).
That's what this code is for:
if not os.WIFEXITED(waitval):
raise ValueError, "Command did not exit successfully"
if os.WEXITSTATUS(waitval):
raise ValueError, "Command returned status %d" % \
os.WEXITSTATUS(waitval)
I did test it, and it does work. The "raise" raises a Python
exception, and since I do not catch that exception, it causes the
program to terminate.
> It will erroneously add *.{orig,rej} files.
No. Patch will exit with a nonzero status if it creates any of those,
and svnpatch makes no changes if this occurs. That is, running
svnpatch in this case is functionally identical to running patch.
-- John
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Re: New code: svnpatch
Posted by Rafael Garcia-Suarez <ra...@hexaflux.com>.
John Goerzen <jg...@complete.org> wrote:
> Hello,
>
> After getting annoyed at the slowness of svn_load_dirs dealing with
> large kernel trees, and the general cumbersomeness of applying
> patches, I wrote svnpatch. It's a simple Python script that is a
> wrapper around patch. It will run patch, detect what has been added
> or removed, and execute appropriate svn add / svn rm commands.
Good first attempt at a naive implementation ;-)
There are a few problems :
It doesn't appear to handle removed/added directories. (patch(1)
automatically deletes dirs when all files in them have been
removed by a patch. Recursively.)
It doesn't check the exit status of patch(1).
It will erroneously add *.{orig,rej} files.
> You run it like this, from your working directory:
>
> bzcat ~/kernel/patch-2.4.20.bz2 | svnpatch -p1
>
> The -p1 (and any other arguments) get paseed to patch.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Re: New code: svnpatch
Posted by Karl Fogel <kf...@newton.ch.collab.net>.
Sander Roobol <ph...@wanadoo.nl> writes:
> Filed as issue #1236.
If I said it for every patch you managed, we'd quickly be swamped in
thank-you mails, so I'll just pick this patch randomly to say: Thanks,
as always, for the excellent patch management, Sander! Far fewer
patches are being dropped these days; I'm think this is largely due to
your tracking.
-Karl
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Re: New code: svnpatch
Posted by Sander Roobol <ph...@wanadoo.nl>.
Filed as issue #1236.
Sander
On Wed, Apr 02, 2003 at 09:57:47PM -0600, John Goerzen wrote:
> Hello,
>
> After getting annoyed at the slowness of svn_load_dirs dealing with
> large kernel trees, and the general cumbersomeness of applying
> patches, I wrote svnpatch. It's a simple Python script that is a
> wrapper around patch. It will run patch, detect what has been added
> or removed, and execute appropriate svn add / svn rm commands.
>
> You run it like this, from your working directory:
>
> bzcat ~/kernel/patch-2.4.20.bz2 | svnpatch -p1
>
> The -p1 (and any other arguments) get paseed to patch.
>
> Feel free to include it in Subversion. You can get it from the file
> svnpatch in the Subversion repository at
> http://svn.complete.org/misc/svnpatch/head. I'm also attaching a copy
> below. While it is written in Python, it does not require the
> Subversion python libraries.
>
> -- John
>
> [snip]
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org