Return-Path: X-Original-To: apmail-subversion-users-archive@minotaur.apache.org Delivered-To: apmail-subversion-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8E0A110095 for ; Tue, 3 Dec 2013 20:06:02 +0000 (UTC) Received: (qmail 83087 invoked by uid 500); 3 Dec 2013 20:06:01 -0000 Delivered-To: apmail-subversion-users-archive@subversion.apache.org Received: (qmail 83066 invoked by uid 500); 3 Dec 2013 20:06:01 -0000 Mailing-List: contact users-help@subversion.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list users@subversion.apache.org Received: (qmail 83059 invoked by uid 99); 3 Dec 2013 20:06:01 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Dec 2013 20:06:01 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of prvs=042231a7c=Andrew.Reedick@cbeyond.net designates 69.199.69.197 as permitted sender) Received: from [69.199.69.197] (HELO mx1.cbeyond.net) (69.199.69.197) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Dec 2013 20:05:55 +0000 X-SBRS: None X-HAT: Sender Group RELAYLIST, Policy $RELAY applied. X-Hostname: mx1.cbeyond.net X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqAEAAU5nlIKBrQg/2dsb2JhbABavHqBMXSCJQEBBAE6GSYMBAIBCA4DBAEBHwkHMhQJCAEBBA4FCIdzC8EzF45NMQcGgxqBEwOJQqQs X-IronPort-AV: E=Sophos;i="4.93,819,1378872000"; d="scan'208";a="22807172" Received: from cbyexhub02.corp.cbeyond.net (HELO corpmail.cbeyond.net) ([10.6.180.32]) by mx1.cbeyond.net with ESMTP/TLS/AES128-SHA; 03 Dec 2013 15:05:33 -0500 Received: from crpmbx01.corp.cbeyond.net ([fe80::2992:4e2c:eaf:436a]) by CBYEXHUB02.corp.cbeyond.net ([::1]) with mapi; Tue, 3 Dec 2013 15:05:33 -0500 From: Andrew Reedick To: Daniel Shahaf CC: Alfred von Campe , "users@subversion.apache.org" Date: Tue, 3 Dec 2013 15:04:13 -0500 Subject: RE: Help with post-commit script Thread-Topic: Help with post-commit script Thread-Index: Ac7wU3VhczojhddRSUi25GfzcPfo5wAA6SnA Message-ID: <1B05D8F50421E24799AE93B03CC284BE01DE865C0D@CRPMBX01.corp.cbeyond.net> References: <6AFC66DF-D223-4688-9032-0894043C72AB@von-campe.com> <1B05D8F50421E24799AE93B03CC284BE01DE7DB7CE@CRPMBX01.corp.cbeyond.net> <20131203181350.GC3081@lp-shahaf.local> In-Reply-To: <20131203181350.GC3081@lp-shahaf.local> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Virus-Checked: Checked by ClamAV on apache.org > -----Original Message----- > From: Daniel Shahaf [mailto:d.s@daniel.shahaf.name] > Sent: Tuesday, December 03, 2013 1:14 PM > To: Andrew Reedick > Cc: Alfred von Campe; users@subversion.apache.org > Subject: Re: Help with post-commit script >=20 >=20 > > svnlook changed ... > $CHANGED_LIST || exit 1 cat $CHANGED_LIST | sed > > 's/^....//g' | perl -ne 'print "$1$2\n" if > > /^(trunk)\/|^(branches\/[^\/]*)\//' | sort -u | xargs -n 1 -i svnlook > > propget $REPOS_PATH my:filelist_prop "{}" > $FILES_TO_REPORT_ON || > > exit 1 > > > > cat $CHANGED_LIST | while read i >=20 > 'read' splits on whitespace, so filenames that contain spaces won't > DTRT. Close. Read will drop leading/trailing whitespace. It does respect "inter= nal" whitespace though.=20 The fix is to set IFS to null: $ OLD_IFS=3D$IFS $ IFS=3D $ echo " a b c d.txt " | while read i > do > echo ".$i." > done . a b c d.txt . Now if someone has embedded newlines in their filenames then that would be = a problem. At that point you're talking about 'xargs -0 (--null)', sort -z= , (--zero-terminated), using perl to chomp the newline and output a null ch= aracter, etc. How does 'svnlook changed' output filenames with embedded ne= wlines anyway? >=20 > > do > > grep -q "$i" "$FILES_TO_REPORT_ON" >=20 > Same for filenames that contain regex metacharacters. The entries in the filelist svn property would need to be in a regex format= . So everything would be escaped already.=20 If not, then perl's quotemeta and greps --fixed-strings flags would be of u= se: perl -ne 'chomp; print quotemeta($_) . "\n"' file.txt. =20 Anyway, IME, it's almost always a better idea to use the --xml option when = parsing svn commands, which implies writing a proper perl script. The work= can (probably) be done in bash, but with all the whitespace handling and p= otentially multiple layers of interpolation going on, the code can get unwi= eldy quickly. Updated script: #!/bin/bash set -o pipefail REPOS_PATH=3D$1 REV=3D$2 SVNLOOK_CMD=3D/path/to/svnlook RECIPIENT_LIST=3D$($SVNLOOK_CMD propget ... my:email_list_prop)=20 if [[ -z "$RECIPIENT_LIST" ]] then exit 0 fi CHANGED_LIST=3D$(mktemp ...) FILES_TO_REPORT_ON=3D$(mktemp ...) $SVNLOOK_CMD changed ... | perl -ne 'chomp; print quotemeta($_) . "\n"' > $= CHANGED_LIST || exit 1=20 perl -i -pe 's/^....//' $CHANGED_LIST perl -ne 'chomp; print quotemeta("$1$2") . "\n" if /^(trunk)\/|^(branches\/= [^\/]*)\//' $CHANGED_LIST | sort -u | xargs -n 1 -i svnlook propget "$REPOS= _PATH" my:filelist_prop "{}" > $FILES_TO_REPORT_ON || exit 1 cat $CHANGED_LIST | while read i do grep -q -F "$i" "$FILES_TO_REPORT_ON" if [[ $? -eq 0 ]] then svnlook diff -r ... | sendmail -s " $i was touched in an impure manner" $= RECIPIENT_LIST=20 fi done