Commits

anatoly techtonik committed f39feb7

run hgimportsvn on the oldest common revision from files history

  • Participants
  • Parent commits 87bf91e

Comments (0)

Files changed (1)

       debug(" no module dir exists, creating %s" % moddir)
       os.mkdir(moddir)
 
+    repopath = repository+'/'+branches[0]
     savedcwd = os.getcwdu()
     os.chdir(moddir)
     if not os.path.exists(".svn"):
       # TODO: support multiple branches - not only the first one
-      repopath = repository+'/'+branches[0]
       debug(" no SVN working copy, making shallow checkout")
       ret = call("svn co %s --depth=empty ." % repopath)
       if ret != 0:
           sys.exit(ret)
         # TODO: target exists after checkout
       
-      info('SVN checkout complete. restart to refresh Mercurial copy')
+      info('SVN checkout complete. restart to do initial Mercurial import')
 
-    else: # if .svn exists create .hg structure
+    elif not os.path.exists(".hg"): # if .svn exists create .hg repository
       # TODO: validate all required files/dirs are present
       #       (dirs should be recheckouted to catch all file changes within)
       # TODO: validate no extra files/dirs are present in working copy
       debug(' creating Mercurial mirror with hgsvn')
-      ret = call("hgimportsvn .")
+      tfname = modname+".targets.def"
+      tfpath = os.path.join(savedcwd, tfname)
+      debug('  saving targets list to %s' % tfname)
+      tf = open(tfpath, "w")
+      for src in sources:
+        tf.write(src+"\n")
+      tf.close()
+
+      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:]
+      debug('  updating to start revision %s' % startrev)
+      ret = call("svn up -r %s" % startrev)
       if ret != 0:
         warning("return code %s is not 0, exiting" % ret)
         sys.exit(ret)
       
+      debug('  importing current state into hg with hgimportsvn')
+      ret = call("hgimportsvn --local-only .")
+      if ret != 0:
+        warning("return code %s is not 0, exiting" % ret)
+        sys.exit(ret)
+      
+      info('initial Mercurial import complete. restart to pull historical data')
+
+    else: # if .svn and .hg structures already exist
+      debug(' pulling %s module history into Mercurial' % modname)
+      #ret = call("hgimportsvn --local-only .")
+      if ret != 0:
+        warning("return code %s is not 0, exiting" % ret)
+        sys.exit(ret)
 
     os.chdir(savedcwd)