这是一个 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"
}
}