user/dev discussion of public-inbox itself
 help / color / Atom feed
* [PATCH] git: use "git rev-parse --git-path"
@ 2019-01-30  8:49 Eric Wong
  0 siblings, 0 replies; 1+ messages 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	[flat|nested] 1+ messages in thread

only message in thread, back to index

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

user/dev discussion of public-inbox itself

Archives are clonable:
	git clone --mirror http://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.org/gmane.mail.public-inbox.general

 note: .onion URLs require Tor: https://www.torproject.org/
       or Tor2web: https://www.tor2web.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox