in reply to Re^2: SVN API log_msg help
in thread Reaped: SVN API log_msg help

First, I think that 'use strict' would help you immensely. You have two variables, $logmsg and $log_msg in the log_msg routine, and I'm quite certain that is not what you want!

Second, you are not setting the log message properly. Since, as the documentation says, the first parameter is a reference to a scalar that should get the log message, you should be doing

${ $log_msg } = message();
(Don't put the leading ampersand on a subroutine call; this makes Perl do funny things like ignore prototypes, none of which you care about, but which could bite you at a later date. Just get out of the habit of using & on subroutines unless you're creating references to them.)

Your code as it stands seems to want to read standard input, write it to a file, and then read that back in again to set the log message. This could be loads simpler - just read it once, write it out, and then take the copy you already have to set the message:

open my $fh, '>>', $filename or die "Can't open $filename for appe +nd: $!"; my @lines = <STDIN>; print $fh @lines; close $fh; ${ $log_msg } = join("", @lines); return;
If there was some reason that you might get an error, then you'd return
return SVN::Error::create($apr_err, $child, $message);
$apr_err is documented in there somewhere, not sure where though. The default error handler should be sufficient unless you want to do something like trap errors writing to the log via eval and pass back a specific "hey, I can't log the message" error.

Leave $citem alone; you can do everything you want with just the $log_msg reference. I found all this poking at SVN::Core and SVN::Client - this much should get you considerably further than you are now.

Replies are listed 'Best First'.
Re^4: SVN API log_msg help
by naresh777 (Initiate) on Dec 14, 2011 at 06:00 UTC

    Thanks very much. I slightly modified and now i am able to commit.

    ${ $log_msg } = join("", @lines); return; # i changed this to my $data =join("",@lines); return $data;

    Now the question comes is when i enter a comment at

     my @lines =<STDIN>;

    It is still waiting to take data until i used "ctrl +D" how can i automate it to close and continue executing and the second thing is the temporary file which it is creating to save message it is dont deleting from temp after program exits

      It depends on what you want to do. If you want it to read only one line and then proceed, use
      ${ $log_msg } = <STDIN>;
      That will read just one line. If you instead want to do something like "read until I enter a null line", use a while loop, read one line at a time, and look for an empty one (only contains "\n").

      For the second option, try File::Temp.

      ($fh, $filename) = tempfile($template, UNLINK => 1);
      should work for you. That will automatically unlink the file when the program ends. If you don't want the filehandle (though I think you do), just use undef as the first item in the list being assigned to. Since you're going to write to the file, I'd suggest just using the handy already-opened-for-write filehandle that the call to tmpfile returns.