これは Perl スクリプトです。右?
Perl に 24 時間前の時刻Time::Piece
を割り出させてから、Subversion の日付を解析するために使用してみませんか?
svn info
実際、単に ではなく、なぜ使用しているのですかsvn log --xml
。これにより、すべての変更の履歴が得られます。各日付を見て、古い日付と一致するかどうかを確認するだけです。
24 時間前の時刻を取得するには、次のようにします。
use Time::Piece
use Time::Seconds #Constants that come in handy
my $current_time = localtime;
my $yesterday_time = $current_time - ONE_DAY;
今、$yesterday_time
24時間前です。
を使用すると、出力の形式を便利な構造体にXML::Simple
変換できます。svn log --xml $file
これが私が書いた簡単なテストプログラムです:
#! /usr/bin/perl
use strict;
use warnings;
use autodie;
use feature qw(say);
use XML::Simple qw(xml_in xml_out);
use Time::Piece;
use Time::Seconds;
my $file_name = "?Some Name?";
my $now = localtime;
my $yesterday_time = $now - ONE_DAY;
open (my $xml_file, "-|", qq(svn log --xml "$file_name"));
my $xml = xml_in($xml_file);
# XML is a reference to a hash with a single key 'logentry'
# This points to a reference to an array and each entry is
# a reference to a hash that contains the four pieces to the
# log entry.
my $entries_ref = $xml->{logentry};
foreach my $entry (@{$entries_ref}) {
# Each entry is a reference to a hash
my $revision = $entry->{revision};
my $author = $entry->{author};
my $date = $entry->{date};
my $message = $entry->{msg};
# For giggles, we print out the four items.
# In truth, there could be more than four items
# in the hash if there was also a revprop too.
say "$revision: $author: $date: $message";
# The date is in 100,000 of a second. We need to get
# rid of everything on the other side of the seconds
# decimal before we manipulate it.
$date =~ s/\.\d+Z$//; # Get rid of 10,000 of seconds
# Now, we can convert the "svn log" date to a Time::Piece
my $rev_date = Time::Piece->strptime($date, "%Y-%m-%dT%H:%M:%S");
# Compare the rev date to the $yesterday_time date
if ($rev_date < $yesterday_time) {
say "Revision $revision is older than one day"
}
}