Repository navigation
Expand file tree
/
Copy pathedg-unused-versions
More file actions
executable file
·146 lines (112 loc) · 4.24 KB
/
Copy pathedg-unused-versions
File metadata and controls
executable file
·146 lines (112 loc) · 4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/perl
=pod
=head1 NAME
edg-unused-versions - make a list of unused EDG binary version numbers
=head1 SYNOPSIS
edg-unused-versions [--old] [--manifest=FILE] [--progress] [--verbose] COMMITS...
=head1 DESCRIPTION
This script reads an EDG manifest file that lists a single EDG binary version number (SHA1 or MD5 hash) per line. The script then
examines each commit reachable from the specified commits and removes its EDG binary version number from further consideration.
At the end, the remaining version numbers are listed; they are the EDG binary versions that are not needed by the specified commit.
=head1 SWITCHES
=over
=item --old
Use the old-style EDG binary version numbers. These are MD5 sums computed recursively over entire directory hierarchies
of the ROSE source tree. They are much more expensive to compute than the new version numbers.
=item --manifest=FILE
Use the specified manifest file rather than "./edg_binaries.txt".
=item --progress
Show progress on the standard error stream.
=item --verbose
Print EDG version numbers that are found and the most recent commit that uses them.
=item COMMITS
The COMMITS and all unrecognized switches are passed directly to git-rev-list.
=back
=head1 AUTHOR
Robb Matzke.
Copyright Lawrence Livermore National Security
Licensed under Revised BSD License (see COPYRIGHT file at top of ROSE source code)
=cut
use strict;
# Figure out where we are, because the other scripts are in the same directory
my($mydir) = $0 =~ /(.*)\//;
my($me) = $0 =~ /([^\/]+)$/;
$mydir ||= ".";
sub help {
local $_ = `(pod2man $0 |nroff -man) 2>/dev/null` ||
`pod2text $0 2>/dev/null` ||
`sed -ne '/^=pod/,/^=cut/p' $0 2>/dev/null`;
die "$0: see source file for documentation" unless $_;
if (open LESS, "|less -R") {
print LESS $_;
close LESS;
} else {
print $_;
}
};
# Return the date of the commit
sub commit_date {
my($commit) = @_;
open GIT, "git cat-file -p '$commit' |" or die "$me: git-cat-file failed for commit $commit\n";
my($time);
while (<GIT>) {
last if /^\s*$/;
last if ($time) = /^committer .*?(\d+)\s*([-+]\d+)?\s*$/;
}
close GIT;
return "" unless defined $time;
my($yy,$mm,$dd) = (localtime $time)[5,4,3]; # don't worry about time zone
$yy+=1900; $mm+=1;
return sprintf "%4d-%02d-%02d", $yy, $mm, $dd;
}
# Parse command line
my($manifest,$hashsize,$progress,$verbose,@edg_generate_sig,@git_rev_list) = ('edg_binaries.txt',40);
while (@ARGV) {
if ($ARGV[0] eq '--') {
shift @ARGV;
last;
} elsif ($ARGV[0] =~ /^(--help|-[h?])$/) {
help; exit 0;
} elsif ($ARGV[0] eq '--old') {
$hashsize=32;
push @edg_generate_sig, shift @ARGV;
} elsif ($ARGV[0] =~ /^--manifest=(.*)/) {
$manifest = shift @ARGV;
} elsif ($ARGV[0] eq '--progress') {
$progress=0; shift @ARGV;
} elsif ($ARGV[0] eq '--verbose') {
$verbose=1; shift @ARGV;
} else {
push @git_rev_list, shift @ARGV;
}
}
@git_rev_list!=0 or
die "usage: $0 [--old] [--manifest=FILE] [--progress] COMMITS... (cf. \"--help\")\n";
# Load the manifest into a hash
my %manifest;
open MANIFEST, "<", $manifest or die "$manifest: $!\n";
$manifest{$_}++ for grep {$_} map {/^([0-9a-f]{$hashsize})$/} <MANIFEST>;
close MANIFEST;
print STDERR "$manifest: number of unique entries: ", 0+keys(%manifest), "\n";
# Remove EDG binary versions that are in use
my($git_rev_list) = join " ", "git rev-list", map {"'$_'"} @git_rev_list;
my @commits = map {chomp; $_} `$git_rev_list`;
print STDERR "$me: considering ", 0+@commits, " commits\n";
my($goal) = 0+@commits;
for my $commit (@commits) {
my($edg_generate_sig) = join " ", "$mydir/edg-generate-sig", map {"'$_'"} @edg_generate_sig;
my($edgbin_version) = `$edg_generate_sig $commit`;
chomp $edgbin_version;
if ($verbose && exists $manifest{$edgbin_version}) {
print STDERR "\r$edgbin_version for commit ", substr($commit,0,7), " on ", commit_date($commit), "\n";
}
delete $manifest{$edgbin_version};
if (defined $progress) {
$progress++;
printf STDERR "\r%-6d (%3d%%) %1d remaining; %s ", $progress, 100*$progress/$goal, 0+keys %manifest, commit_date($commit);
}
last unless keys %manifest;
}
print STDERR "\n" if defined $progress;
# Print unused EDG binary version numbers
print "$_\n" for sort keys %manifest;