[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: svn log question

From: Ryan Schmidt <subversion-2010a_at_ryandesign.com>
Date: Wed, 10 Mar 2010 15:44:18 -0600

On Mar 10, 2010, at 14:49, Kevin Longfellow wrote:

> I'm setting up monitoring hourly commits on several repositories and thought something like this would work:
>
> #!/bin/sh
> OneHourAgo=`date -d '1 hour ago' +'%F %T'`
> DateNow=`date +'%F %T'`
> em_result=`svn log -r "{${OneHourAgo}}:{${DateNow}}" file:///${SvnBase}/${1} | egrep "^r.*line|^r.*lines"$ | wc -l`
>
> There likely is an easier or more accurate way to do this but the above will always report a value of 1 even when the HEAD revision does not fall within the specified date as shown below.
>
> svn log -r "{2010-03-10 11:42:20}:{2010-03-10 12:42:20}" file:///misc_sourcectrl01/svnrepositories/svnrepos1
> ------------------------------------------------------------------------
> r12138 | user | 2009-07-09 07:41:21 -0700 (Thu, 09 Jul 2009) | 1 line
>
> add the source
> ------------------------------------------------------------------------
>
> It's not a big deal but it does make unused repositories look like there is some activity. Any ideas on a better way to do this or why the command always returns the HEAD revision?

Subversion will always return one more result than you expect, so you can just discard it. See the box labeled "Is Subversion a Day Early?" on this page:

http://svnbook.red-bean.com/en/1.5/svn.tour.revs.specifiers.html#svn.tour.revs.dates

I'd recommend making this script analyze the log messages in the prior full hour period, not the hour preceding the time that you run the script, since even if you schedule it to run via cron, it might not run at exactly the same time every hour, especially if you're analyzing several repositories one after another.

StartDate=`date -d '1 hour ago' +'%F %H:00:00'`
EndDate=`date +'%F %H:00:00'`

You also will want to use the -q switch to svn log to save some bandwidth; since you're already using egrep to discard the log messages anyway you may as well not transfer them from the server. You wouldn't even need to use egrep then, really, since you could just take the number of lines of the quiet log output, subtract 3 (to remove the dividing line, the extra log message, and another dividing line), and divide by 2 (to remove the remaining dividing lines), to get the number of changes in this time period.

count_log_lines=`svn log -q -r "{${StartDate}}:{${EndDate}}" file:///${SvnBase}/${1} | wc -l`
em_result=$((($count_log_lines - 3) / 2))
Received on 2010-03-10 22:44:56 CET

This is an archived mail posted to the Subversion Users mailing list.