]> git.ipfire.org Git - thirdparty/git.git/blame - perl/Git/IndexInfo.pm
Merge branch 'bc/sha-256-cvs-svn-updates'
[thirdparty/git.git] / perl / Git / IndexInfo.pm
CommitLineData
10c2aa59
MS
1package Git::IndexInfo;
2use strict;
3use warnings;
4use Git qw/command_input_pipe command_close_pipe/;
5
6sub new {
7 my ($class) = @_;
ff508e22 8 my $hash_algo = Git::config('extensions.objectformat') || 'sha1';
10c2aa59 9 my ($gui, $ctx) = command_input_pipe(qw/update-index -z --index-info/);
ff508e22 10 bless { gui => $gui, ctx => $ctx, nr => 0, hash_algo => $hash_algo}, $class;
10c2aa59
MS
11}
12
13sub remove {
14 my ($self, $path) = @_;
ff508e22 15 my $length = $self->{hash_algo} eq 'sha256' ? 64 : 40;
16 if (print { $self->{gui} } '0 ', 0 x $length, "\t", $path, "\0") {
10c2aa59
MS
17 return ++$self->{nr};
18 }
19 undef;
20}
21
22sub update {
23 my ($self, $mode, $hash, $path) = @_;
24 if (print { $self->{gui} } $mode, ' ', $hash, "\t", $path, "\0") {
25 return ++$self->{nr};
26 }
27 undef;
28}
29
30sub DESTROY {
31 my ($self) = @_;
32 command_close_pipe($self->{gui}, $self->{ctx});
33}
34
351;