@@ -2,7 +2,7 @@ package Git::SVN;
22use strict;
33use warnings;
44use Fcntl qw/ :DEFAULT :seek/ ;
5- use constant rev_map_fmt => ' NH40 ' ;
5+ use constant rev_map_fmt => ' NH* ' ;
66use vars qw/ $_no_metadata
77 $_repack $_repack_flags $_use_svm_props $_head
88 $_use_svnsync_props $no_reuse_existing
@@ -2087,10 +2087,10 @@ sub rebuild_from_rev_db {
20872087 open my $fh , ' <' , $path or croak " open: $! " ;
20882088 binmode $fh or croak " binmode: $! " ;
20892089 while (<$fh >) {
2090- length ($_ ) == 41 or croak " inconsistent size in ($_ ) != 41 " ;
2090+ length ($_ ) == $: :oid_length + 1 or croak " inconsistent size in ($_ )" ;
20912091 chomp ($_ );
20922092 ++$r ;
2093- next if $_ eq (' 0' x 40 );
2093+ next if $_ eq (' 0' x $: :oid_length );
20942094 $self -> rev_map_set($r , $_ );
20952095 print " r$r = $_ \n " ;
20962096 }
@@ -2196,9 +2196,9 @@ sub rebuild {
21962196# (mainly tags)
21972197#
21982198# The format is this:
2199- # - 24 bytes for every record,
2199+ # - 24 or 36 bytes for every record,
22002200# * 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
22022202# - No empty padding records like the old format
22032203# (except the last record, which can be overwritten)
22042204# - new records are written append-only since SVN revision numbers
@@ -2207,46 +2207,47 @@ sub rebuild {
22072207# - Piping the file to xxd -c24 is a good way of dumping it for
22082208# viewing or editing (piped back through xxd -r), should the need
22092209# 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
22112211# This is used to optimize fetch performance when using multiple
22122212# "fetch" directives in .git/config
22132213#
22142214# These files are disposable unless noMetadata or useSvmProps is set
22152215
22162216sub _rev_map_set {
22172217 my ($fh , $rev , $commit ) = @_ ;
2218+ my $record_size = ($: :oid_length / 2) + 4;
22182219
22192220 binmode $fh or croak " binmode: $! " ;
22202221 my $size = (stat ($fh ))[7];
2221- ($size % 24 ) == 0 or croak " inconsistent size: $size " ;
2222+ ($size % $record_size ) == 0 or croak " inconsistent size: $size " ;
22222223
22232224 my $wr_offset = 0;
22242225 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 )" ;
22282229 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
22332234 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 )" ;
22362237 ($last_rev , $last_commit ) =
22372238 unpack (rev_map_fmt, $buf );
2238- if ($last_commit eq (' 0' x 40 )) {
2239+ if ($last_commit eq (' 0' x $: :oid_length )) {
22392240 croak " inconsistent .rev_map\n " ;
22402241 }
22412242 }
22422243 if ($last_rev >= $rev ) {
22432244 croak " last_rev is higher!: $last_rev >= $rev " ;
22442245 }
2245- $wr_offset = -24 ;
2246+ $wr_offset = -$record_size ;
22462247 }
22472248 }
22482249 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
22502251 croak " write: $! " ;
22512252}
22522253
@@ -2271,7 +2272,7 @@ sub mkfile {
22712272sub rev_map_set {
22722273 my ($self , $rev , $commit , $update_ref , $uuid ) = @_ ;
22732274 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 " ;
22752276 my $db = $self -> map_path($uuid );
22762277 my $db_lock = " $db .lock" ;
22772278 my $sigmask ;
@@ -2344,29 +2345,30 @@ sub rev_map_max {
23442345
23452346sub rev_map_max_norebuild {
23462347 my ($self , $want_commit ) = @_ ;
2348+ my $record_size = ($: :oid_length / 2) + 4;
23472349 my $map_path = $self -> map_path;
23482350 stat $map_path or return $want_commit ? (0, undef ) : 0;
23492351 sysopen (my $fh , $map_path , O_RDONLY) or croak " open: $! " ;
23502352 binmode $fh or croak " binmode: $! " ;
23512353 my $size = (stat ($fh ))[7];
2352- ($size % 24 ) == 0 or croak " inconsistent size: $size " ;
2354+ ($size % $record_size ) == 0 or croak " inconsistent size: $size " ;
23532355
23542356 if ($size == 0) {
23552357 close $fh or croak " close: $! " ;
23562358 return $want_commit ? (0, undef ) : 0;
23572359 }
23582360
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: $! " ;
23612363 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 ) {
23642366 return $want_commit ? (0, undef ) : 0;
23652367 }
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: $! " ;
23682370 ($r , $c ) = unpack (rev_map_fmt, $buf );
2369- if ($c eq (' 0' x 40 )) {
2371+ if ($c eq (' 0' x $: :oid_length )) {
23702372 croak " Penultimate record is all-zeroes in $map_path " ;
23712373 }
23722374 }
@@ -2387,30 +2389,31 @@ sub rev_map_get {
23872389
23882390sub _rev_map_get {
23892391 my ($fh , $rev ) = @_ ;
2392+ my $record_size = ($: :oid_length / 2) + 4;
23902393
23912394 binmode $fh or croak " binmode: $! " ;
23922395 my $size = (stat ($fh ))[7];
2393- ($size % 24 ) == 0 or croak " inconsistent size: $size " ;
2396+ ($size % $record_size ) == 0 or croak " inconsistent size: $size " ;
23942397
23952398 if ($size == 0) {
23962399 return undef ;
23972400 }
23982401
2399- my ($l , $u ) = (0, $size - 24 );
2402+ my ($l , $u ) = (0, $size - $record_size );
24002403 my ($r , $c , $buf );
24012404
24022405 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 ;
24042407 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: $! " ;
24062409 my ($r , $c ) = unpack (rev_map_fmt, $buf );
24072410
24082411 if ($r < $rev ) {
2409- $l = $i + 24 ;
2412+ $l = $i + $record_size ;
24102413 } elsif ($r > $rev ) {
2411- $u = $i - 24 ;
2414+ $u = $i - $record_size ;
24122415 } else { # $r == $rev
2413- return $c eq (' 0' x 40 ) ? undef : $c ;
2416+ return $c eq (' 0' x $: :oid_length ) ? undef : $c ;
24142417 }
24152418 }
24162419 undef ;
0 commit comments