]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Git.pm
No ext_urls
[public-inbox.git] / lib / PublicInbox / Git.pm
index 70adfd4522bd1f0624352173dbb039f95ceef154..2729b38fd9c0404295953b06486b613d1712fb4b 100644 (file)
@@ -20,7 +20,7 @@ use PublicInbox::Spawn qw(popen_rd which);
 use PublicInbox::Tmpfile;
 use IO::Poll qw(POLLIN);
 use Carp qw(croak carp);
-use Digest::SHA ();
+use PublicInbox::SHA ();
 use PublicInbox::DS qw(awaitpid);
 our @EXPORT_OK = qw(git_unquote git_quote);
 our $PIPE_BUFSIZ = 65536; # Linux default
@@ -52,6 +52,11 @@ my %ESC_GIT = map { $GIT_ESC{$_} => $_ } keys %GIT_ESC;
 my $EXE_ST = ''; # pack('dd', st_ctime, st_size);
 my ($GIT_EXE, $GIT_VER);
 
+sub version {
+       check_git_exe();
+       $GIT_VER;
+}
+
 sub check_git_exe () {
        $GIT_EXE = which('git') // die "git not found in $ENV{PATH}";
        my @st = stat($GIT_EXE) or die "stat: $!";
@@ -340,11 +345,9 @@ sub check_async_step ($$) {
        chomp(my $line = my_readline($self->{in_c}, $rbuf));
        my ($hex, $type, $size) = split(/ /, $line);
 
-       # Future versions of git.git may have type=ambiguous, but for now,
-       # we must handle 'dangling' below (and maybe some other oddball
-       # stuff):
+       # git <2.21 would show `dangling' (2.21+ shows `ambiguous')
        # https://public-inbox.org/git/20190118033845.s2vlrb3wd3m2jfzu@dcvr/T/
-       if ($hex eq 'dangling' || $hex eq 'notdir' || $hex eq 'loop') {
+       if ($hex eq 'dangling') {
                my $ret = my_read($self->{in_c}, $rbuf, $type + 1);
                $self->fail(defined($ret) ? 'read EOF' : "read: $!") if !$ret;
        }
@@ -419,12 +422,9 @@ sub check {
        check_async_wait($self);
        my ($hex, $type, $size) = @$result;
 
-       # Future versions of git.git may show 'ambiguous', but for now,
-       # we must handle 'dangling' below (and maybe some other oddball
-       # stuff):
+       # git <2.21 would show `dangling' (2.21+ shows `ambiguous')
        # https://public-inbox.org/git/20190118033845.s2vlrb3wd3m2jfzu@dcvr/T/
-       return if $type eq 'missing' || $type eq 'ambiguous';
-       return if $hex eq 'dangling' || $hex eq 'notdir' || $hex eq 'loop';
+       return if $type =~ /\A(?:missing|ambiguous)\z/ || $hex eq 'dangling';
        ($hex, $type, $size);
 }
 
@@ -635,7 +635,7 @@ sub cloneurl {
 sub manifest_entry {
        my ($self, $epoch, $default_desc) = @_;
        my $fh = $self->popen('show-ref');
-       my $dig = Digest::SHA->new(1);
+       my $dig = PublicInbox::SHA->new(1);
        while (read($fh, my $buf, 65536)) {
                $dig->add($buf);
        }