Autocommit to SVN (if x time has gone by)

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Autocommit to SVN (if x time has gone by) Mon Dec 31, 2012 12:04 pm • by Vegenad
Hi,

I'm attempting to commit a folder to SVN whenever the contents change and it hasn't been committed by Hazel within the last day (to avoid filling my SVN repository with lots of tiny changes).

I've attempted to handle this using the following two sets of rules but it seems to be running the rules every few seconds and as a result is taking up a lot of RAM and processor cycles.

Image

Uploaded with ImageShack.us

Image

Uploaded with ImageShack.us

The shell script I'm running is the following:

cd $1
svn update
svn commit -m "Autocommit"

Could anyone suggest a method of handling this without the overhead?

Many thanks,

Danny
Vegenad
 
Posts: 3
Joined: Mon Dec 31, 2012 8:24 am

Re: Autocommit to SVN (if x time has gone by) Mon Dec 31, 2012 12:40 pm • by a_freyer
The issue that you're running into seems to be that the modified date of the folder is changing every time a child file is changed. What I would do is something like this:

At the end of your commit script, write a temp file of the date of that commit:

Code: Select all
cd $1
svn update
svn commit -m "Autocommit"
date -j -f "%a %b %d %T %Z %Y" "`date`" "+%s" > .lastCommit


Note: I have hidden the file by putting a period in front of it. If you want the file to be visible, remove that.

Now, we have an easy marker to test against that is unrelated to the last time the folder was modified, but only related to the last time an SNV commit was made.

Now, in our rule, we add this:

Code: Select all
if (all) of the following conditions are met for (the file or folder being processed):
     Passes shell script (embedded script)
     ...

Do the following to the matched file or folder:
     …


With the embedded script as this:

Code: Select all
if [ $(expr $(date -j -f "%a %b %d %T %Z %Y" "`date`" "+%s") - $(cat .lastCommit)) -gt 86400 ]; then exit 0; else exit 1; fi
.

This will pass (i.e. exit 0) ONLY when the number of seconds since the last autocommit is greater than 24 hours.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: Autocommit to SVN (if x time has gone by) Thu Jan 03, 2013 8:47 am • by Vegenad
Thank you very much for your help!

I couldn't get it to work with the date command given for some reason (although it really should work) as it returns the following error.

Code: Select all
Failed conversion of ``Thu  3 Jan 2013 10:56:58 GMT'' using format ``%a %b %d %T %Z %Y''


However, I think I've got it working correctly using the command:

Code: Select all
date -j +%s


I've pasted the complete code below in case it's useful to anyone else - presuming it's correct which it may not be.

Image

Uploaded with ImageShack.us

I've added a condition to check for the existence of the .lastcommit file. If it doesn't exist then the script passes.

Passes shell script:

Code: Select all
if [ ! -f .lastcommit ]
   then exit 0
fi
if [ $(date -j +%s) - $(cat .lastCommit)) -gt 86400 ];
   then exit 0;
   else exit 1;
fi


Run shell script:

Code: Select all
cd $1
svn update
svn commit -m "Autocommit"
date -j +%s > .lastCommit


Cheers,

Danny
Vegenad
 
Posts: 3
Joined: Mon Dec 31, 2012 8:24 am

Re: Autocommit to SVN (if x time has gone by) Thu Jan 03, 2013 10:58 am • by a_freyer
I note that your if statement does not have camel case for lastCommit. That may present a problem.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: Autocommit to SVN (if x time has gone by) Fri Jan 04, 2013 8:11 am • by Vegenad
Good catch; thank you :).

Danny
Vegenad
 
Posts: 3
Joined: Mon Dec 31, 2012 8:24 am


Return to Support