about summary refs log tree commit homepage
path: root/script/public-inbox-index
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-02-27 21:57:57 +0000
committerEric Wong <e@80x24.org>2016-02-27 21:57:57 +0000
commit052f26f3ada1042afa5acadbecc48b487f4e2d52 (patch)
treeb6b30f94cdb20534ffc074359db30084c9858fa6 /script/public-inbox-index
parent617f35dacbd4e5972bf2d82411b45009bbc79a42 (diff)
downloadpublic-inbox-052f26f3ada1042afa5acadbecc48b487f4e2d52.tar.gz
This seems to match more closely with what is expected of Perl
packages based on how blib is used.  Hopefully makes the top-level
source tree less cluttered and things easier-to-find.
Diffstat (limited to 'script/public-inbox-index')
-rwxr-xr-xscript/public-inbox-index65
1 files changed, 65 insertions, 0 deletions
diff --git a/script/public-inbox-index b/script/public-inbox-index
new file mode 100755
index 00000000..578d91d5
--- /dev/null
+++ b/script/public-inbox-index
@@ -0,0 +1,65 @@
+#!/usr/bin/perl -w
+# Copyright (C) 2015 all contributors <meta@public-inbox.org>
+# License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
+# Basic tool to create a Xapian search index for a git repository
+# configured for public-inbox.
+# Usage with libeatmydata <https://www.flamingspork.com/projects/libeatmydata/>
+# highly recommended: eatmydata public-inbox-index GIT_DIR
+
+use strict;
+use warnings;
+my $usage = "public-inbox-index GIT_DIR";
+use PublicInbox::Config;
+eval { require PublicInbox::SearchIdx };
+if ($@) {
+        print STDERR "Search::Xapian required for $0\n";
+        exit 1;
+}
+my @dirs;
+
+sub resolve_git_dir {
+        my ($cd) = @_;
+        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;
+                return $cd if ($dir eq '.' && defined $cd);
+                $dir;
+        }
+}
+
+if (@ARGV) {
+        @dirs = map { resolve_git_dir($_) } @ARGV;
+} else {
+        @dirs = (resolve_git_dir());
+}
+
+sub usage { print STDERR "Usage: $usage\n"; exit 1 }
+usage() unless @dirs;
+
+foreach my $dir (@dirs) {
+        index_dir($dir);
+}
+
+sub index_dir {
+        my ($git_dir) = @_;
+        -d $git_dir or die "$git_dir does not appear to be a git repository\n";
+
+        system('git', "--git-dir=$git_dir", 'update-server-info') and
+                die "git update-server-info failed for $git_dir";
+        my $s = PublicInbox::SearchIdx->new($git_dir, 1);
+        $s->index_sync;
+}