diff svnwrap/svn_swig_wrapper.py @ 301:79440ed81011

Allow specifying a revision to stop at using the -H flag. This is useful for converting repositories which have been deleted or renamed, such as llvm-gcc-4-2 in the LLVM repositories which was renamed to llvm-gcc-4.2 shortly after its creation. Also, consolidate the two places in svn_swig_wrapper.py where a default chunk size is specified to one, single variable declaration.
author Dan Villiom Podlaski Christiansen <danchr@gmail.com>
date Fri, 27 Mar 2009 03:21:45 +0100
parents 4aba7542f6a9
children ce676eff002b
line wrap: on
line diff
--- a/svnwrap/svn_swig_wrapper.py
+++ b/svnwrap/svn_swig_wrapper.py
@@ -29,6 +29,9 @@ class SubversionRepoCanNotDiff(Exception
     """Exception raised when the svn API diff3() command cannot be used
     """
 
+'''Default chunk size used in fetch_history_at_paths() and revisions().'''
+_chunk_size = 1000
+
 def optrev(revnum):
     optrev = core.svn_opt_revision_t()
     optrev.kind = core.svn_opt_revision_number
@@ -145,7 +148,7 @@ class SubversionRepo(object):
     This uses the SWIG Python bindings, and will only work on svn >= 1.4.
     It takes a required param, the URL.
     """
-    def __init__(self, url='', username=''):
+    def __init__(self, url='', username='', head=None):
         self.svn_url = url
         self.uname = username
         self.auth_baton_pool = core.Pool()
@@ -207,6 +210,26 @@ class SubversionRepo(object):
         return 0
     START = property(START)
 
+    def last_changed_rev(self):
+        try:
+            holder = []
+            ra.get_log(self.ra, [''],
+                       self.HEAD, 1,
+                       1, #limit of how many log messages to load
+                       True, # don't need to know changed paths
+                       True, # stop on copies
+                       lambda paths, revnum, author, date, message, pool:
+                           holder.append(revnum),
+                       self.pool)
+
+            return holder[-1]
+        except core.SubversionException, e:
+            if e.apr_err not in [core.SVN_ERR_FS_NOT_FOUND]:
+                raise
+            else:
+                return self.HEAD
+    last_changed_rev = property(last_changed_rev)
+
     def branches(self):
         """Get the branches defined in this repo assuming a standard layout.
 
@@ -302,7 +325,7 @@ class SubversionRepo(object):
         folders, props, junk = r
         return folders
 
-    def revisions(self, start=None, chunk_size=1000):
+    def revisions(self, start=None, stop=None, chunk_size=_chunk_size):
         """Load the history of this repo.
 
         This is LAZY. It returns a generator, and fetches a small number