Skip to content

Commit 97abf19

Browse files
committed
Handle added files in perforce
Signed-off-by: Henry Cox <[email protected]>
1 parent 36cc064 commit 97abf19

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

scripts/P4version.pm

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,19 @@ sub new
150150
}
151151
close(P4) or die("error on close 'p4 have' pipe: $!");
152152

153+
open(WHERE, '-|', "$cd p4 where $depot") or
154+
die("unable to execute p4 where: $!");
155+
my ($depot_path, $workspace_path, $workspace_dir);
156+
while (<WHERE>) {
157+
if (/^(\S+)\s*(\S+)\s*(\S+)$/) {
158+
$depot_path = substr($1, 0, -4); # remove the '/...' tail
159+
$workspace_path = substr($2, 0, -4);
160+
$workspace_dir = substr($3, 0, -4);
161+
last;
162+
}
163+
}
164+
close(WHERE) or die("error on close 'p4 where' pipe: $!");
165+
153166
# check for local edits...
154167
open(EDITS, '-|', "$cd p4 opened $depot$dots") or
155168
die("unable to execute p4 opened: $!");
@@ -158,7 +171,19 @@ sub new
158171
/^(.+?)(#[0-9]+) - (edit|add|delete) (default change|change (\S+)) /)
159172
{
160173
# file is locally edited...append modify time or MD5 signature to the version ID
161-
my $data = $filehash{$1};
174+
my $data;
175+
if (exists($filehash{$1})) {
176+
die("unexpected 'add' state") if 'add' eq $3;
177+
$data = $filehash{$1};
178+
} else {
179+
die("unexpected 'add' state") unless 'add' eq $3;
180+
my $trimmed = substr($1, length($depot_path));
181+
my $full_name = $workspace_dir . $trimmed;
182+
$data = [$full_name, $1, $trimmed, '#add'];
183+
$filehash{$full_name} = $data;
184+
$filehash{$1} = $data;
185+
$filehash{$trimmed} = $data unless $trimmed eq $full_name;
186+
}
162187
if (!$local_edit) {
163188
die("$1$2 has local changes - see '--local-edit' flag");
164189
}

0 commit comments

Comments
 (0)