date: make DATE_MODE thread-safe
[git.git] / perl / Git / IndexInfo.pm
blob9ee054f854e8682e16933ad0a770be5847bd33e5
1 package Git::IndexInfo;
2 use strict;
3 use warnings $ENV{GIT_PERL_FATAL_WARNINGS} ? qw(FATAL all) : ();
4 use Git qw/command_input_pipe command_close_pipe/;
6 sub new {
7 my ($class) = @_;
8 my $hash_algo = Git::config('extensions.objectformat') || 'sha1';
9 my ($gui, $ctx) = command_input_pipe(qw/update-index -z --index-info/);
10 bless { gui => $gui, ctx => $ctx, nr => 0, hash_algo => $hash_algo}, $class;
13 sub remove {
14 my ($self, $path) = @_;
15 my $length = $self->{hash_algo} eq 'sha256' ? 64 : 40;
16 if (print { $self->{gui} } '0 ', 0 x $length, "\t", $path, "\0") {
17 return ++$self->{nr};
19 undef;
22 sub update {
23 my ($self, $mode, $hash, $path) = @_;
24 if (print { $self->{gui} } $mode, ' ', $hash, "\t", $path, "\0") {
25 return ++$self->{nr};
27 undef;
30 sub DESTROY {
31 my ($self) = @_;
32 command_close_pipe($self->{gui}, $self->{ctx});