]> Sergey Matveev's repositories - public-inbox.git/commitdiff
git: use "git rev-parse --git-path"
authorEric Wong <e@80x24.org>
Wed, 30 Jan 2019 08:47:43 +0000 (08:47 +0000)
committerEric Wong <e@80x24.org>
Wed, 30 Jan 2019 08:47:43 +0000 (08:47 +0000)
Using git worktrees was causing t/solver_git.t to fail on me.

lib/PublicInbox/Git.pm
lib/PublicInbox/SolverGit.pm

index 3ad08112e4d6f6c6237786928d0f3b768af038fb..e844884a2acf8f5d94469c65ee37d4550d455627 100644 (file)
@@ -51,12 +51,21 @@ sub new {
        my @st;
        $st[7] = $st[10] = 0;
        # may contain {-tmp} field for File::Temp::Dir
-       bless { git_dir => $git_dir, st => \@st }, $class
+       bless { git_dir => $git_dir, st => \@st, -git_path => {} }, $class
+}
+
+sub git_path ($$) {
+       my ($self, $path) = @_;
+       $self->{-git_path}->{$path} ||= do {
+               local $/ = "\n";
+               chomp(my $str = $self->qx(qw(rev-parse --git-path), $path));
+               $str;
+       };
 }
 
 sub alternates_changed {
        my ($self) = @_;
-       my $alt = "$self->{git_dir}/objects/info/alternates";
+       my $alt = git_path($self, 'objects/info/alternates');
        my @st = stat($alt) or return 0;
        my $old_st = $self->{st};
        # 10 - ctime, 7 - size
@@ -239,7 +248,8 @@ sub cleanup {
 sub packed_bytes {
        my ($self) = @_;
        my $n = 0;
-       foreach my $p (glob("$self->{git_dir}/objects/pack/*.pack")) {
+       my $pack_dir = git_path($self, 'objects/pack');
+       foreach my $p (glob("$pack_dir/*.pack")) {
                $n += -s $p;
        }
        $n
index d7875333af9cec3dcc4f5df20aeda4e185a3a316..59d2c93ca4274af1b831e9b15a1a86e9cb8bd538 100644 (file)
@@ -272,8 +272,9 @@ EOF
 
        my $f = 'objects/info/alternates';
        open $fh, '>', "$git_dir/$f" or die "open: $f: $!";
-       print($fh (map { "$_->{git_dir}/objects\n" } @{$self->{gits}})) or
-               die "print $f: $!";
+       foreach my $git (@{$self->{gits}}) {
+               print $fh $git->git_path('objects'),"\n" or die "print $f: $!";
+       }
        close $fh or die "close: $f: $!";
        my $tmp_git = $self->{tmp_git} = PublicInbox::Git->new($git_dir);
        $tmp_git->{-tmp} = $self->{tmp};