From: Eric Wong Date: Mon, 21 Apr 2014 08:42:00 +0000 (+0000) Subject: ssoma: add --since option for time-limiting imports X-Git-Tag: v0.0.0~3 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=75e9eb706d6c33424287f1eb4c7fac364daab0d0;p=ssoma-mda.git ssoma: add --since option for time-limiting imports This should make it easier to avoid duplicating mail if you're coming from being a normal mailing list subscriber and switching to ssoma. --- diff --git a/lib/Ssoma/Extractor.pm b/lib/Ssoma/Extractor.pm index 9c93b43..11ad130 100644 --- a/lib/Ssoma/Extractor.pm +++ b/lib/Ssoma/Extractor.pm @@ -25,7 +25,7 @@ sub _flist { } sub _extract { - my ($self, $target) = @_; + my ($self, $target, $since) = @_; my $git = $self->{git}; # read all of the state file @@ -49,6 +49,26 @@ sub _extract { my $new; # arrayref of new file pathnames in a git tree + if (defined $since) { + my @cmd = (qw(git rev-list), "--since=$since", $tip); + my $tmp; + + # get the commit last in the list, unfortunately --reverse + # is not usable with --since + open my $rl, '-|', @cmd or die "failed to open rev-list: $!\n"; + foreach my $cmt (<$rl>) { + chomp $cmt; + + # do not re-import even if --since is specified + if (defined $last && ($last eq $cmt)) { + $tmp = undef; + last + } + $tmp = $cmt; + } + close $rl; # we may break the pipe here + $last = $tmp if defined $tmp; + } if (defined $last) { # only inject newly-added $last =~ /\A[a-f0-9]{40}\z/ or die "$lkey invalid in $state\n"; @@ -127,8 +147,8 @@ sub _imap_deliver_each_msg { } sub extract { - my ($self, $target) = @_; - $self->{git}->tmp_git_do(sub { $self->_extract($target) }); + my ($self, $target, $since) = @_; + $self->{git}->tmp_git_do(sub { $self->_extract($target, $since) }); } sub _deliver_die { diff --git a/ssoma b/ssoma index b6332fd..dabd511 100755 --- a/ssoma +++ b/ssoma @@ -35,7 +35,11 @@ our %cmd = ( "sync" => { doc => "sync target(s) for existing LISTNAME", arg => "[LISTNAME] [TARGET]", - opt => { "cron" => \$opts{cron} } + opt => { + cron => \$opts{cron}, + 'since=s' => \$opts{since}, + 'after=s' => \$opts{since}, + } }, "cat" => { doc => "show a message by Message-ID", @@ -226,6 +230,7 @@ sub do_sync { my ($dir, $targets) = @_; my $git = Ssoma::Git->new($dir); my $ex = Ssoma::Extractor->new($git); + my $since = $opts{since}; # no targets? sync all of them if (scalar(@$targets) == 0) { @@ -247,7 +252,7 @@ sub do_sync { }); foreach my $target (@$targets) { - $ex->extract($target); + $ex->extract($target, $since); } }