[Python-Dev] Expose Subversion revision number to Python

Phillip J. Eby pje at telecommunity.com
Fri Dec 16 16:51:33 CET 2005


At 08:35 AM 12/16/2005 -0500, Barry Warsaw wrote:
>On Fri, 2005-12-16 at 01:38 -0500, Phillip J. Eby wrote:
>
> > FYI, this is not the true revision number; it's only the revision 
> number in
> > which the directory was last modified, not the latest revision number
> > within the tree.
>
>Yep, I know.  At work, we've gone through many iterations of this,
>including essentially what you do in setuptools.
>
>I opted against that for several reasons.  First, I wanted to keep the
>patch as simple as possible.  Second, I didn't want to depend on Python
>already being built (i.e. write a Python script to do this).  Third, I
>think most Python developers will just svn up at the top of the source
>tree, then rebuild, rather than svn up some buried sub-tree, cd back to
>the top and rebuild from there.  At least, that's how I generally work
>with the Python tree.

Actually, the issue I was concerned about was that when you make a change 
to some file and commit it, the build number won't change unless you also 
svn up, and maybe not even then.  I never figured out how to get a good 
answer without reading the full "svn info -R" or the .svn/entries files.

Note that you can just use:

     svn info -R|grep '^Last Changed Rev'|sort -nr|head -1|cut -f 4 -d" "

To get the highest-numbered revision.  However, both this approach and 
yours will not deal with Subversion messages in non-English locales.  I 
discovered this with setuptools when I was using "svn info" when somebody 
reported that the text before the numbers is different in non-English locales.

After a bit of experimentation, here's a pipeline that gets the info 
directly from the entries files, without reliance on the language of svn 
info's output:

     find . -name entries | grep '\.svn/entries$' | xargs grep -h 
committed-rev \
          | cut -f2 -d'"' | sort -nr |head -1



More information about the Python-Dev mailing list