Skip to content

Commit

Permalink
Item12477: handle flexible switch between .changes formats
Browse files Browse the repository at this point in the history
  • Loading branch information
Comment committed Dec 20, 2014
1 parent e1584b4 commit dd7f1b5
Showing 1 changed file with 23 additions and 36 deletions.
59 changes: 23 additions & 36 deletions RCSStoreContrib/lib/Foswiki/Store/Rcs/Store.pm
Expand Up @@ -549,11 +549,11 @@ sub _readChanges {
# Old (pre 1.2) format

# Create a hash for this line
my %row = (
topic => Foswiki::Sandbox::untaint(
shift(@row), \&Foswiki::Sandbox::validateTopicName
)
);
my %row;

$row{topic} =
Foswiki::Sandbox::untaint( shift(@row),
\&Foswiki::Sandbox::validateTopicName );
$row{user} = shift(@row);
$row{time} = shift(@row) || 0;
$row{revision} = shift(@row) || 1;
Expand Down Expand Up @@ -633,44 +633,31 @@ sub recordChange {
my $text = '';
my $t = time;

if ( $Foswiki::cfg{RCS}{TabularChangeFormat} ) {
my @changes =
map {
my @row = split( /\t/, $_ );
\@row
}
split( /[\r\n]+/, Foswiki::Store::Rcs::Handler->readFile($file) );

# Forget old stuff
my $cutoff = time() - $Foswiki::cfg{Store}{RememberChangesFor};
while ( scalar(@changes) && $changes[0]->[2] < $cutoff ) {
if ( -e $file ) {
@changes = _readChanges( $file, $web );
my $cutoff = $t - $Foswiki::cfg{Store}{RememberChangesFor};
while ( scalar(@changes) && $changes[0]->{time} < $cutoff ) {
shift(@changes);
}
}

# Add the new change to the end of the file
push(
@changes,
[
$topic, $args{cuid},
$t, $args{revision},
$json->encode( \%args )
]
);
# Add the new change to the end of the file
$args{time} = time;
push( @changes, \%args );

if ( $Foswiki::cfg{RCS}{TabularChangeFormat} ) {
$args{topic} ||= $topic;
foreach (@changes) {
my $hash = $_;
$_ = [
$hash->{topic}, $hash->{cuid}, $hash->{time},
$hash->{revision}, $json->encode($hash)
];
}

$text = join( "\n", map { join( "\t", @$_ ) } @changes );
}
else {
if ( -e $file ) {
@changes = _readChanges( $file, $web );
my $cutoff = $t - $Foswiki::cfg{Store}{RememberChangesFor};
while ( scalar(@changes) && $changes[0]->{time} < $cutoff ) {
shift(@changes);
}
}

# Add the new change to the end of the file
$args{time} = time;
push( @changes, \%args );
$text = $json->encode( \@changes );
}

Expand Down

0 comments on commit dd7f1b5

Please sign in to comment.