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 File::Path qw(remove_tree);
9 require_mods(qw(DBD::SQLite Search::Xapian));
10 use_ok 'PublicInbox::Over';
12 my ($tmpdir, $for_destroy) = tmpdir();
13 local $ENV{PI_CONFIG} = "$tmpdir/cfg";
14 my $v1dir = "$tmpdir/v1";
15 my $addr = 'x@example.com';
16 run_script(['-init', '--indexlevel=medium', 'v1', $v1dir,
17 'http://example.com/x', $addr])
25 From: timeless <t@example.com>
27 Subject: can I haz the time?
28 Message-ID: <19700101000000-1234@example.com>
32 reset refs/heads/master
33 commit refs/heads/master
35 author timeless <t@example.com> 749520000 +0100
36 committer x <x@example.com> 1285977600 -0100
39 M 100644 :1 53/256f6177504c2878d3a302ef5090dacf5e752c
42 pipe(my($r, $w)) or die;
43 length($data) <= 512 or die "data too large to fit in POSIX pipe";
44 print $w $data or die;
46 my $cmd = ['git', "--git-dir=$v1dir", 'fast-import', '--quiet'];
47 PublicInbox::Import::run_die($cmd, undef, { 0 => $r });
50 run_script(['-index', $v1dir]) or die 'v1 index failed';
53 my $cfg = PublicInbox::Config->new;
54 my $ibx = $cfg->lookup($addr);
55 $smsg = $ibx->over->get_art(1);
56 is($smsg->{ds}, 749520000, 'datestamp from git author time');
57 is($smsg->{ts}, 1285977600, 'timestamp from git committer time');
58 my $res = $ibx->search->query("m:$smsg->{mid}");
59 is(scalar @$res, 1, 'got one result for m:');
60 is($res->[0]->{ds}, $smsg->{ds}, 'Xapian stored datestamp');
61 $res = $ibx->search->query('d:19931002..19931002');
62 is(scalar @$res, 1, 'got one result for d:');
63 is($res->[0]->{ds}, $smsg->{ds}, 'Xapian search on datestamp');
66 require_git(2.6, 1) or skip('git 2.6+ required for v2', 10);
67 my $v2dir = "$tmpdir/v2";
68 run_script(['-convert', $v1dir, $v2dir]) or die 'v2 conversion failed';
71 my $ibx = PublicInbox::Inbox->new({inboxdir => $v2dir,
73 my $v2smsg = $ibx->over->get_art(1);
74 is($v2smsg->{ds}, $smsg->{ds},
75 'v2 datestamp from git author time');
76 is($v2smsg->{ts}, $smsg->{ts},
77 'v2 timestamp from git committer time');
78 my $res = $ibx->search->query("m:$smsg->{mid}");
79 is($res->[0]->{ds}, $smsg->{ds}, 'Xapian stored datestamp');
80 $res = $ibx->search->query('d:19931002..19931002');
81 is(scalar @$res, 1, 'got one result for d:');
82 is($res->[0]->{ds}, $smsg->{ds}, 'Xapian search on datestamp');
87 # test non-parallelized conversion
88 run_script(['-convert', '-j0', $v1dir, $v2dir]) or
89 die 'v2 conversion failed';