user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH 4/5] fetch|clone|--mirror: shorten paths for progress output
  2021-09-15 21:35  7% [PATCH 0/5] make(1) inspired things Eric Wong
@ 2021-09-15 21:35  5% ` Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2021-09-15 21:35 UTC (permalink / raw)
  To: meta

The full pathname for "curl -o ..." was too noisy and confusing.
Reduce confusion by adding the ".tmp" suffix and relying on
"-C".  We'll also avoid displaying "-C" in run_reap() and
rely on "--git-dir=" with "git fetch" to display progress for
users.
---
 lib/PublicInbox/Fetch.pm     | 18 +++++++++---------
 lib/PublicInbox/LeiMirror.pm | 12 +++++++-----
 t/lei-mirror.t               |  8 ++++----
 3 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/lib/PublicInbox/Fetch.pm b/lib/PublicInbox/Fetch.pm
index 184b4f26..993e5b19 100644
--- a/lib/PublicInbox/Fetch.pm
+++ b/lib/PublicInbox/Fetch.pm
@@ -15,9 +15,9 @@ use File::Temp ();
 
 sub new { bless {}, __PACKAGE__ }
 
-sub fetch_cmd ($$) {
+sub fetch_args ($$) {
 	my ($lei, $opt) = @_;
-	my @cmd = qw(git);
+	my @cmd; # (git --git-dir=...) to be added by caller
 	$opt->{$_} = $lei->{$_} for (0..2);
 	# we support "-c $key=$val" for arbitrary git config options
 	# e.g.: git -c http.proxy=socks5h://127.0.0.1:9050
@@ -41,10 +41,9 @@ sub remote_url ($$) {
 sub do_manifest ($$$) {
 	my ($lei, $dir, $ibx_uri) = @_;
 	my $muri = URI->new("$ibx_uri/manifest.js.gz");
-	my $ft = File::Temp->new(TEMPLATE => 'manifest-XXXX',
-				UNLINK => 1, DIR => $dir);
+	my $ft = File::Temp->new(TEMPLATE => 'm-XXXX',
+				UNLINK => 1, DIR => $dir, SUFFIX => '.tmp');
 	my $fn = $ft->filename;
-	my @opt = (qw(-R -o), $fn);
 	my $mf = "$dir/manifest.js.gz";
 	my $m0; # current manifest.js.gz contents
 	if (open my $fh, '<', $mf) {
@@ -53,8 +52,9 @@ sub do_manifest ($$$) {
 		};
 		$lei->err($@) if $@;
 	}
-	my $curl_cmd = $lei->{curl}->for_uri($lei, $muri, @opt);
-	my $opt = {};
+	my ($bn) = ($fn =~ m!/([^/]+)\z!);
+	my $curl_cmd = $lei->{curl}->for_uri($lei, $muri, qw(-R -o), $bn);
+	my $opt = { -C => $dir };
 	$opt->{$_} = $lei->{$_} for (0..2);
 	my $cerr = PublicInbox::LeiMirror::run_reap($lei, $curl_cmd, $opt);
 	if ($cerr) {
@@ -153,9 +153,9 @@ EOM
 		my $cmd;
 		my $opt = {}; # for spawn
 		if (-d $d) {
-			$opt->{-C} = $d;
 			$fp2->[0] = get_fingerprint2($d) if $fp2;
-			$cmd = [ @$torsocks, fetch_cmd($lei, $opt) ];
+			$cmd = [ @$torsocks, 'git', "--git-dir=$d",
+				fetch_args($lei, $opt) ];
 		} else {
 			my $e_uri = $ibx_uri->clone;
 			my ($epath) = ($d =~ m!(/git/[0-9]+\.git)\z!);
diff --git a/lib/PublicInbox/LeiMirror.pm b/lib/PublicInbox/LeiMirror.pm
index 749c6b7d..0e048070 100644
--- a/lib/PublicInbox/LeiMirror.pm
+++ b/lib/PublicInbox/LeiMirror.pm
@@ -181,7 +181,7 @@ sub index_cloned_inbox {
 
 sub run_reap {
 	my ($lei, $cmd, $opt) = @_;
-	$lei->qerr("# @$cmd" . ($opt->{-C} ? " (in $opt->{-C})" : ''));
+	$lei->qerr("# @$cmd");
 	$opt->{pgid} = 0 if $lei->{sock};
 	my $pid = spawn($cmd, undef, $opt);
 	my $reap = PublicInbox::OnDestroy->new($lei->can('sigint_reap'), $pid);
@@ -276,11 +276,13 @@ sub try_manifest {
 	$uri->path($path . '/manifest.js.gz');
 	my $pdir = $lei->rel2abs($self->{dst});
 	$pdir =~ s!/[^/]+/?\z!!;
-	my $ft = File::Temp->new(TEMPLATE => 'manifest-XXXX',
-				UNLINK => 1, DIR => $pdir);
+	my $ft = File::Temp->new(TEMPLATE => 'm-XXXX',
+				UNLINK => 1, DIR => $pdir, SUFFIX => '.tmp');
 	my $fn = $ft->filename;
-	my $cmd = $curl->for_uri($lei, $uri, '-R', '-o', $fn);
-	my $opt = { 0 => $lei->{0}, 1 => $lei->{1}, 2 => $lei->{2} };
+	my ($bn) = ($fn =~ m!/([^/]+)\z!);
+	my $cmd = $curl->for_uri($lei, $uri, '-R', '-o', $bn);
+	my $opt = { -C => $pdir };
+	$opt->{$_} = $lei->{$_} for (0..2);
 	my $cerr = run_reap($lei, $cmd, $opt);
 	if ($cerr) {
 		return try_scrape($self) if ($cerr >> 8) == 22; # 404 missing
diff --git a/t/lei-mirror.t b/t/lei-mirror.t
index 3eb7f36a..7dd03b26 100644
--- a/t/lei-mirror.t
+++ b/t/lei-mirror.t
@@ -116,12 +116,12 @@ SKIP: {
 	ok(!run_script([qw(-fetch --exit-code -C), "$d/t2"], undef, $opt),
 		'-fetch succeeds w/ manifest.js.gz');
 	is($? >> 8, 127, '--exit-code gave 127');
-	unlike($err, qr/git fetch/, 'no fetch done w/ manifest');
+	unlike($err, qr/git --git-dir=\S+ fetch/, 'no fetch done w/ manifest');
 	unlink("$d/t2/manifest.js.gz") or xbail "unlink $!";
 	ok(!run_script([qw(-fetch --exit-code -C), "$d/t2"], undef, $opt),
 		'-fetch succeeds w/o manifest.js.gz');
 	is($? >> 8, 127, '--exit-code gave 127');
-	like($err, qr/git fetch/, 'fetch forced w/o manifest');
+	like($err, qr/git --git-dir=\S+ fetch/, 'fetch forced w/o manifest');
 
 	ok(run_script([qw(-clone -q -C), $d, "$http/t1"], undef, $opt),
 		'cloning v1 works');
@@ -131,14 +131,14 @@ SKIP: {
 	ok(!run_script([qw(-fetch --exit-code -C), "$d/t1"], undef, $opt),
 		'fetching v1 works');
 	is($? >> 8, 127, '--exit-code gave 127');
-	unlike($err, qr/git fetch/, 'no fetch done w/ manifest');
+	unlike($err, qr/git --git-dir=\S+ fetch/, 'no fetch done w/ manifest');
 	unlink("$d/t1/manifest.js.gz") or xbail "unlink $!";
 	my $before = [ glob("$d/t1/*") ];
 	ok(!run_script([qw(-fetch --exit-code -C), "$d/t1"], undef, $opt),
 		'fetching v1 works w/o manifest.js.gz');
 	is($? >> 8, 127, '--exit-code gave 127');
 	unlink("$d/t1/FETCH_HEAD"); # git internal
-	like($err, qr/git fetch/, 'no fetch done w/ manifest');
+	like($err, qr/git --git-dir=\S+ fetch/, 'no fetch done w/ manifest');
 	ok(unlink("$d/t1/manifest.js.gz"), 'manifest created');
 	my $after = [ glob("$d/t1/*") ];
 	is_deeply($before, $after, 'no new files created');

^ permalink raw reply related	[relevance 5%]

* [PATCH 0/5] make(1) inspired things
@ 2021-09-15 21:35  7% Eric Wong
  2021-09-15 21:35  5% ` [PATCH 4/5] fetch|clone|--mirror: shorten paths for progress output Eric Wong
  0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2021-09-15 21:35 UTC (permalink / raw)
  To: meta

make(1) is familiar to most, so maybe it'll help users learn
unfamiliar with public-inbox-* stuff.

Eric Wong (5):
  fetch: support --exit-code switch
  TODO: update some items
  clone|fetch|--mirror: add convenience $INBOX_DIR/Makefile
  fetch|clone|--mirror: shorten paths for progress output
  support -C (chdir) for most non-daemon commands

 Documentation/public-inbox-fetch.pod | 30 +++++++++++-
 TODO                                 | 15 ++----
 lib/PublicInbox/Fetch.pm             | 42 +++++++++++-----
 lib/PublicInbox/LeiMirror.pm         | 73 +++++++++++++++++++++++++---
 script/public-inbox-compact          |  3 +-
 script/public-inbox-convert          |  6 +--
 script/public-inbox-edit             |  3 +-
 script/public-inbox-extindex         |  3 +-
 script/public-inbox-fetch            |  4 +-
 script/public-inbox-index            |  3 +-
 script/public-inbox-init             |  4 +-
 script/public-inbox-purge            |  3 +-
 script/public-inbox-xcpdb            |  3 +-
 t/lei-mirror.t                       | 22 ++++++---
 t/v2mirror.t                         |  3 +-
 15 files changed, 167 insertions(+), 50 deletions(-)

^ permalink raw reply	[relevance 7%]

Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2021-09-15 21:35  7% [PATCH 0/5] make(1) inspired things Eric Wong
2021-09-15 21:35  5% ` [PATCH 4/5] fetch|clone|--mirror: shorten paths for progress output 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).