1

私は現在、いくつかのディレクトリ内のテキストファイルの変更を追跡するためにsvnを使用しています。以下のコード(プログラム全体の一部)を使用して、現在のリビジョン番号を抽出し、xmlを使用してperl/cgiスクリプトに表示しています。私の目標は、過去24時間(または1日)に変更されたsvnリビジョンに対して異なる色の番号を表示することです。svn--recursive関数でそれを行う方法があると思いました。特定の日付の見方は知っていますが、これは常に更新されています。

my $SVNInfoXML=`svn --recursive --xml info data/text/`;
my $SVNInfo=XMLin($SVNInfoXML);
my %FileInfo=();my $SVNLatestRev=0;
for my $entry (@{$SVNInfo->{entry}}) {
    $FileInfo{File::Basename::basename($entry->{path},'.diff')}=$entry;
    $SVNLatestRev=($entry->{revision}>$SVNLatestRev)?$entry->{revision}:$SVNLatestRev;}

プログラムの後半で、最新のsvnリビジョン番号を表示するテーブルをHTMLで印刷します。ただし、数だけでなく、最終日に改訂されたかどうかも確認する必要があります。

4

1 に答える 1

2

これは 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_time24時間前です。

を使用すると、出力の形式を便利な構造体に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"
    }
}
于 2012-07-20T02:14:21.657 に答える