[p4] Best way to prevent checkins with wrong line endings?
G Barthelemy
gb.perforce at googlemail.com
Thu Nov 8 05:12:38 PST 2007
If this can be of any use, here's one I wrote earlier. This one uses
the P4 Perl API, modifies new clients only, changes the default
SubmitOptions from submitunchanged to revertunchanged, the LineEnd
mode from local to share, and removes the view mapping for our
specdepot (which users can always add manually should they need to
sync from the specdepot). It also identifies itself in the server logs
using the script's filename.
#!/usr/local/bin/perl -w
=head1 NAME
customise_client.pl - Perforce trigger to customise the p4 client form.
=head1 SYNOPSIS
customise_client form-out client "/usr/bin/perl
<triggers_path>/customise_client.pl %serverport% %formname%
%formfile%"
=head1 DESCRIPTION
The following Perforce trigger script modifies the client form on the
fly as it is generated by the server and presented to the user
(form-out). Some default values such as the SubmitOptions, LineEnd and
the mapping of the specdepot are changed.
Note that as this script uses the Perforce Perl API, which is not
bundled with Perl, upgrading Perl without installing the Perforce API
is a bad idea.
=cut
use File::Basename;
use P4;
our $p4 = new P4;
my $p4user = "p4triggers";
my $port = $ARGV[0];
my $client = $ARGV[1];
my $form = $ARGV[2];
$p4->SetProg(basename($0));
$p4->SetUser($p4user);
$p4->SetPort($port);
$p4->Tagged();
$p4->Connect() or die ("Couldn't initialise p4 connection.\n");
$allclientsref = $p4->Clients();
$p4->Disconnect();
# if client exists, then leave it alone
foreach my $clientref (@{$allclientsref}) {
exit 0 if ($clientref->{'client'} eq $client);
}
# If we made it to here, this is a new client
# Slurp temporary file
open FORM, '<', $form or die ("Trigger couldn't read from temporary
file $form.\n");
my @lines = <FORM>;
close FORM;
# Perform modifications
open FORM, '>', $form or die ("Couldn't write to temporary file $form.\n");
foreach $line (@lines) {
$line =~
s/^SubmitOptions:\s+submitunchanged/SubmitOptions:\trevertunchanged/;
$line =~ s/^LineEnd:\s+local/LineEnd:\tshare/;
next if ($line =~ m|^\s+//specdepot/\.\.\.|);
print FORM $line;
}
close FORM;
exit 0;
On Nov 7, 2007 3:28 PM, Jay Glanville
<Jay.Glanville at naturalconvergence.com> wrote:
> Thanks to all for your suggestion. I will investigate spec triggers
> more intimately.
>
> ---
> Jay Dickon Glanville
>
More information about the perforce-user
mailing list