user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] git: use "git rev-parse --git-path"
Date: Wed, 30 Jan 2019 08:49:43 +0000	[thread overview]
Message-ID: <20190130084943.15729-1-e@80x24.org> (raw)

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


                 reply	other threads:[~2019-01-30  8:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190130084943.15729-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).