Search code examples
pythonsvnpysvn

Does pysvn let you limit log messages in reverse order?


Essentially I want the same behaviour as running:

log = client.log(url)
oldestEntry = log[-1]

Except without having to download the entire log. I know setting

limit=1

lets you find the newest entry. Is there any way of limiting from the reverse order?


Solution

  • Reverse the order of the revision_start and revision_end and set limit to 1:

    import pysvn
    
    url='http://svn.apache.org/repos/asf/httpd/httpd/trunk/README'
    
    epoch = pysvn.Revision(pysvn.opt_revision_kind.number, 0)
    head = pysvn.Revision(pysvn.opt_revision_kind.head)
    
    client = pysvn.Client()
    
    # Get all entries
    l = client.log(url)
    print len(l), l[0].revision, l[-1].revision
    
    # Get most recent entry:
    l = client.log(url, limit=1)
    print len(l), l[0].revision
    
    # Get most recent entry, again:
    l = client.log(url, revision_start=head, revision_end=epoch, limit=1)
    print len(l), l[0].revision
    
    # Get least recent entry
    l = client.log(url, revision_start=epoch, revision_end=head, limit=1)
    print len(l), l[0].revision
    

    The result is:

    22 <Revision kind=number 1209505> <Revision kind=number 87470>
    1 <Revision kind=number 1209505>
    1 <Revision kind=number 1209505>
    1 <Revision kind=number 87470>