tags:

views:

59

answers:

1

For some reason, we can't update the SVN in some build machines. Installed svn version is 1.3.x. But Hudson slave used 1.6 to create a checkout. This means we can't run "svn info" on those checkouts:

$ svnversion 
subversion/libsvn_wc/questions.c:110: (apr_err=155021)
svn: This client is too old to work with working copy '.'; please get a newer Subversion client
$ svn info
subversion/libsvn_wc/questions.c:110: (apr_err=155021)
svn: This client is too old to work with working copy '.'; please get a newer Subversion client
$

My question, is there a way to access the revision number without having to invoking the svn binary? You know, like trying to look into the .svn/ directory? Assume that the checkout is using latest svn version (1.6).

A: 

I found an answer to this by looking at setuptools source code (setuptools/command/egg_info.py)

        entries_file = join(dirname(__file__), '.svn', 'entries')
        assert exists(entries_file), '%s is missing' % entries_file
        with open(entries_file) as f:
            data = f.read()
            # parsing code inherited from setuptools/command/egg_info.py
            if data.startswith('<?xml'):
                localrev = max([int(m.group(1)) for m in revre.finditer(data)]+[0])
            else:
                if data<8:
                    raise Exception, "unrecognized .svn/entries format"

                data = map(str.splitlines,data.split('\n\x0c\n'))
                del data[0][0]  # get rid of the '8' or '9'
                localrev = max([int(d[9]) for d in data if len(d)>9 and d[9]]+[0])
Sridhar Ratnakumar