diff options
author | Eric Wong <e@80x24.org> | 2023-03-21 23:07:21 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2023-03-25 09:37:45 +0000 |
commit | 32fa6be4222d9af593c22a7dc101d8d5e8835511 (patch) | |
tree | 16bbac338b62675b1214bd1fceea4ca4ab2d40cd /lib/PublicInbox/TestCommon.pm | |
parent | 72dfac803728571c30e7ab8caf005229bc1f39f8 (diff) | |
download | public-inbox-32fa6be4222d9af593c22a7dc101d8d5e8835511.tar.gz |
It seems relying on root commits is a reasonable way to deduplicate and handle repositories with common history. I initially wanted to shoehorn this into extindex, but decided a separate Xapian index layout capable of being EITHER external to handle many forks or internal (in $GIT_DIR/public-inbox-cindex) for small projects is the right way to go. Unlike most existing parts of public-inbox, this relies on absolute paths of $GIT_DIR stored in the Xapian DB and does not rely on the config file. We'll be relying on the config file to map absolute paths to public URL paths for WWW.
Diffstat (limited to 'lib/PublicInbox/TestCommon.pm')
-rw-r--r-- | lib/PublicInbox/TestCommon.pm | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm index ed28ac48..494323c0 100644 --- a/lib/PublicInbox/TestCommon.pm +++ b/lib/PublicInbox/TestCommon.pm @@ -21,6 +21,7 @@ BEGIN { @EXPORT = qw(tmpdir tcp_server tcp_connect require_git require_mods run_script start_script key2sub xsys xsys_e xqx eml_load tick have_xapian_compact json_utf8 setup_public_inboxes create_inbox + create_coderepo tcp_host_port test_lei lei lei_ok $lei_out $lei_err $lei_opt test_httpd xbail require_cmd is_xdeeply tail_f ignore_inline_c_missing); @@ -325,7 +326,7 @@ sub run_script ($;$$) { } } my $tail = @tail_paths ? tail_f(@tail_paths) : undef; - if ($key =~ /-(index|convert|extindex|convert|xcpdb)\z/) { + if ($key =~ /-(index|cindex|extindex|convert|xcpdb)\z/) { unshift @argv, '--no-fsync'; } if ($run_mode == 0) { @@ -698,6 +699,44 @@ sub setup_public_inboxes () { @ret; } +our %COMMIT_ENV = ( + GIT_AUTHOR_NAME => 'A U Thor', + GIT_COMMITTER_NAME => 'C O Mitter', + GIT_AUTHOR_EMAIL => 'a@example.com', + GIT_COMMITTER_EMAIL => 'c@example.com', +); + +sub create_coderepo ($$;@) { + my $ident = shift; + my $cb = pop; + my %opt = @_; + require PublicInbox::Lock; + require PublicInbox::Import; + my ($base) = ($0 =~ m!\b([^/]+)\.[^\.]+\z!); + my ($db) = (PublicInbox::Import::default_branch() =~ m!([^/]+)\z!); + my $dir = "t/data-gen/$base.$ident-$db"; + my $new = !-d $dir; + if ($new && !mkdir($dir)) { + my $err = $!; + -d $dir or xbail "mkdir($dir): $err"; + } + my $lk = bless { lock_path => "$dir/creat.lock" }, 'PublicInbox::Lock'; + my $scope = $lk->lock_for_scope; + my $tmpdir = delete $opt{tmpdir}; + if (!-f "$dir/creat.stamp") { + opendir(my $dfh, '.') or xbail "opendir .: $!"; + chdir($dir) or xbail "chdir($dir): $!"; + local %ENV = (%ENV, %COMMIT_ENV); + $cb->($dir); + chdir($dfh) or xbail "cd -: $!"; + open my $s, '>', "$dir/creat.stamp" or + BAIL_OUT "error creating $dir/creat.stamp: $!"; + } + return $dir if !defined($tmpdir); + xsys_e([qw(/bin/cp -Rp), $dir, $tmpdir]); + $tmpdir; +} + sub create_inbox ($$;@) { my $ident = shift; my $cb = pop; |