about summary refs log tree commit homepage
path: root/t
diff options
context:
space:
mode:
authorEric Wong <e@yhbt.net>2020-03-20 08:18:13 +0000
committerEric Wong <e@yhbt.net>2020-03-22 09:00:23 +0000
commit8e81d6f0d44198717ae540421a09824d75c9bb6d (patch)
tree754d15673307a90dcba5aa4cb088f7cbcd2ece49 /t
parentc29b2b7ded47def906cf00e3baad65c102304120 (diff)
downloadpublic-inbox-8e81d6f0d44198717ae540421a09824d75c9bb6d.tar.gz
When indexing messages without Date: and/or Received: headers,
fall back to using timestamps originally recorded by git in the
commit object.  This allows git mirrors to preserve the import
datestamp and timestamp of a message according to what was fed
into git, instead of blindly falling back to the current time.
Diffstat (limited to 't')
-rw-r--r--t/index-git-times.t93
1 files changed, 93 insertions, 0 deletions
diff --git a/t/index-git-times.t b/t/index-git-times.t
new file mode 100644
index 00000000..2e9e88e8
--- /dev/null
+++ b/t/index-git-times.t
@@ -0,0 +1,93 @@
+# Copyright (C) 2020 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+use Test::More;
+use PublicInbox::TestCommon;
+use PublicInbox::Import;
+use PublicInbox::Config;
+use File::Path qw(remove_tree);
+
+require_mods(qw(DBD::SQLite Search::Xapian));
+use_ok 'PublicInbox::Over';
+
+my ($tmpdir, $for_destroy) = tmpdir();
+local $ENV{PI_CONFIG} = "$tmpdir/cfg";
+my $v1dir = "$tmpdir/v1";
+my $addr = 'x@example.com';
+run_script(['-init', '--indexlevel=medium', 'v1', $v1dir,
+                'http://example.com/x', $addr])
+        or die "init failed";
+
+{
+        my $data = <<'EOF';
+blob
+mark :1
+data 133
+From: timeless <t@example.com>
+To: x <x@example.com>
+Subject: can I haz the time?
+Message-ID: <19700101000000-1234@example.com>
+
+plz
+
+reset refs/heads/master
+commit refs/heads/master
+mark :2
+author timeless <t@example.com> 749520000 +0100
+committer x <x@example.com> 1285977600 -0100
+data 20
+can I haz the time?
+M 100644 :1 53/256f6177504c2878d3a302ef5090dacf5e752c
+
+EOF
+        pipe(my($r, $w)) or die;
+        length($data) <= 512 or die "data too large to fit in POSIX pipe";
+        print $w $data or die;
+        close $w or die;
+        my $cmd = ['git', "--git-dir=$v1dir", 'fast-import', '--quiet'];
+        PublicInbox::Import::run_die($cmd, undef, { 0 => $r });
+}
+
+run_script(['-index', $v1dir]) or die 'v1 index failed';
+my $smsg;
+{
+        my $cfg = PublicInbox::Config->new;
+        my $ibx = $cfg->lookup($addr);
+        $smsg = $ibx->over->get_art(1);
+        is($smsg->{ds}, 749520000, 'datestamp from git author time');
+        is($smsg->{ts}, 1285977600, 'timestamp from git committer time');
+        my $res = $ibx->search->query("m:$smsg->{mid}");
+        is(scalar @$res, 1, 'got one result for m:');
+        is($res->[0]->{ds}, $smsg->{ds}, 'Xapian stored datestamp');
+        $res = $ibx->search->query('d:19931002..19931002');
+        is(scalar @$res, 1, 'got one result for d:');
+        is($res->[0]->{ds}, $smsg->{ds}, 'Xapian search on datestamp');
+}
+SKIP: {
+        require_git(2.6, 1) or skip('git 2.6+ required for v2', 10);
+        my $v2dir = "$tmpdir/v2";
+        run_script(['-convert', $v1dir, $v2dir]) or die 'v2 conversion failed';
+
+        my $check_v2 = sub {
+                my $ibx = PublicInbox::Inbox->new({inboxdir => $v2dir,
+                                address => $addr});
+                my $v2smsg = $ibx->over->get_art(1);
+                is($v2smsg->{ds}, $smsg->{ds},
+                        'v2 datestamp from git author time');
+                is($v2smsg->{ts}, $smsg->{ts},
+                        'v2 timestamp from git committer time');
+                my $res = $ibx->search->query("m:$smsg->{mid}");
+                is($res->[0]->{ds}, $smsg->{ds}, 'Xapian stored datestamp');
+                $res = $ibx->search->query('d:19931002..19931002');
+                is(scalar @$res, 1, 'got one result for d:');
+                is($res->[0]->{ds}, $smsg->{ds}, 'Xapian search on datestamp');
+        };
+        $check_v2->();
+        remove_tree($v2dir);
+
+        # test non-parallelized conversion
+        run_script(['-convert', '-j0', $v1dir, $v2dir]) or
+                die 'v2 conversion failed';
+        $check_v2->();
+}
+
+done_testing;