]> Sergey Matveev's repositories - public-inbox.git/blob - t/index-git-times.t
www: drop --subject from "git send-email" instructions
[public-inbox.git] / t / index-git-times.t
1 #!perl -w
2 # Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 use strict;
5 use v5.10.1;
6 use Test::More;
7 use PublicInbox::TestCommon;
8 use PublicInbox::Config;
9 use PublicInbox::Admin;
10 use PublicInbox::Import;
11 use File::Path qw(remove_tree);
12
13 require_mods(qw(DBD::SQLite Search::Xapian));
14 use_ok 'PublicInbox::Over';
15
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 my $default_branch = PublicInbox::Import::default_branch;
21 run_script(['-init', '--indexlevel=medium', 'v1', $v1dir,
22                 'http://example.com/x', $addr])
23         or die "init failed";
24
25 {
26         my $data = <<"EOF";
27 blob
28 mark :1
29 data 133
30 From: timeless <t\@example.com>
31 To: x <x\@example.com>
32 Subject: can I haz the time?
33 Message-ID: <19700101000000-1234\@example.com>
34
35 plz
36
37 reset $default_branch
38 commit $default_branch
39 mark :2
40 author timeless <t\@example.com> 749520000 +0100
41 committer x <x\@example.com> 1285977600 -0100
42 data 20
43 can I haz the time?
44 M 100644 :1 53/256f6177504c2878d3a302ef5090dacf5e752c
45
46 EOF
47         pipe(my($r, $w)) or die;
48         length($data) <= 512 or die "data too large to fit in POSIX pipe";
49         print $w $data or die;
50         close $w or die;
51         my $cmd = ['git', "--git-dir=$v1dir", 'fast-import', '--quiet'];
52         xsys_e($cmd, undef, { 0 => $r });
53 }
54
55 run_script(['-index', '--skip-docdata', $v1dir]) or die 'v1 index failed';
56
57 my $smsg;
58 {
59         my $cfg = PublicInbox::Config->new;
60         my $ibx = $cfg->lookup($addr);
61         my $lvl = PublicInbox::Admin::detect_indexlevel($ibx);
62         is($lvl, 'medium', 'indexlevel detected');
63         is($ibx->{-skip_docdata}, 1, '--skip-docdata flag set on -index');
64         $smsg = $ibx->over->get_art(1);
65         is($smsg->{ds}, 749520000, 'datestamp from git author time');
66         is($smsg->{ts}, 1285977600, 'timestamp from git committer time');
67         my $mset = $ibx->search->mset("m:$smsg->{mid}");
68         is($mset->size, 1, 'got one result for m:');
69         my $res = $ibx->search->mset_to_smsg($ibx, $mset);
70         is($res->[0]->{ds}, $smsg->{ds}, 'Xapian stored datestamp');
71         $mset = $ibx->search->mset('d:19931002..19931002');
72         $res = $ibx->search->mset_to_smsg($ibx, $mset);
73         is(scalar @$res, 1, 'got one result for d:');
74         is($res->[0]->{ds}, $smsg->{ds}, 'Xapian search on datestamp');
75 }
76 SKIP: {
77         require_git(2.6, 1) or skip('git 2.6+ required for v2', 10);
78         my $v2dir = "$tmpdir/v2";
79         run_script(['-convert', $v1dir, $v2dir]) or die 'v2 conversion failed';
80
81         my $check_v2 = sub {
82                 my $ibx = PublicInbox::Inbox->new({inboxdir => $v2dir,
83                                 address => $addr});
84                 my $lvl = PublicInbox::Admin::detect_indexlevel($ibx);
85                 is($lvl, 'medium', 'indexlevel detected after convert');
86                 is($ibx->{-skip_docdata}, 1,
87                         '--skip-docdata preserved after convert');
88                 my $v2smsg = $ibx->over->get_art(1);
89                 is($v2smsg->{ds}, $smsg->{ds},
90                         'v2 datestamp from git author time');
91                 is($v2smsg->{ts}, $smsg->{ts},
92                         'v2 timestamp from git committer time');
93                 my $mset = $ibx->search->mset("m:$smsg->{mid}");
94                 my $res = $ibx->search->mset_to_smsg($ibx, $mset);
95                 is($res->[0]->{ds}, $smsg->{ds}, 'Xapian stored datestamp');
96                 $mset = $ibx->search->mset('d:19931002..19931002');
97                 $res = $ibx->search->mset_to_smsg($ibx, $mset);
98                 is(scalar @$res, 1, 'got one result for d:');
99                 is($res->[0]->{ds}, $smsg->{ds}, 'Xapian search on datestamp');
100         };
101         $check_v2->();
102         remove_tree($v2dir);
103
104         # test non-parallelized conversion
105         run_script(['-convert', '-j0', $v1dir, $v2dir]) or
106                 die 'v2 conversion failed';
107         $check_v2->();
108 }
109
110 done_testing;