user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
blob d0a8dd00a76fb7939e507ae30f3573b88f7d0823 1033 bytes (raw)
name: lib/PublicInbox/Admin.pm 	 # note: path name is non-authoritative(*)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
 
# Copyright (C) 2019 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>

# common stuff for administrative command-line tools
# Unstable internal API
package PublicInbox::Admin;
use strict;
use warnings;
use Cwd 'abs_path';
use base qw(Exporter);
our @EXPORT_OK = qw(resolve_repo_dir);

sub resolve_repo_dir {
	my ($cd, $ver) = @_;
	my $prefix = defined $cd ? $cd : './';
	if (-d $prefix && -f "$prefix/inbox.lock") { # v2
		$$ver = 2 if $ver;
		return abs_path($prefix);
	}

	my @cmd = qw(git rev-parse --git-dir);
	my $cmd = join(' ', @cmd);
	my $pid = open my $fh, '-|';
	defined $pid or die "forking $cmd failed: $!\n";
	if ($pid == 0) {
		if (defined $cd) {
			chdir $cd or die "chdir $cd failed: $!\n";
		}
		exec @cmd;
		die "Failed to exec $cmd: $!\n";
	} else {
		my $dir = eval {
			local $/;
			<$fh>;
		};
		close $fh or die "error in $cmd: $!\n";
		chomp $dir;
		$$ver = 1 if $ver;
		return abs_path($cd) if ($dir eq '.' && defined $cd);
		abs_path($dir);
	}
}

1;

debug log:

solving d0a8dd0 ...
found d0a8dd0 in https://80x24.org/public-inbox.git

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

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).