[Catalyst-commits] r6642 - in trunk/misc: . svn
andyg at dev.catalyst.perl.org
andyg at dev.catalyst.perl.org
Sat Aug 11 01:45:07 GMT 2007
Author: andyg
Date: 2007-08-11 01:45:07 +0100 (Sat, 11 Aug 2007)
New Revision: 6642
Added:
trunk/misc/svn/
trunk/misc/svn/ban-tabs.pl
trunk/misc/svn/pre-commit
Log:
A little pre-commit script to check for leading tabs
Added: trunk/misc/svn/ban-tabs.pl
===================================================================
--- trunk/misc/svn/ban-tabs.pl (rev 0)
+++ trunk/misc/svn/ban-tabs.pl 2007-08-11 00:45:07 UTC (rev 6642)
@@ -0,0 +1,109 @@
+#!/usr/bin/perl
+#
+# Check an svn transaction for leading tabs
+#
+# $Id$
+# Author: Andy Grundman <andy at hybridized.org>
+#
+# Inspired by a Python pre-commit script that I found here:
+# http://blog.wordaligned.org/articles/2006/08/09/a-subversion-pre-commit-hook
+#
+
+use strict;
+
+use constant DEBUG => 0;
+use constant SVNLOOK => '/usr/bin/svnlook';
+
+my $test;
+
+my $repos = shift;
+if ( $repos eq '-r' ) {
+ $test = 1;
+ $repos = shift;
+}
+
+my $txn = shift;
+
+unless ( $repos && $txn ) {
+ usage();
+}
+
+# Get list of changed files
+my @files;
+my $cmd = sprintf "%s %s %s %s %s",
+ SVNLOOK,
+ 'changed',
+ $repos,
+ $test ? '--revision' : '--transaction',
+ $txn;
+
+DEBUG && warn "$cmd\n";
+
+open my $changed, "$cmd |" or die "Unable to run $cmd: $!\n";
+while (<$changed>) {
+ chomp;
+
+ if ( /^[AU]\s+(.+)/ ) {
+ my $path = $1;
+
+ # Skip dirs
+ if ( $path !~ m{/$} ) {
+ push @files, $path;
+ }
+ }
+}
+close $changed;
+
+# Check each file for tabs
+my @has_tabs;
+
+for my $file ( @files ) {
+ my $cmd = sprintf "%s %s %s %s %s %s",
+ SVNLOOK,
+ 'cat',
+ $repos,
+ $test ? '--revision' : '--transaction',
+ $txn,
+ $file;
+
+ DEBUG && warn "$cmd\n";
+
+ open my $cat, "$cmd |" or die "Unable to run $cmd: $!\n";
+ my @lines = <$cat>;
+ close $cat;
+
+ my $line = 1;
+ for ( @lines ) {
+ if ( /^\t/ ) {
+ push @has_tabs, {
+ file => $file,
+ line => $line,
+ };
+ last;
+ }
+ $line++;
+ }
+}
+
+if ( @has_tabs ) {
+ warn "Leading tabs were found in the following file(s). Please correct and re-commit.\n";
+ for my $file ( @has_tabs ) {
+ my $error = sprintf "Line: %4d %s\n", $file->{line}, $file->{file};
+ warn $error;
+ }
+ exit 1;
+}
+
+exit 0;
+
+sub usage {
+ warn <<USAGE;
+Usage: $0 [OPTIONS] REPOS TXN
+
+options:
+ -r Test mode. TXN actually refers to a revision.
+USAGE
+
+ exit 1;
+}
+
Property changes on: trunk/misc/svn/ban-tabs.pl
___________________________________________________________________
Name: svn:executable
+ *
Added: trunk/misc/svn/pre-commit
===================================================================
--- trunk/misc/svn/pre-commit (rev 0)
+++ trunk/misc/svn/pre-commit 2007-08-11 00:45:07 UTC (rev 6642)
@@ -0,0 +1,11 @@
+#!/bin/sh
+#
+# Deny all commits that contain leading tabs
+
+REPOS="$1"
+TXN="$2"
+
+/home/catalyst/bin/ban-tabs.pl "$REPOS" "$TXN" || exit 1
+
+# All checks passed, so allow the commit.
+exit 0
Property changes on: trunk/misc/svn/pre-commit
___________________________________________________________________
Name: svn:executable
+ *
More information about the Catalyst-commits
mailing list