You are not logged in.

#1 2007-11-02 13:45:24

Cub69
Member
From: Ottawa, Canada
Registered: 2006-01-20
Posts: 87
Website

Patching with mulitple recursive patch files

Hi everyone,

I would like to patch a series of files - I have a directory tree with the original files and a matching tree that contains .dff files.  Anyone know how I can accomplish this?

Thanks
Cub

Offline

#2 2007-11-02 16:15:56

Cub69
Member
From: Ottawa, Canada
Registered: 2006-01-20
Posts: 87
Website

Re: Patching with mulitple recursive patch files

Ok, since no one replied, I figured the answer was no so I wrote a quick perl script to do it for me.  Here it is if anyone is interested.

cat patch-recurse.pl
#! /usr/bin/perl
##  This program will recusively go through a directory tree and apply patches from diff files
##  Options are:  $1 patch-source tree $2 destination tree, $3 patch-options like  -p1, -F10 or -R
##  Norm Dressler

$srctree=$ARGV[0];
$destree=$ARGV[1];
$patchopts=$ARGV[2];

recurse("$ARGV[0]");

sub recurse
{
    my($path) =@_ ;
    print( "working in: $path\n" );
    $path .= '/' if($path !~ /\/$/);
    for my $eachFile (glob($path . '*')) {
        # if the file is a directory
        if( -d $eachFile)
        {
            # pass the directory to the routine ( recursion )
            recurse($eachFile);
        }
        else
        {
            handleFile($path, $eachFile );
        }
    }
}

sub handleFile
{
        my($destpath, $File) = @_;
        ## strip leading dirs and merge with destree
        $destpath =~ s/$srctree/$destree/g;
        printf("$destpath\t$File\n");
        #Dry-run to ensure patch will apply
        `patch -d $destpath --dry-run $patchopts <$File>/tmp/dryrun.log`;
break;
        if ( $results=`cat /tmp/dryrun.log`=~ /FAILED/o ) {
                $results=`cat /tmp/dryrun.log`;
                printf("Failed\n$results\n\nFile being patched: $File\nDirectory: $destpath\n");
                printf("Should I apply this patch anyways? (y/n) ");
                chomp($answer = <>);        # Get the input, assign it to the variable
                if    ( $answer eq "y" ) {
                       `patch -d $destpath $patchopts <$File>>/tmp/patch.log`;
                }
        } else {
                #dry-run was fine, patch for real!
                 `patch -d $destpath $patchopts <$File>>/tmp/patch.log`;
        }
}

Offline

#3 2007-11-10 08:52:29

colinzhengj
Member
From: Cambridge, MA
Registered: 2007-03-20
Posts: 23
Website

Re: Patching with mulitple recursive patch files

Hmm,,,,concatenate all the diff files and run patch on the resulting single file should do the same

Offline

Board footer

Powered by FluxBB