Commits

anatoly techtonik committed 73725c6

factor out oldest revision search for targets file into function

  • Participants
  • Parent commits f67ef64

Comments (0)

Files changed (1)

   tf.close()
   return tfpath
 
+def find_oldest_rev_for_targets(tfilepath, repopath):
+  """Detect the oldest revision where at least one entry from
+     targets file is found
+  """
+  debug('  looking for the oldest entry for at least one target from a given set')
+  # svn log -v --targets=F -l 1 -r 0:HEAD http://svn.python.org/projects/python/trunk --xml
+  proc = subprocess.Popen('svn log -v --targets="%s" -l 1 -r 0:HEAD %s' % (tfilepath, repopath),
+                          stdout=subprocess.PIPE, shell=True)
+  out = proc.communicate()[0]
+  if out == None:
+    warning("no output from svn log, exiting")
+    sys.exit(-1)
+
+  # output looks like
+  # ------------------------------------------------------------------------
+  # r12153 | gward | 1998-12-19 00:00:30 +0200 (Sat, 19 Dec 1998) | 2 lines
+  return out.splitlines()[1].split(None, 1)[0][1:]
+
 
 if __name__ == '__main__':
   cwd = os.path.dirname(__file__) or "."
       debug(' creating Mercurial mirror with hgsvn')
       tfpath = create_targets_file(modname, sources)
 
-      debug('  looking for the oldest entry for a given set of files')
-      # svn log -v --targets=F -l 1 -r 0:HEAD http://svn.python.org/projects/python/trunk --xml
-      proc = subprocess.Popen('svn log -v --targets="%s" -l 1 -r 0:HEAD %s' % (tfpath, repopath),
-                              stdout=subprocess.PIPE, shell=True)
-      out = proc.communicate()[0]
-      if out == None:
-        warning("no output from svn log, exiting")
-        sys.exit(-1)
-
-      # output looks like
-      # ------------------------------------------------------------------------
-      # r12153 | gward | 1998-12-19 00:00:30 +0200 (Sat, 19 Dec 1998) | 2 lines
-      startrev = out.splitlines()[1].split(None, 1)[0][1:]
+      startrev = find_oldest_rev_for_targets(tfpath, repopath)
       debug('  updating to start revision %s' % startrev)
       ret = call("svn up -r %s" % startrev)
       if ret != 0: