From: david.karr on
I'm writing a script that will (among other things) search the content
of a target element at a revision for a particular substring. In fact,
it will iterate through the available revisions for an element,
searching for the substring.

In looking at the numerous SVN Perl packages, I started with
"SVN::Client". This gives me a convenient interface to get the
revision numbers available for a target element.

Next, I have to be able to get the text content of the target element
at each of those revisions, in order to search for a substring. The
only obvious interface in SVN::Client that gives me access to the
element content is the "cat()" method, which writes the content to a
file descriptor. I suppose I could get this to work, but this seems
pretty indirect.

Assuming I'm not missing a different way to do this with SVN::Client,
among the numerous other SVN Perl packages, is there another one that
would give me convenient access to the content of an element at a
revision?
From: Christian Winter on
david.karr wrote:
[...]
> Next, I have to be able to get the text content of the target element
> at each of those revisions, in order to search for a substring. The
> only obvious interface in SVN::Client that gives me access to the
> element content is the "cat()" method, which writes the content to a
> file descriptor. I suppose I could get this to work, but this seems
> pretty indirect.
>
> Assuming I'm not missing a different way to do this with SVN::Client,
> among the numerous other SVN Perl packages, is there another one that
> would give me convenient access to the content of an element at a
> revision?

You can always use Perl's feature of "in memory" files to avoid
writing to disk and re-reading the contents:

my $memfile;
open( CURRFILE, ">", \$memfile)
or die "Failed to open in-memory file: $!";
$ctx->cat(\*CURRFILE, $target, $revision, $pool);

-Chris
From: david.karr on
On Apr 20, 8:34 pm, Christian Winter <thepoet_nos...(a)arcor.de> wrote:
> david.karr wrote:
>
> [...]
>
> > Next, I have to be able to get the text content of the target element
> > at each of those revisions, in order to search for a substring.  The
> > only obvious interface in SVN::Client that gives me access to the
> > element content is the "cat()" method, which writes the content to a
> > file descriptor. I suppose I could get this to work, but this seems
> > pretty indirect.
>
> > Assuming I'm not missing a different way to do this with SVN::Client,
> > among the numerous other SVN Perl packages, is there another one that
> > would give me convenient access to the content of an element at a
> > revision?
>
> You can always use Perl's feature of "in memory" files to avoid
> writing to disk and re-reading the contents:
>
> my $memfile;
> open( CURRFILE, ">", \$memfile)
>    or die "Failed to open in-memory file: $!";
> $ctx->cat(\*CURRFILE, $target, $revision, $pool);
>
> -Chris

Ok, I think this basically works, but I'm finding that some revisions
of an element fail with a "Filesystem has no item: File not found:
revision ..." error. I got the list of revisions to check with
something like this:

$ctx->log([$opt_element], 1, "HEAD", 1, 0, \&addToRevisionsList);

sub addToRevisionsList($$$$$$) {
my ($changed_paths, $revision, $author, $date, $message) = @_;
print "revision[" . $revision . "]\n";
push(@revisionsList, $revision);
}

When I later try to iterate through them with something like this:

for my $revision (@revisionsList) {
print $revision . "\n";
my $memfile;
open( CURRFILE, ">", \$memfile)
or die "Failed to open in-memory file: $!";
$ctx->cat(\*CURRFILE, $opt_element, $revision);
print "file[" . $memfile . "]\n";
}

The first few entries in the revisions list fails with that error. I
tried manually submitting the last revision in the list, and that
works fine.

How can I either only run "cat()" on revisions where I somehow know
it's going to work, or safely fail the "cat()" calls that don't have a
file associated with them? In the current state of the script, the
first "cat()" that fails kills the script.