-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCmtN2Off.perl
executable file
·67 lines (58 loc) · 1.63 KB
/
CmtN2Off.perl
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
#!/usr/bin/perl
use lib ("$ENV{HOME}/lookup", "$ENV{HOME}/lib64/perl5", "/home/audris/lib64/perl5","$ENV{HOME}/lib/perl5", "$ENV{HOME}/lib/x86_64-linux-gnu/perl", "$ENV{HOME}/share/perl5");
use strict;
use warnings;
use Error qw(:try);
use TokyoCabinet;
use Compress::LZF;
sub toHex {
return unpack "H*", $_[0];
}
sub fromHex {
return pack "H*", $_[0];
}
my $sections = 128;
my $check = defined $ARGV[1] ? $ARGV[1] : 0;
my $fast = defined $ARGV[2] ? $ARGV[2] : 1;
my $fbaseo="All.sha1o/sha1.commit_";
my $fbasei ="/data/All.blobs/commit_";
my (%fhoso);
#for my $sec (0 .. ($sections-1)){
my $sec = $ARGV[0];
my $pre = "/fast";
tie %{$fhoso{$sec}}, "TokyoCabinet::HDB", "$pre/${fbaseo}$sec.tch", TokyoCabinet::HDB::OWRITER | TokyoCabinet::HDB::OCREAT,
937777, -1, -1, TokyoCabinet::TDB::TLARGE, 100000
or die "cant open $pre/$fbaseo$sec.tch\n";
my $nn = 0;
if ( -f "$fbasei$sec.idx"){
if ($fast){
open A, "tac $fbasei$sec.idx|" or die ($!);
}else{
open A, "cat $fbasei$sec.idx|" or die ($!);
}
while (<A>){
chop ();
my @x = split (/\;/, $_, -1);
my $of = $x[1];
my $len = $x[2];
my $hash = $x[3];
my $h = fromHex ($hash);
my $off = pack ("w w", $of, $len);
if (defined $fhoso{$sec}{$h}){
if ($check){
my ($ofO, $lenO) = unpack "w w", $fhoso{$sec}{$h};
if ($ofO != $of || $lenO != $len){
print "incorrect for $hash: $ofO != $of || $lenO != $len\n";
}
}
if($fast){ last; }
}else{
$nn ++;
$fhoso{$sec}{$h} = $off;
}
}
}else{
die "no $fbasei$sec.idx\n";
}
untie %{$fhoso{$sec}};
print "done/updated $nn commits\n";