• 4
  • 13
  • 5
  • 1
  • 2
Der Blog
Albrecht Weinert

a-weinert.de,  weinert-automation.de
|< < > >|

blog... /makesvnkeepmtime/   [de]
Albrecht Weinert

Make Subversion keep mTime

Subversion (SVN) is a good versioning system and still "the" standard. Nevertheless, it has one big deficiency:
    SVN destroys the file modification meta info (mTime for short).
See also this older contribution. Since then the frustating discussion is still on. In the meantime you can have some SVN clients taking the commit time instead of the check out time as the file’s mTime. But that’s still not the time „the photo was taken“.

So SVN has no own remedy yet. And the ongoing discussion can be boiled down to one will have to put the respective last mTime as a file property under SVN control. That property then has to be set before any commit or update. And it has to be used for mTime repair after any update or check out — and after commits also(!).

Recently I made the acquaintance of awk/gawk (on Windows) for the purpose of linking Atmel bootloader items to the application, hence unrelated to the big SVN problem. Nevertheless, that tool — that’s as well very flexible and very fragile — leads the way to the mTime rescue. You’ll need WinAVR and Frame4J installed for the following. All will run analogously on Linux, too.

To set/update the property mtime of each file be in the root of your local working copy, make the script saveTheDate.bat and run it there:
  java FS -relateToDir -omitDirs .svn;build -antTime | grep "m " | \↵
    gawk '{print "svn propset mtime \"" $1 " " $2 " " $3 "\" " $5 }' > saveTheDate.bat
  call saveTheDate.bat

saveTheDate.bat will look like:
  svn propset mtime "11/21/2012 01:49:11 pm " de\frame4j\util\TimeRO.java
  svn propset mtime "11/21/2012 01:49:11 pm " de\frame4j\util\TimeST.java
  svn propset mtime "01/27/2009 01:18:36 pm " factory\tomcat-coyote.jar
  svn propset mtime "07/04/2013 03:45:27 pm " translateIt.bat
  svn propset mtime "11/21/2012 01:49:12 pm " UCopy.java
  svn propset mtime "11/22/2012 01:36:09 pm " de\frame4j\UCopy.java
  svn propset ..... and so on

containing as many lines as you have files outside the build and .svn directories.

Note the American style date and 12h time format (by -antTime option), which is outright ugly. The values are portable GMT. Anyway the touch tool will just understand that horridness.
Note also the trailing blank as an easy and pragmatic way to fight a gawk-bug.
And note the grep „m “ filter’s only purpose is filtering out empty lines, that gawk won’t ignore gracefully.

Now the other way round.
To use each file’s property mtime of to reapair the file modification date be in the root of your local working copy, make the script rescueTheDate.bat and run it there:
  svn propget mtime -R | \↵
    gawk '{print "touch -m --date=\"" $3 " " $4 " " $5 "\" " $1 }' > rescueTheDate.bat
  call rescueTheDate.bat

rescueTheDate.bat will look like:
  touch -m --date="01/23/2010 01:17:12 pm" factory\junit.jar
  touch -m --date="11/21/2012 01:49:11 pm" de\frame4j\util\TimeRO.java
  touch -m --date="11/21/2012 01:49:11 pm" SendMail.java
  touch -m --date="06/28/2013 12:09:29 am" de\a_weinert\dta\DTAus.java
  touch -m --date="02/01/2013 11:46:21 am" factory\4win64\readme.txt
  touch -m --date="11/21/2012 01:49:12 pm" TimeHelper.java
  touch -m --date="01/23/2010 01:17:12 pm" de\frame4j\io\doc-files\dirVisit-kl.png
  touch -m --date="11/21/2012 01:49:12 pm" de\frame4j\io\ByteCharSeq.java
  touch -m --date="01/23/2010 01:17:12 pm" factory\4windows\bsDoesItNative.dll

containing as many lines as you have files with the mtime property.

Of course one has to remember to run those scripts right before respectively after the respective SVN actions. This can be automated.

In between the schema — partly put in scripts as proposed — works quite well. Except for …
The touch tool — both on Windows and on Linux — can’t set times in the range of one or two hours starting at 00:00:00. Unbelievable but true! The only remedy for
    touch: invalid date format
found so far was a on time action adding two hours in said rescueTheDate.bat at all lines afflicted by the touch bug.

Feedback welcome.

Post comments feed

Your Comment

Please log in to write a comment. Use the same link to register as a new welcome user.

Copyright   ©   2013, 2019   Albrecht Weinert,       E-Mail (webmaster)