Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get HEAD revision number of SVN Repository with PYSVN

Tags:

python

pysvn

I'm using pysvn to monitor the changes in a Subversion directory. This is how i get informations from revisions:

(...)
svn_root = "http://svn/"
client = pysvn.Client()
from_revision = pysvn.Revision(pysvn.opt_revision_kind.number, 1500)
to_revision = pysvn.Revision( pysvn.opt_revision_kind.head )

revisions = client.log(svn_root, to_revision, to_revision, discover_changed_paths=True)

Now I want to get the changes not from a specific revision, like in my example, but the changes within the last 5 revisions (from head - 5 to head). How can I accomplish that? How can i get the NUMBER of the head revision?

I could do it by calling the Shell from Python. But I guess that there is a "Pythonic" way for that using pysvn.

like image 798
Wolkenarchitekt Avatar asked Apr 03 '11 09:04

Wolkenarchitekt


People also ask

How do I find my SVN revision number?

To find information about the history of a file or directory, use the svn log command. svn log will provide you with a record of who made changes to a file or directory, at what revision it changed, the time and date of that revision, and, if it was provided, the log message that accompanied the commit.

What is SVN revision number?

As we described in the section called “Revisions”, revision numbers in Subversion are pretty straightforward—integers that keep getting larger as you commit more changes to your versioned data. Still, it doesn't take long before you can no longer remember exactly what happened in each and every revision.


2 Answers

Got it. When providing the path to the checked out SVN source, i can ask for the HEAD revision like this:

headrev = client.info(svnroot).get("revision").number

An alternative would be this:

headrev = pysvn.Revision( pysvn.opt_revision_kind.head )            
revlog = svnclient.log( url, revision_start=headrev, revision_end=headrev, discover_changed_paths=False)
headrev = revlog[0].revision.number

(Attention, the latter only works if you use the root of an SVN repository as the url. revlog will be empty if you provide a sub-url of the repo if it's not HEAD itself)

like image 169
Wolkenarchitekt Avatar answered Sep 23 '22 16:09

Wolkenarchitekt


A better (and faster) method is this:

client.revpropget("revision", url=svn_url)[0].number
like image 27
user1988536 Avatar answered Sep 25 '22 16:09

user1988536