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

New code: svnpatch

From: John Goerzen <jgoerzen_at_complete.org>
Date: 2003-04-03 05:57:47 CEST


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 (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
# 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

import os, sys, stat

def getdirlist(startdir):
    retval = []
    for entry in os.listdir(startdir):
        if entry == '.svn':
            # Ignore Subversion special data.
        newfile = os.path.join(startdir, entry)
        if os.path.isdir(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!"
        # 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" % \

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:

for file in newfiles:
    if not file in existingfiles:

print "%d files deleted; %d files added." % (len(deletedfiles),

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
Received on Thu Apr 3 06:01:33 2003

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

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