svn fetcher: use 'svn update' to update sources - close OE#1367
authorMarcin Juszkiewicz <marcin@juszkiewicz.com.pl>
Fri, 26 Jan 2007 17:55:11 +0000 (17:55 +0000)
committerMarcin Juszkiewicz <marcin@juszkiewicz.com.pl>
Fri, 26 Jan 2007 17:55:11 +0000 (17:55 +0000)
For first fetch we use 'svn checkout' but for next updates we need to use
'svn update' to fetch only changes.

Patch written by Paul Sokolovsky.

lib/bb/fetch/svn.py

index 8856500..610b0b4 100644 (file)
@@ -29,6 +29,7 @@ This implementation is for svn. It is based on the cvs implementation.
 # Based on functions from the base bb module, Copyright 2003 Holger Schurig
 
 import os, re
+import sys
 import bb
 from   bb import data
 from   bb.fetch import Fetch
@@ -139,33 +140,34 @@ class Svn(Fetch):
             data.setVar('SVNCOOPTS', " ".join(options), localdata)
             data.setVar('SVNMODULE', module, localdata)
             svncmd = data.getVar('FETCHCOMMAND', localdata, 1)
+            svnupcmd = data.getVar('UPDATECOMMAND', localdata, 1)
 
             if svn_rsh:
                 svncmd = "svn_RSH=\"%s\" %s" % (svn_rsh, svncmd)
-
-#           create temp directory
-            bb.debug(2, "Fetch: creating temporary directory")
-            bb.mkdirhier(data.expand('${WORKDIR}', localdata))
-            data.setVar('TMPBASE', data.expand('${WORKDIR}/oesvn.XXXXXX', localdata), localdata)
-            tmppipe = os.popen(data.getVar('MKTEMPDIRCMD', localdata, 1) or "false")
-            tmpfile = tmppipe.readline().strip()
-            if not tmpfile:
-                bb.error("Fetch: unable to create temporary directory.. make sure 'mktemp' is in the PATH.")
-                raise FetchError(module)
-
-#           check out sources there
-            os.chdir(tmpfile)
-            bb.note("Fetch " + loc)
-            bb.debug(1, "Running %s" % svncmd)
-            myret = os.system(svncmd)
+                svnupcmd = "svn_RSH=\"%s\" %s" % (svn_rsh, svnupcmd)
+
+            pkg = data.expand('${PN}', d)
+            pkgdir = os.path.join(data.expand('${SVNDIR}', localdata), pkg)
+            moddir = os.path.join(pkgdir, module)
+            bb.debug(2, "Fetch: checking for module directory '%s'" % moddir)
+
+            if os.access(os.path.join(moddir, '.svn'), os.R_OK):
+                bb.note("Update " + loc)
+                # update sources there
+                os.chdir(moddir)
+                bb.debug(1, "Running %s" % svnupcmd)
+                myret = os.system(svnupcmd)
+            else:
+                bb.note("Fetch " + loc)
+#               check out sources there
+                bb.mkdirhier(pkgdir)
+                os.chdir(pkgdir)
+                bb.debug(1, "Running %s" % svncmd)
+                myret = os.system(svncmd)
             if myret != 0:
-                try:
-                    os.rmdir(tmpfile)
-                except OSError:
-                    pass
                 raise FetchError(module)
 
-            os.chdir(os.path.join(tmpfile, os.path.dirname(module)))
+            os.chdir(pkgdir)
 #           tar them up to a defined filename
             myret = os.system("tar -czf %s %s" % (os.path.join(dldir,tarfn), os.path.basename(module)))
             if myret != 0:
@@ -173,7 +175,5 @@ class Svn(Fetch):
                     os.unlink(tarfn)
                 except OSError:
                     pass
-#           cleanup
-            os.system('rm -rf %s' % tmpfile)
             os.chdir(olddir)
         del localdata