update readme and add gitignore
[client-tools.git] / tools / p4_integrate_deleted.pl
blob2684219e30ae200245ca4eda97ef1a289a0eee72
1 #!/usr/bin/perl
3 # handle command line arguments
4 die "usage: perl p4_integrate_deleted.pl branch-name\n" if (scalar(@ARGV) != 1);
6 # read in the branch view
7 $branch = $ARGV[0];
8 print STDERR "processing branch $branch\n";
9 open(BRANCH, "p4 branch -o $branch |");
10 @branch = <BRANCH>;
11 shift @branch while ($branch[0] ne "View:\n");
12 shift @branch;
13 close(BRANCH);
15 foreach $mapping (@branch)
17 # process all the positive line in the mapping
18 chomp;
19 $mapping =~ s/^\s+//;
20 next if ($mapping eq "");
21 ($from, $to) = split(/\s+/, $mapping);
22 next if ($from =~ /^-/);
24 print STDERR "processing mapping $from -> $to\n";
26 undef %file;
28 # read in all the deleted source files
29 open(FILES, "p4 files $from |");
30 $count = 0;
31 print STDERR "processing files";
32 while (<FILES>)
34 chomp;
35 $count += 1;
36 if ($count == 10000)
38 print STDERR ".";
39 $count = 0;
41 next if (!/ - delete change /);
42 s/#[^#]+//;
43 $file{$_} = 1;
46 close(FILES);
47 print STDERR "\n";
49 # read in the set of source files we have. subtract them from the list of deleted files
50 open(HAVE, "p4 files $from#have |");
51 $count = 0;
52 print STDERR "processing have";
53 while (<HAVE>)
55 chomp;
56 $count += 1;
57 if ($count == 10000)
59 print STDERR ".";
60 $count = 0;
62 s/#[^#]+//;
63 delete $file{$_};
65 close(HAVE);
66 print STDERR "\n";
68 print STDERR "integrating ", scalar(keys %file), " files\n";
69 foreach (sort keys %file)
71 system("p4 integrate -b $branch -s \"$_\"");