Skip to contentSkip to conversation

fetch/hg: support submodules

PATCH In review Dan McGregor 2 participants 3 messages May 12, 2015 – May 18, 2015

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 fetch/hg: support submodules

From: Daniel McGregor <[email protected]>

Use hg clone and hg pull to copy the source into the build directory rather than taring up the cloned repository and untarring in the destination.

This allows submodules to be cloned. While here, make the default behaviour keep the hg scm data to match the behaviour of the git fetcher.

---
 lib/bb/fetch2/hg.py | 55 +++++++++++++++++++++++++++++++++++------------------
 1 file changed, 36 insertions(+), 19 deletions(-)
lib/bb/fetch2/hg.py +36 -19
index 81592f6..6547cca 100644
@@ -64,7 +64,9 @@ class Hg(FetchMethod):
         elif not ud.revision:
             ud.revision = self.latest_revision(ud, d)
 
-        ud.localfile = data.expand('%s_%s_%s_%s.tar.gz' % (ud.module.replace('/', '.'), ud.host, ud.path.replace('/', '.'), ud.revision), d)
+        ud.localfile = ud.moddir
+
+        ud.basecmd = data.getVar("FETCHCMD_hg", d, True) or "/usr/bin/env hg"
 
     def need_update(self, ud, d):
         revTag = ud.parm.get('rev', 'tip')
@@ -80,8 +82,6 @@ class Hg(FetchMethod):
         command is "fetch", "update", "info"
         """
 
-        basecmd = data.expand('${FETCHCMD_hg}', d)
-
         proto = ud.parm.get('protocol', 'http')
 
         host = ud.host
@@ -98,7 +98,7 @@ class Hg(FetchMethod):
                 hgroot = ud.user + "@" + host + ud.path
 
         if command == "info":
-            return "%s identify -i %s://%s/%s" % (basecmd, proto, hgroot, ud.module)
+            return "%s identify -i %s://%s/%s" % (ud.basecmd, proto, hgroot, ud.module)
 
         options = [];
 
@@ -111,22 +111,22 @@ class Hg(FetchMethod):
 
         if command == "fetch":
             if ud.user and ud.pswd:
-                cmd = "%s --config auth.default.prefix=* --config auth.default.username=%s --config auth.default.password=%s --config \"auth.default.schemes=%s\" clone %s %s://%s/%s %s" % (basecmd, ud.user, ud.pswd, proto, " ".join(options), proto, hgroot, ud.module, ud.module)
+                cmd = "%s --config auth.default.prefix=* --config auth.default.username=%s --config auth.default.password=%s --config \"auth.default.schemes=%s\" clone %s %s://%s/%s %s" % (ud.basecmd, ud.user, ud.pswd, proto, " ".join(options), proto, hgroot, ud.module, ud.module)
             else:
-                cmd = "%s clone %s %s://%s/%s %s" % (basecmd, " ".join(options), proto, hgroot, ud.module, ud.module)	      
+                cmd = "%s clone %s %s://%s/%s %s" % (ud.basecmd, " ".join(options), proto, hgroot, ud.module, ud.module)
         elif command == "pull":
             # do not pass options list; limiting pull to rev causes the local
             # repo not to contain it and immediately following "update" command
             # will crash
             if ud.user and ud.pswd:
-                cmd = "%s --config auth.default.prefix=* --config auth.default.username=%s --config auth.default.password=%s --config \"auth.default.schemes=%s\" pull" % (basecmd, ud.user, ud.pswd, proto)
+                cmd = "%s --config auth.default.prefix=* --config auth.default.username=%s --config auth.default.password=%s --config \"auth.default.schemes=%s\" pull" % (ud.basecmd, ud.user, ud.pswd, proto)
             else:
-                cmd = "%s pull" % (basecmd)
+                cmd = "%s pull" % (ud.basecmd)
         elif command == "update":
             if ud.user and ud.pswd:
-                cmd = "%s --config auth.default.prefix=* --config auth.default.username=%s --config auth.default.password=%s --config \"auth.default.schemes=%s\" update -C %s" % (basecmd, ud.user, ud.pswd, proto, " ".join(options))
+                cmd = "%s --config auth.default.prefix=* --config auth.default.username=%s --config auth.default.password=%s --config \"auth.default.schemes=%s\" update -C %s" % (ud.basecmd, ud.user, ud.pswd, proto, " ".join(options))
             else:
-                cmd = "%s update -C %s" % (basecmd, " ".join(options))
+                cmd = "%s update -C %s" % (ud.basecmd, " ".join(options))
         else:
             raise FetchError("Invalid hg command %s" % command, ud.url)
 
@@ -163,15 +163,6 @@ class Hg(FetchMethod):
         logger.debug(1, "Running %s", updatecmd)
         runfetchcmd(updatecmd, d)
 
-        scmdata = ud.parm.get("scmdata", "")
-        if scmdata == "keep":
-            tar_flags = ""
-        else:
-            tar_flags = "--exclude '.hg' --exclude '.hgrags'"
-
-        os.chdir(ud.pkgdir)
-        runfetchcmd("tar %s -czf %s %s" % (tar_flags, ud.localpath, ud.module), d, cleanup = [ud.localpath])
-
     def supports_srcrev(self):
         return True
 
@@ -191,3 +182,29 @@ class Hg(FetchMethod):
         Return a unique key for the url
         """
         return "hg:" + ud.moddir
+
+    def localpath(self, ud, d):
+        return ud.moddir
+
+    def unpack(self, ud, destdir, d):
+        """
+        Make a local clone or export for the url
+        """
+
+        revflag = "-r %s" % ud.revision
+        subdir = ud.parm.get("destsuffix", ud.module)
+        codir = "%s/%s" % (destdir, subdir)
+
+        scmdata = ud.parm.get("scmdata", "")
+        if scmdata != "nokeep":
+            if not os.access(os.path.join(codir, '.hg'), os.R_OK):
+                logger.debug(2, "Unpack: creating new hg repository in '" + codir + "'")
+                runfetchcmd("%s init %s" % (ud.basecmd, codir), d)
+            logger.debug(2, "Unpack: updating source in '" + codir + "'")
+            os.chdir(codir)
+            runfetchcmd("%s pull %s" % (ud.basecmd, ud.moddir), d)
+            runfetchcmd("%s up -C %s" % (ud.basecmd, revflag), d)
+        else:
+            logger.debug(2, "Unpack: extracting source to '" + codir + "'")
+            os.chdir(ud.moddir)
+            runfetchcmd("%s archive -t files %s %s" % (ud.basecmd, revflag, codir), d)
Signature · 1 line
2.4.0
#1 lore raw

Hello,

This patches breaks the BB_GENERATE_MIRROR_TARBALLS, it doesn't generate or untar the local tarball any more, the local tarball's mirror doesn't work any more.

// Robert

Quoted 124 lines · Dan McGregor

From: Daniel McGregor <[email protected]>

Use hg clone and hg pull to copy the source into the build directory rather than taring up the cloned repository and untarring in the destination.

This allows submodules to be cloned. While here, make the default behaviour keep the hg scm data to match the behaviour of the git fetcher.

---
  lib/bb/fetch2/hg.py | 55 +++++++++++++++++++++++++++++++++++------------------
  1 file changed, 36 insertions(+), 19 deletions(-)
lib/bb/fetch2/hg.py +36 -19
index 81592f6..6547cca 100644
@@ -64,7 +64,9 @@ class Hg(FetchMethod):
          elif not ud.revision:
              ud.revision = self.latest_revision(ud, d)
 
-        ud.localfile = data.expand('%s_%s_%s_%s.tar.gz' % (ud.module.replace('/', '.'), ud.host, ud.path.replace('/', '.'), ud.revision), d)
+        ud.localfile = ud.moddir
+
+        ud.basecmd = data.getVar("FETCHCMD_hg", d, True) or "/usr/bin/env hg"
 
      def need_update(self, ud, d):
          revTag = ud.parm.get('rev', 'tip')
@@ -80,8 +82,6 @@ class Hg(FetchMethod):
          command is "fetch", "update", "info"
          """
 
-        basecmd = data.expand('${FETCHCMD_hg}', d)
-
          proto = ud.parm.get('protocol', 'http')
 
          host = ud.host
@@ -98,7 +98,7 @@ class Hg(FetchMethod):
                  hgroot = ud.user + "@" + host + ud.path
 
          if command == "info":
-            return "%s identify -i %s://%s/%s" % (basecmd, proto, hgroot, ud.module)
+            return "%s identify -i %s://%s/%s" % (ud.basecmd, proto, hgroot, ud.module)
 
          options = [];
 
@@ -111,22 +111,22 @@ class Hg(FetchMethod):
 
          if command == "fetch":
              if ud.user and ud.pswd:
-                cmd = "%s --config auth.default.prefix=* --config auth.default.username=%s --config auth.default.password=%s --config \"auth.default.schemes=%s\" clone %s %s://%s/%s %s" % (basecmd, ud.user, ud.pswd, proto, " ".join(options), proto, hgroot, ud.module, ud.module)
+                cmd = "%s --config auth.default.prefix=* --config auth.default.username=%s --config auth.default.password=%s --config \"auth.default.schemes=%s\" clone %s %s://%s/%s %s" % (ud.basecmd, ud.user, ud.pswd, proto, " ".join(options), proto, hgroot, ud.module, ud.module)
              else:
-                cmd = "%s clone %s %s://%s/%s %s" % (basecmd, " ".join(options), proto, hgroot, ud.module, ud.module)	
+                cmd = "%s clone %s %s://%s/%s %s" % (ud.basecmd, " ".join(options), proto, hgroot, ud.module, ud.module)
          elif command == "pull":
              # do not pass options list; limiting pull to rev causes the local
              # repo not to contain it and immediately following "update" command
              # will crash
              if ud.user and ud.pswd:
-                cmd = "%s --config auth.default.prefix=* --config auth.default.username=%s --config auth.default.password=%s --config \"auth.default.schemes=%s\" pull" % (basecmd, ud.user, ud.pswd, proto)
+                cmd = "%s --config auth.default.prefix=* --config auth.default.username=%s --config auth.default.password=%s --config \"auth.default.schemes=%s\" pull" % (ud.basecmd, ud.user, ud.pswd, proto)
              else:
-                cmd = "%s pull" % (basecmd)
+                cmd = "%s pull" % (ud.basecmd)
          elif command == "update":
              if ud.user and ud.pswd:
-                cmd = "%s --config auth.default.prefix=* --config auth.default.username=%s --config auth.default.password=%s --config \"auth.default.schemes=%s\" update -C %s" % (basecmd, ud.user, ud.pswd, proto, " ".join(options))
+                cmd = "%s --config auth.default.prefix=* --config auth.default.username=%s --config auth.default.password=%s --config \"auth.default.schemes=%s\" update -C %s" % (ud.basecmd, ud.user, ud.pswd, proto, " ".join(options))
              else:
-                cmd = "%s update -C %s" % (basecmd, " ".join(options))
+                cmd = "%s update -C %s" % (ud.basecmd, " ".join(options))
          else:
              raise FetchError("Invalid hg command %s" % command, ud.url)
 
@@ -163,15 +163,6 @@ class Hg(FetchMethod):
          logger.debug(1, "Running %s", updatecmd)
          runfetchcmd(updatecmd, d)
 
-        scmdata = ud.parm.get("scmdata", "")
-        if scmdata == "keep":
-            tar_flags = ""
-        else:
-            tar_flags = "--exclude '.hg' --exclude '.hgrags'"
-
-        os.chdir(ud.pkgdir)
-        runfetchcmd("tar %s -czf %s %s" % (tar_flags, ud.localpath, ud.module), d, cleanup = [ud.localpath])
-
      def supports_srcrev(self):
          return True
 
@@ -191,3 +182,29 @@ class Hg(FetchMethod):
          Return a unique key for the url
          """
          return "hg:" + ud.moddir
+
+    def localpath(self, ud, d):
+        return ud.moddir
+
+    def unpack(self, ud, destdir, d):
+        """
+        Make a local clone or export for the url
+        """
+
+        revflag = "-r %s" % ud.revision
+        subdir = ud.parm.get("destsuffix", ud.module)
+        codir = "%s/%s" % (destdir, subdir)
+
+        scmdata = ud.parm.get("scmdata", "")
+        if scmdata != "nokeep":
+            if not os.access(os.path.join(codir, '.hg'), os.R_OK):
+                logger.debug(2, "Unpack: creating new hg repository in '" + codir + "'")
+                runfetchcmd("%s init %s" % (ud.basecmd, codir), d)
+            logger.debug(2, "Unpack: updating source in '" + codir + "'")
+            os.chdir(codir)
+            runfetchcmd("%s pull %s" % (ud.basecmd, ud.moddir), d)
+            runfetchcmd("%s up -C %s" % (ud.basecmd, revflag), d)
+        else:
+            logger.debug(2, "Unpack: extracting source to '" + codir + "'")
+            os.chdir(ud.moddir)
+            runfetchcmd("%s archive -t files %s %s" % (ud.basecmd, revflag, codir), d)
#2 lore raw

Thanks for the heads up, I'll poke at it this evening.

Quoted 166 lines · Robert Yang

Hello,

This patches breaks the BB_GENERATE_MIRROR_TARBALLS, it doesn't generate or untar the local tarball any more, the local tarball's mirror doesn't work any more.

// Robert

Quoted 155 lines · Dan McGregor

From: Daniel McGregor <[email protected]>

Use hg clone and hg pull to copy the source into the build directory rather than taring up the cloned repository and untarring in the destination.

This allows submodules to be cloned. While here, make the default behaviour keep the hg scm data to match the behaviour of the git fetcher.

---
  lib/bb/fetch2/hg.py | 55
+++++++++++++++++++++++++++++++++++------------------
  1 file changed, 36 insertions(+), 19 deletions(-)
lib/bb/fetch2/hg.py +3 -1
index 81592f6..6547cca 100644
@@ -64,7 +64,9 @@ class Hg(FetchMethod):
          elif not ud.revision:
              ud.revision = self.latest_revision(ud, d)
 
-        ud.localfile = data.expand('%s_%s_%s_%s.tar.gz' %
 (ud.module.replace('/', '.'), ud.host, ud.path.replace('/', '.'),
 ud.revision), d)
+        ud.localfile = ud.moddir
+
+        ud.basecmd = data.getVar("FETCHCMD_hg", d, True) or

"/usr/bin/env hg"

def need_update(self, ud, d):
revTag = ud.parm.get('rev', 'tip')

lib/bb/fetch2/hg.py +1 -3
@@ -80,8 +82,6 @@ class Hg(FetchMethod):
          command is "fetch", "update", "info"
          """
 
-        basecmd = data.expand('${FETCHCMD_hg}', d)
-
          proto = ud.parm.get('protocol', 'http')
 
          host = ud.host
@@ -98,7 +98,7 @@ class Hg(FetchMethod):
                  hgroot = ud.user + "@" + host + ud.path
 
          if command == "info":
-            return "%s identify -i %s://%s/%s" % (basecmd, proto,
 hgroot, ud.module)
+            return "%s identify -i %s://%s/%s" % (ud.basecmd, proto,
 hgroot, ud.module)
 
          options = [];
lib/bb/fetch2/hg.py +0 -1
@@ -111,22 +111,22 @@ class Hg(FetchMethod):
 
          if command == "fetch":
              if ud.user and ud.pswd:
-                cmd = "%s --config auth.default.prefix=* --config

auth.default.username=%s --config auth.default.password=%s --config \"auth.default.schemes=%s\" clone %s %s://%s/%s %s" % (basecmd, ud.user, ud.pswd, proto, " ".join(options), proto, hgroot, ud.module, ud.module)
+ cmd = "%s --config auth.default.prefix=* --config
auth.default.username=%s --config auth.default.password=%s --config \"auth.default.schemes=%s\" clone %s %s://%s/%s %s" % (ud.basecmd, ud.user, ud.pswd, proto, " ".join(options), proto, hgroot, ud.module, ud.module)
else:
- cmd = "%s clone %s %s://%s/%s %s" % (basecmd, "
".join(options), proto, hgroot, ud.module, ud.module)
+ cmd = "%s clone %s %s://%s/%s %s" % (ud.basecmd, "
".join(options), proto, hgroot, ud.module, ud.module)
elif command == "pull":
# do not pass options list; limiting pull to rev causes the
local

              # repo not to contain it and immediately following "update"
command
              # will crash
              if ud.user and ud.pswd:
-                cmd = "%s --config auth.default.prefix=* --config
auth.default.username=%s --config auth.default.password=%s --config
\"auth.default.schemes=%s\" pull" % (basecmd, ud.user, ud.pswd, proto)
+                cmd = "%s --config auth.default.prefix=* --config
auth.default.username=%s --config auth.default.password=%s --config
\"auth.default.schemes=%s\" pull" % (ud.basecmd, ud.user, ud.pswd, proto)
              else:
lib/bb/fetch2/hg.py +1 -2
-                cmd = "%s pull" % (basecmd)
+                cmd = "%s pull" % (ud.basecmd)
          elif command == "update":
              if ud.user and ud.pswd:
-                cmd = "%s --config auth.default.prefix=* --config

auth.default.username=%s --config auth.default.password=%s --config \"auth.default.schemes=%s\" update -C %s" % (basecmd, ud.user, ud.pswd, proto, " ".join(options))
+ cmd = "%s --config auth.default.prefix=* --config
auth.default.username=%s --config auth.default.password=%s --config \"auth.default.schemes=%s\" update -C %s" % (ud.basecmd, ud.user, ud.pswd, proto, " ".join(options))
else:

lib/bb/fetch2/hg.py +18 -10
-                cmd = "%s update -C %s" % (basecmd, " ".join(options))
+                cmd = "%s update -C %s" % (ud.basecmd, " ".join(options))
          else:
              raise FetchError("Invalid hg command %s" % command, ud.url)
@@ -163,15 +163,6 @@ class Hg(FetchMethod):
          logger.debug(1, "Running %s", updatecmd)
          runfetchcmd(updatecmd, d)
 
-        scmdata = ud.parm.get("scmdata", "")
-        if scmdata == "keep":
-            tar_flags = ""
-        else:
-            tar_flags = "--exclude '.hg' --exclude '.hgrags'"
-
-        os.chdir(ud.pkgdir)
-        runfetchcmd("tar %s -czf %s %s" % (tar_flags, ud.localpath,
 ud.module), d, cleanup = [ud.localpath])
-
      def supports_srcrev(self):
          return True
@@ -191,3 +182,29 @@ class Hg(FetchMethod):
          Return a unique key for the url
          """
          return "hg:" + ud.moddir
+
+    def localpath(self, ud, d):
+        return ud.moddir
+
+    def unpack(self, ud, destdir, d):
+        """
+        Make a local clone or export for the url
+        """
+
+        revflag = "-r %s" % ud.revision
+        subdir = ud.parm.get("destsuffix", ud.module)
+        codir = "%s/%s" % (destdir, subdir)
+
+        scmdata = ud.parm.get("scmdata", "")
+        if scmdata != "nokeep":
+            if not os.access(os.path.join(codir, '.hg'), os.R_OK):
+                logger.debug(2, "Unpack: creating new hg repository in

'" + codir + "'")

lib/bb/fetch2/hg.py +7 -0
+                runfetchcmd("%s init %s" % (ud.basecmd, codir), d)
+            logger.debug(2, "Unpack: updating source in '" + codir + "'")
+            os.chdir(codir)
+            runfetchcmd("%s pull %s" % (ud.basecmd, ud.moddir), d)
+            runfetchcmd("%s up -C %s" % (ud.basecmd, revflag), d)
+        else:
+            logger.debug(2, "Unpack: extracting source to '" + codir +

"'")

lib/bb/fetch2/hg.py +2 -0
+            os.chdir(ud.moddir)
+            runfetchcmd("%s archive -t files %s %s" % (ud.basecmd,

revflag, codir), d)