user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
* [PATCH] git: use "git rev-parse --git-path"
@ 2019-01-30  8:49 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2019-01-30  8:49 UTC (permalink / raw)
  To: meta

Using git worktrees was causing t/solver_git.t to fail on me.
---
 lib/PublicInbox/Git.pm       | 16 +++++++++++++---
 lib/PublicInbox/SolverGit.pm |  5 +++--
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm
index 3ad0811..e844884 100644
--- a/lib/PublicInbox/Git.pm
+++ b/lib/PublicInbox/Git.pm
@@ -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
diff --git a/lib/PublicInbox/SolverGit.pm b/lib/PublicInbox/SolverGit.pm
index d787533..59d2c93 100644
--- a/lib/PublicInbox/SolverGit.pm
+++ b/lib/PublicInbox/SolverGit.pm
@@ -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};
-- 
EW


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2019-01-30  8:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-30  8:49 [PATCH] git: use "git rev-parse --git-path" Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).