2 # Copyright (C) 2020 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
7 use PublicInbox::TestCommon;
8 use PublicInbox::Import;
9 use PublicInbox::Config;
10 use PublicInbox::Admin;
11 use File::Path qw(remove_tree);
13 require_mods(qw(DBD::SQLite Search::Xapian));
14 use_ok 'PublicInbox::Over';
16 my ($tmpdir, $for_destroy) = tmpdir();
17 local $ENV{PI_CONFIG} = "$tmpdir/cfg";
18 my $v1dir = "$tmpdir/v1";
19 my $addr = 'x@example.com';
20 run_script(['-init', '--indexlevel=medium', 'v1', $v1dir,
21 'http://example.com/x', $addr])
29 From: timeless <t@example.com>
31 Subject: can I haz the time?
32 Message-ID: <19700101000000-1234@example.com>
36 reset refs/heads/master
37 commit refs/heads/master
39 author timeless <t@example.com> 749520000 +0100
40 committer x <x@example.com> 1285977600 -0100
43 M 100644 :1 53/256f6177504c2878d3a302ef5090dacf5e752c
46 pipe(my($r, $w)) or die;
47 length($data) <= 512 or die "data too large to fit in POSIX pipe";
48 print $w $data or die;
50 my $cmd = ['git', "--git-dir=$v1dir", 'fast-import', '--quiet'];
51 PublicInbox::Import::run_die($cmd, undef, { 0 => $r });
54 run_script(['-index', '--skip-docdata', $v1dir]) or die 'v1 index failed';
58 my $cfg = PublicInbox::Config->new;
59 my $ibx = $cfg->lookup($addr);
60 my $lvl = PublicInbox::Admin::detect_indexlevel($ibx);
61 is($lvl, 'medium', 'indexlevel detected');
62 is($ibx->{-skip_docdata}, 1, '--skip-docdata flag set on -index');
63 $smsg = $ibx->over->get_art(1);
64 is($smsg->{ds}, 749520000, 'datestamp from git author time');
65 is($smsg->{ts}, 1285977600, 'timestamp from git committer time');
66 my $mset = $ibx->search->mset("m:$smsg->{mid}");
67 is($mset->size, 1, 'got one result for m:');
68 my $res = $ibx->search->mset_to_smsg($ibx, $mset);
69 is($res->[0]->{ds}, $smsg->{ds}, 'Xapian stored datestamp');
70 $mset = $ibx->search->mset('d:19931002..19931002');
71 $res = $ibx->search->mset_to_smsg($ibx, $mset);
72 is(scalar @$res, 1, 'got one result for d:');
73 is($res->[0]->{ds}, $smsg->{ds}, 'Xapian search on datestamp');
76 require_git(2.6, 1) or skip('git 2.6+ required for v2', 10);
77 my $v2dir = "$tmpdir/v2";
78 run_script(['-convert', $v1dir, $v2dir]) or die 'v2 conversion failed';
81 my $ibx = PublicInbox::Inbox->new({inboxdir => $v2dir,
83 my $lvl = PublicInbox::Admin::detect_indexlevel($ibx);
84 is($lvl, 'medium', 'indexlevel detected after convert');
85 is($ibx->{-skip_docdata}, 1,
86 '--skip-docdata preserved after convert');
87 my $v2smsg = $ibx->over->get_art(1);
88 is($v2smsg->{ds}, $smsg->{ds},
89 'v2 datestamp from git author time');
90 is($v2smsg->{ts}, $smsg->{ts},
91 'v2 timestamp from git committer time');
92 my $mset = $ibx->search->mset("m:$smsg->{mid}");
93 my $res = $ibx->search->mset_to_smsg($ibx, $mset);
94 is($res->[0]->{ds}, $smsg->{ds}, 'Xapian stored datestamp');
95 $mset = $ibx->search->mset('d:19931002..19931002');
96 $res = $ibx->search->mset_to_smsg($ibx, $mset);
97 is(scalar @$res, 1, 'got one result for d:');
98 is($res->[0]->{ds}, $smsg->{ds}, 'Xapian search on datestamp');
103 # test non-parallelized conversion
104 run_script(['-convert', '-j0', $v1dir, $v2dir]) or
105 die 'v2 conversion failed';