[p4] P4V vs P4Win
Arnt Gulbrandsen
arnt at gulbrandsen.priv.no
Tue Apr 17 01:55:30 PDT 2007
Rick Cameron writes:
> One feature of p4win that doesn't appear to have a equivalent in p4v
> 2007.1 is the "Local files not in depot" view. Not that I ever use
> it, but .. um .. a friend of mine sometimes realises he has forgotten
> to add a newly-created file to the depot, and uses this view to track
> it down.
I'm as stupid as your friend, but on a rare bright day I realised that
there is a Right Answer to this problem.
The algorithm is (I think I've posted this before):
1. Ask the build system for a complete list of source files
2. Ask perforce for a complete list of versioned files
3. Note any discrepancies
Due to the regrettable mental characteristics alluded to in my first
sentence, the script I wrote to implement this algorithm is a) bad, b)
too long and c) in perl. It's for jam. Users of make or other build
tools get to write their own.
Arnt
#!/usr/bin/perl
# find everything on which anything depends, and everything that
# depends on something, and the filenames involved
open( I, "jam -dd -dm |" );
while( <I> ) {
chomp;
if ( /^Depends "(.*)" : "(.*)" ;$/ ) {
$possible{$2} = 1;
$produce{$1} = 1;
}
elsif ( /^Includes "(.*)" : "(.*)" ;$/ ) {
$possible{$2} = 1;
}
elsif ( /^([a-z]+).?\s+([a-z-]+)\s+(.*)$/ ) {
if ( $2 eq "--" && $1 eq "bind" ) {
$args = $3;
if ( $args =~ /^([^:]*):\s+(.*)/ ) {
if ( !($2 =~ /^\// ) ) {
$name{$1} = ${2};
}
}
}
}
}
# for each target: can we make it? do we know a file name for it? do
# we have it? if no, yes and yes, then we need to source-control
# this file.
foreach ( sort keys %possible ) {
if ( !defined($produce{$_}) && defined($name{$_}) && -f $name{$_} ) {
$n = $name{$_};
# ugh. get rid of foo/../bar/evil.h
$n =~ s/\/[^\/]+\/\.\.\//\//;
$n =~ s/\/[^\/]+\/\.\.\//\//;
$n =~ s/\/[^\/]+\/\.\.\//\//;
$need{$n} = 1;
}
}
# find out what files we already have source control for.
$cwd = `pwd`;
chomp $cwd;
open( I, "p4 have ... |" );
while( <I> ) {
chomp;
s/.*${cwd}\///;
$have{$_} = 1;
}
# finally, what do we need but don't have?
foreach ( sort keys %need ) {
if ( !defined($have{$_}) ) {
print "p4 add ", $_, "\n";
}
}
More information about the perforce-user
mailing list