@@ -2,7 +2,7 @@ package Git::SVN;
2
2
use strict;
3
3
use warnings;
4
4
use Fcntl qw/ :DEFAULT :seek/ ;
5
- use constant rev_map_fmt => ' NH40 ' ;
5
+ use constant rev_map_fmt => ' NH* ' ;
6
6
use vars qw/ $_no_metadata
7
7
$_repack $_repack_flags $_use_svm_props $_head
8
8
$_use_svnsync_props $no_reuse_existing
@@ -2087,10 +2087,10 @@ sub rebuild_from_rev_db {
2087
2087
open my $fh , ' <' , $path or croak " open: $! " ;
2088
2088
binmode $fh or croak " binmode: $! " ;
2089
2089
while (<$fh >) {
2090
- length ($_ ) == 41 or croak " inconsistent size in ($_ ) != 41 " ;
2090
+ length ($_ ) == $: :oid_length + 1 or croak " inconsistent size in ($_ )" ;
2091
2091
chomp ($_ );
2092
2092
++$r ;
2093
- next if $_ eq (' 0' x 40 );
2093
+ next if $_ eq (' 0' x $: :oid_length );
2094
2094
$self -> rev_map_set($r , $_ );
2095
2095
print " r$r = $_ \n " ;
2096
2096
}
@@ -2196,9 +2196,9 @@ sub rebuild {
2196
2196
# (mainly tags)
2197
2197
#
2198
2198
# The format is this:
2199
- # - 24 bytes for every record,
2199
+ # - 24 or 36 bytes for every record,
2200
2200
# * 4 bytes for the integer representing an SVN revision number
2201
- # * 20 bytes representing the sha1 of a git commit
2201
+ # * 20 or 32 bytes representing the oid of a git commit
2202
2202
# - No empty padding records like the old format
2203
2203
# (except the last record, which can be overwritten)
2204
2204
# - new records are written append-only since SVN revision numbers
@@ -2207,46 +2207,47 @@ sub rebuild {
2207
2207
# - Piping the file to xxd -c24 is a good way of dumping it for
2208
2208
# viewing or editing (piped back through xxd -r), should the need
2209
2209
# ever arise.
2210
- # - The last record can be padding revision with an all-zero sha1
2210
+ # - The last record can be padding revision with an all-zero oid
2211
2211
# This is used to optimize fetch performance when using multiple
2212
2212
# "fetch" directives in .git/config
2213
2213
#
2214
2214
# These files are disposable unless noMetadata or useSvmProps is set
2215
2215
2216
2216
sub _rev_map_set {
2217
2217
my ($fh , $rev , $commit ) = @_ ;
2218
+ my $record_size = ($: :oid_length / 2) + 4;
2218
2219
2219
2220
binmode $fh or croak " binmode: $! " ;
2220
2221
my $size = (stat ($fh ))[7];
2221
- ($size % 24 ) == 0 or croak " inconsistent size: $size " ;
2222
+ ($size % $record_size ) == 0 or croak " inconsistent size: $size " ;
2222
2223
2223
2224
my $wr_offset = 0;
2224
2225
if ($size > 0) {
2225
- sysseek($fh , -24 , SEEK_END) or croak " seek: $! " ;
2226
- my $read = sysread ($fh , my $buf , 24 ) or croak " read: $! " ;
2227
- $read == 24 or croak " read only $read bytes (!= 24 )" ;
2226
+ sysseek($fh , -$record_size , SEEK_END) or croak " seek: $! " ;
2227
+ my $read = sysread ($fh , my $buf , $record_size ) or croak " read: $! " ;
2228
+ $read == $record_size or croak " read only $read bytes (!= $record_size )" ;
2228
2229
my ($last_rev , $last_commit ) = unpack (rev_map_fmt, $buf );
2229
- if ($last_commit eq (' 0' x 40 )) {
2230
- if ($size >= 48 ) {
2231
- sysseek($fh , -48 , SEEK_END) or croak " seek: $! " ;
2232
- $read = sysread ($fh , $buf , 24 ) or
2230
+ if ($last_commit eq (' 0' x $: :oid_length )) {
2231
+ if ($size >= ( $record_size * 2) ) {
2232
+ sysseek($fh , -( $record_size * 2) , SEEK_END) or croak " seek: $! " ;
2233
+ $read = sysread ($fh , $buf , $record_size ) or
2233
2234
croak " read: $! " ;
2234
- $read == 24 or
2235
- croak " read only $read bytes (!= 24 )" ;
2235
+ $read == $record_size or
2236
+ croak " read only $read bytes (!= $record_size )" ;
2236
2237
($last_rev , $last_commit ) =
2237
2238
unpack (rev_map_fmt, $buf );
2238
- if ($last_commit eq (' 0' x 40 )) {
2239
+ if ($last_commit eq (' 0' x $: :oid_length )) {
2239
2240
croak " inconsistent .rev_map\n " ;
2240
2241
}
2241
2242
}
2242
2243
if ($last_rev >= $rev ) {
2243
2244
croak " last_rev is higher!: $last_rev >= $rev " ;
2244
2245
}
2245
- $wr_offset = -24 ;
2246
+ $wr_offset = -$record_size ;
2246
2247
}
2247
2248
}
2248
2249
sysseek($fh , $wr_offset , SEEK_END) or croak " seek: $! " ;
2249
- syswrite ($fh , pack (rev_map_fmt, $rev , $commit ), 24 ) == 24 or
2250
+ syswrite ($fh , pack (rev_map_fmt, $rev , $commit ), $record_size ) == $record_size or
2250
2251
croak " write: $! " ;
2251
2252
}
2252
2253
@@ -2271,7 +2272,7 @@ sub mkfile {
2271
2272
sub rev_map_set {
2272
2273
my ($self , $rev , $commit , $update_ref , $uuid ) = @_ ;
2273
2274
defined $commit or die " missing arg3\n " ;
2274
- length $commit == 40 or die " arg3 must be a full SHA1 hexsum \n " ;
2275
+ $commit =~ / ^ $: :oid $ / or die " arg3 must be a full hex object ID \n " ;
2275
2276
my $db = $self -> map_path($uuid );
2276
2277
my $db_lock = " $db .lock" ;
2277
2278
my $sigmask ;
@@ -2344,29 +2345,30 @@ sub rev_map_max {
2344
2345
2345
2346
sub rev_map_max_norebuild {
2346
2347
my ($self , $want_commit ) = @_ ;
2348
+ my $record_size = ($: :oid_length / 2) + 4;
2347
2349
my $map_path = $self -> map_path;
2348
2350
stat $map_path or return $want_commit ? (0, undef ) : 0;
2349
2351
sysopen (my $fh , $map_path , O_RDONLY) or croak " open: $! " ;
2350
2352
binmode $fh or croak " binmode: $! " ;
2351
2353
my $size = (stat ($fh ))[7];
2352
- ($size % 24 ) == 0 or croak " inconsistent size: $size " ;
2354
+ ($size % $record_size ) == 0 or croak " inconsistent size: $size " ;
2353
2355
2354
2356
if ($size == 0) {
2355
2357
close $fh or croak " close: $! " ;
2356
2358
return $want_commit ? (0, undef ) : 0;
2357
2359
}
2358
2360
2359
- sysseek($fh , -24 , SEEK_END) or croak " seek: $! " ;
2360
- sysread ($fh , my $buf , 24 ) == 24 or croak " read: $! " ;
2361
+ sysseek($fh , -$record_size , SEEK_END) or croak " seek: $! " ;
2362
+ sysread ($fh , my $buf , $record_size ) == $record_size or croak " read: $! " ;
2361
2363
my ($r , $c ) = unpack (rev_map_fmt, $buf );
2362
- if ($want_commit && $c eq (' 0' x 40 )) {
2363
- if ($size < 48 ) {
2364
+ if ($want_commit && $c eq (' 0' x $: :oid_length )) {
2365
+ if ($size < $record_size * 2 ) {
2364
2366
return $want_commit ? (0, undef ) : 0;
2365
2367
}
2366
- sysseek($fh , -48 , SEEK_END) or croak " seek: $! " ;
2367
- sysread ($fh , $buf , 24 ) == 24 or croak " read: $! " ;
2368
+ sysseek($fh , -( $record_size * 2) , SEEK_END) or croak " seek: $! " ;
2369
+ sysread ($fh , $buf , $record_size ) == $record_size or croak " read: $! " ;
2368
2370
($r , $c ) = unpack (rev_map_fmt, $buf );
2369
- if ($c eq (' 0' x 40 )) {
2371
+ if ($c eq (' 0' x $: :oid_length )) {
2370
2372
croak " Penultimate record is all-zeroes in $map_path " ;
2371
2373
}
2372
2374
}
@@ -2387,30 +2389,31 @@ sub rev_map_get {
2387
2389
2388
2390
sub _rev_map_get {
2389
2391
my ($fh , $rev ) = @_ ;
2392
+ my $record_size = ($: :oid_length / 2) + 4;
2390
2393
2391
2394
binmode $fh or croak " binmode: $! " ;
2392
2395
my $size = (stat ($fh ))[7];
2393
- ($size % 24 ) == 0 or croak " inconsistent size: $size " ;
2396
+ ($size % $record_size ) == 0 or croak " inconsistent size: $size " ;
2394
2397
2395
2398
if ($size == 0) {
2396
2399
return undef ;
2397
2400
}
2398
2401
2399
- my ($l , $u ) = (0, $size - 24 );
2402
+ my ($l , $u ) = (0, $size - $record_size );
2400
2403
my ($r , $c , $buf );
2401
2404
2402
2405
while ($l <= $u ) {
2403
- my $i = int (($l /24 + $u /24 ) / 2) * 24 ;
2406
+ my $i = int (($l /$record_size + $u /$record_size ) / 2) * $record_size ;
2404
2407
sysseek($fh , $i , SEEK_SET) or croak " seek: $! " ;
2405
- sysread ($fh , my $buf , 24 ) == 24 or croak " read: $! " ;
2408
+ sysread ($fh , my $buf , $record_size ) == $record_size or croak " read: $! " ;
2406
2409
my ($r , $c ) = unpack (rev_map_fmt, $buf );
2407
2410
2408
2411
if ($r < $rev ) {
2409
- $l = $i + 24 ;
2412
+ $l = $i + $record_size ;
2410
2413
} elsif ($r > $rev ) {
2411
- $u = $i - 24 ;
2414
+ $u = $i - $record_size ;
2412
2415
} else { # $r == $rev
2413
- return $c eq (' 0' x 40 ) ? undef : $c ;
2416
+ return $c eq (' 0' x $: :oid_length ) ? undef : $c ;
2414
2417
}
2415
2418
}
2416
2419
undef ;
0 commit comments