Skip to content

Commit ff508e2

Browse files
bk2204gitster
authored andcommitted
perl: make Git::IndexInfo work with SHA-256
Most of the Git modules, git-svn excepted, don't know anything about the hash algorithm and mostly work. However, when we're printing an all-zero object ID in Git::IndexInfo, we need to know the hash length. Since we don't want to change the API to have that information passed in, let's query the config to find the hash algorithm and compute the right value. Signed-off-by: brian m. carlson <[email protected]> Acked-by: Eric Wong <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9ab3315 commit ff508e2

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

perl/Git/IndexInfo.pm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ use Git qw/command_input_pipe command_close_pipe/;
55

66
sub new {
77
my ($class) = @_;
8+
my $hash_algo = Git::config('extensions.objectformat') || 'sha1';
89
my ($gui, $ctx) = command_input_pipe(qw/update-index -z --index-info/);
9-
bless { gui => $gui, ctx => $ctx, nr => 0}, $class;
10+
bless { gui => $gui, ctx => $ctx, nr => 0, hash_algo => $hash_algo}, $class;
1011
}
1112

1213
sub remove {
1314
my ($self, $path) = @_;
14-
if (print { $self->{gui} } '0 ', 0 x 40, "\t", $path, "\0") {
15+
my $length = $self->{hash_algo} eq 'sha256' ? 64 : 40;
16+
if (print { $self->{gui} } '0 ', 0 x $length, "\t", $path, "\0") {
1517
return ++$self->{nr};
1618
}
1719
undef;

0 commit comments

Comments
 (0)