Subject: Re: keeping pkgsrc up-to-date
To: Marton Fabo <morton@eik.bme.hu>
From: Thomas Klausner <wiz@danbala.ifoer.tuwien.ac.at>
List: tech-pkg
Date: 07/02/2002 03:12:25
--9dgjiU4MmWPVapMU
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Tue, Jul 02, 2002 at 12:26:59AM +0200, Marton Fabo wrote:
> As I see, daily pkgsrc changes are generated for the pkgsrc-changes list, 
> and sent to all the subscribers. Couldn't this or some similar thing be 
> used to keep in sync with less disk and network traffic? For example, some 
> script could be written to extract the files changed since the last day, 
> and update only those files. I'm sure this would be much lighter/faster 
> than a full CVS update for example.

I've written a short perl script that does exactly that -- use
source-changes (and/or www-changes and/or pkgsrc-changes) mails as
input and do the suitable cvs updates.

I'm sure I'm not the only one who has such a script, and it might have
a bug or two lurking, but so far I've been pretty happy about it.

You'll have to configure it before the first start, read the comments
in the file.

If you find any problems, mail me.

Bye,
 Thomas

-- 
Thomas Klausner - wiz@danbala.tuwien.ac.at
Intolerance is the last defense of the insecure.

--9dgjiU4MmWPVapMU
Content-Type: application/x-perl
Content-Disposition: attachment; filename="autofetch.pl"
Content-Transfer-Encoding: quoted-printable

#!/usr/pkg/bin/perl=0A#=0A# Copyright (c) 2000, 2001, 2002 Thomas Klausner =
<wiz@netbsd.org>=0A# All rights reserved.=0A#=0A# $Id: autofetch.pl,v 1.6 2=
002/07/02 01:11:48 wiz Exp $=0A#=0A# Redistribution and use in source and b=
inary forms, with or without=0A# modification, are permitted provided that =
the following conditions=0A# are met:=0A# 1. Redistributions of source code=
 must retain the above copyright=0A#    notice, this list of conditions and=
 the following disclaimer.=0A# 2. Redistributions in binary form must repro=
duce the above copyright=0A#    notice, this list of conditions and the fol=
lowing disclaimer in the=0A#    documentation and/or other materials provid=
ed with the distribution.=0A# 3. The name of the author may not be used to =
endorse or promote products=0A#    derived from this software without speci=
fic prior written permission.=0A#=0A# THIS SOFTWARE IS PROVIDED BY THOMAS K=
LAUSNER ``AS IS'' AND ANY EXPRESS=0A# OR IMPLIED WARRANTIES, INCLUDING, BUT=
 NOT LIMITED TO, THE IMPLIED=0A# WARRANTIES OF MERCHANTABILITY AND FITNESS =
FOR A PARTICULAR PURPOSE ARE=0A# DISCLAIMED.  IN NO EVENT SHALL THE FOUNDAT=
ION OR CONTRIBUTORS BE=0A# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE=
CIAL, EXEMPLARY, OR=0A# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED T=
O, PROCUREMENT OF=0A# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR P=
ROFITS; OR=0A# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF L=
IABILITY,=0A# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEG=
LIGENCE=0A# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWAR=
E, EVEN=0A# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.=0A#=0A# Use NetBS=
D source-changes postings to generate 'cvs update' lines=0A# or, by default=
, do 'cvs update's.=0A#=0A# Flags:=0A# -t   Generate (not properly quoted) =
shell code instead of=0A#      directly doing cvs update.=0A#=0A# Modify th=
e next lines to specify the place for your CVS archive(s);=0A# comment out =
lines for parts of the repository that you don't want =0A# to follow. Branc=
h commits are logged internally as commits to=0A# 'directory-branchname' (s=
ee syssrc-netbsd-1-5 below as an example).=0A=0A#$base =3D "/usr";=0A$base =
=3D "/archive/cvs";=0A#$base15 =3D "/archive/cvs/1.5";=0A=0A%nametodir =3D =
(=0A	      "basesrc" =3D> "$base/src",=0A	      "cryptosrc-intl" =3D> "$bas=
e/src",=0A	      "doc" =3D> "$base/doc",=0A	      "gnusrc" =3D> "$base/src"=
,=0A	      "htdocs" =3D> "$base/htdocs",=0A	      "pkgsrc" =3D> "$base/pkgs=
rc",=0A	      "sharesrc" =3D> "$base/src",=0A	      "syssrc" =3D> "$base/sr=
c",=0A#	      "syssrc-netbsd-1-5" =3D> "$base15/syssrc",=0A	      "xsrc" =
=3D> "$base/xsrc"=0A);=0A=0A$cvspreflags =3D "-z3";=0A$cvspostflags =3D "-d=
P";=0A=0A# You shouldn't have to change anything below this line=0A=0A# if =
the following flag is set, print what would be executed instead of=0A# doin=
g it right away=0A$testflag =3D 0;=0Aif ((@ARGV > 0) and ($ARGV[0] eq "-t")=
) {=0A    $testflag =3D 1;=0A    shift @ARGV;=0A}=0A=0A%output =3D ();=0A$d=
ir =3D "";=0A$collection =3D "";=0A@files =3D ();=0A$relevant =3D 0;=0A=0Aw=
hile (<>) {=0A    chomp();=0A#    print("parsing: $_\n");=0A    if (/^$/) {=
=0A	$relevant =3D 0;=0A	next;=0A    }=0A    if (/^(Modified|Added|Removed) =
Files:/) {=0A	$relevant =3D 1;=0A	next;=0A    }=0A    if (/Update of \/cvsr=
oot\/([\S]*(?:src|doc)[^\/]*)\/(\S*)$/) {=0A	# import of new packages=0A	$c=
ollection =3D $1;=0A	# not really necessary, but oh well...=0A	$dir =3D $2;=
=0A	@files =3D split ' ', $2;=0A    }=0A    elsif ($relevant =3D=3D 0) {=0A=
	next;=0A    }=0A    elsif (/\t([\S]*(?:src|doc)[^\/]*)\/([^:]*): (.*)/) {=
=0A	# update of files in a sub-directory=0A	$collection =3D $1;=0A	$dir =3D=
 $2;=0A	@files =3D split ' ', $3;=0A	if ($dir =3D~ /\[(.*)\]/) {=0A	    # b=
ranch commit, change collection=0A	    $collection .=3D "-$1";=0A	    $dir =
=3D~ s/ \[(.*)\]//g;=0A#	    print "branch commit: $1 ($collection, $dir)\n=
";=0A	}=0A	foreach $entry (@files) {=0A	    $entry =3D~ s,^,$dir/,;=0A	}=0A=
    } =0A    elsif (/\t([\S]*(?:src|doc)[^:]*): (.*)/) {=0A	# update of fil=
es in root directory=0A	$collection =3D $1;=0A	$dir =3D "";=0A	@files =3D s=
plit ' ', $2;=0A	if ($collection =3D~ /\[(.*)\]/) {=0A	    # branch commit,=
 change collection=0A	    $collection =3D~ s/ \[(.*)\]//g;=0A	    $collecti=
on .=3D "-$1";=0A	}=0A    } =0A    elsif (/^\t    ([^ ].*)$/) {=0A	# contin=
uation line of above=0A	@files =3D split ' ', $1;=0A	if ($dir) {=0A	    for=
each $entry (@files) {=0A		$entry =3D~ s,^,$dir/,;=0A	    }=0A	}=0A    }=0A=
    else {=0A	next;=0A    }=0A=0A    if ($nametodir{$collection}) {=0A#	pri=
nt "pushing @files to $collection\n";=0A	push @{$output{$collection}}, @fil=
es;=0A	@files =3D ();=0A    }=0A}=0A=0A$last =3D "thisshouldntmatchanything=
";=0A=0A# optimize cvs update, remove duplicates (which break cvs update=0A=
# with bogus conflicts)=0Aforeach $entry (keys %output) {=0A    chdir($name=
todir{$entry});=0A    @args =3D ("cvs", $cvspreflags, "update", $cvspostfla=
gs);=0A    unshift @args, "echo", "cd $nametodir{$entry};" if $testflag;=0A=
    foreach $line (sort @{$output{$entry}}) {=0A	$_ =3D $line;=0A	=0A	if (!=
 /^$last\// and !/^$last$/) {=0A	    $donttake =3D $line;=0A	    while (! -=
f $donttake and ! -d $donttake and $line =3D~ /\//) {=0A		$line =3D $dontta=
ke;=0A		$donttake =3D~ s/\/[^\/]*$//;=0A	    }=0A	    push @args, $line;=0A=
	    $last =3D quotemeta($line);=0A	}=0A    }=0A    $rc =3D system @args;=
=0A    printf ("cvs update failed: return value %d: $!", $rc>>8) if $rc;=0A=
}=0A
--9dgjiU4MmWPVapMU--