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