public-inbox.git  about / heads / tags
an "archives first" approach to mailing lists
blob eac2d6509b4f37bae063f0a2266f826d25661c9f 3486 bytes (raw)
$ git show HEAD:t/index-git-times.t	# shows this blob on the CLI

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
 
#!perl -w
# Copyright (C) all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
use strict;
use v5.10.1;
use PublicInbox::TestCommon;
use PublicInbox::Config;
use PublicInbox::Admin;
use PublicInbox::Import;
use File::Path qw(remove_tree);
require PublicInbox::InboxWritable;

require_mods(qw(DBD::SQLite 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';
my $default_branch = PublicInbox::Import::default_branch;
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 $default_branch
commit $default_branch
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'];
	xsys_e($cmd, undef, { 0 => $r });
}

run_script(['-index', '--skip-docdata', $v1dir]) or die 'v1 index failed';

my $smsg;
{
	my $cfg = PublicInbox::Config->new;
	my $ibx = $cfg->lookup($addr);
	my $lvl = PublicInbox::InboxWritable::detect_indexlevel($ibx);
	is($lvl, 'medium', 'indexlevel detected');
	is($ibx->{-skip_docdata}, 1, '--skip-docdata flag set on -index');
	$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 $mset = $ibx->search->mset("m:$smsg->{mid}");
	is($mset->size, 1, 'got one result for m:');
	my $res = $ibx->search->mset_to_smsg($ibx, $mset);
	is($res->[0]->{ds}, $smsg->{ds}, 'Xapian stored datestamp');
	$mset = $ibx->search->mset('d:19931002..19931002');
	$res = $ibx->search->mset_to_smsg($ibx, $mset);
	is(scalar @$res, 1, 'got one result for d:');
	is($res->[0]->{ds}, $smsg->{ds}, 'Xapian search on datestamp');
}
SKIP: {
	require_git(2.6, 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 $lvl = PublicInbox::InboxWritable::detect_indexlevel($ibx);
		is($lvl, 'medium', 'indexlevel detected after convert');
		is($ibx->{-skip_docdata}, 1,
			'--skip-docdata preserved after convert');
		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 $mset = $ibx->search->mset("m:$smsg->{mid}");
		my $res = $ibx->search->mset_to_smsg($ibx, $mset);
		is($res->[0]->{ds}, $smsg->{ds}, 'Xapian stored datestamp');
		$mset = $ibx->search->mset('d:19931002..19931002');
		$res = $ibx->search->mset_to_smsg($ibx, $mset);
		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;

git clone https://public-inbox.org/public-inbox.git
git clone http://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/public-inbox.git