Skip to contentSkip to conversation

fetch/git: a few cleanups and one minor fix

PATCH New Christopher Larson 1 participant 5 messages Mar 21, 2017

lore
Share & tools
lore
#0 lore raw

cover fetch/git: a few cleanups and one minor fix

From: Christopher Larson <[email protected]>

The following changes since commit 1ff9b3c669fa187f152de7b8b57d14c2468d926c:

tests/data: Add inactive remove override test (2017-03-16 12:54:59 +0000)

are available in the git repository at:

[email protected]:kergoth/bitbake bb-fetch-git-cleanup

for you to fetch changes up to 0f71517b5208e117133b67fe728d482e7a575f35:

fetch/git: fix FetchError reference (2017-03-17 14:32:25 -0700)

----------------------------------------------------------------
Christopher Larson (4):
fetch/git: use enumerate for ud.names fetch/git: kill pointless quotes around single % args fetch/git: drop pointless os.path.join, workdir= fetch/git: fix FetchError reference

 lib/bb/fetch2/git.py | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
Signature · 1 line
2.8.0
#1 lore raw

PATCH 1/4 fetch/git: use enumerate for ud.names

From: Christopher Larson <[email protected]>

list.index() isn't a particularly efficient operation, so keep track of our position via enumerate() instead, which is more pythonic as well.

---
 lib/bb/fetch2/git.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/bb/fetch2/git.py +2 -2
index 0779e80..bbd302e 100644
@@ -173,8 +173,8 @@ class Git(FetchMethod):
         if len(branches) != len(ud.names):
             raise bb.fetch2.ParameterError("The number of name and branch parameters is not balanced", ud.url)
         ud.branches = {}
-        for name in ud.names:
-            branch = branches[ud.names.index(name)]
+        for pos, name in enumerate(ud.names):
+            branch = branches[pos]
             ud.branches[name] = branch
             ud.unresolvedrev[name] = branch
 
Signature · 1 line
2.8.0
#2 lore raw

PATCH 2/4 fetch/git: kill pointless quotes around single % args

In reply to Christopher Larson

From: Christopher Larson <[email protected]>

---
 lib/bb/fetch2/git.py | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
lib/bb/fetch2/git.py +5 -5
index bbd302e..e1e8765 100644
@@ -205,7 +205,7 @@ class Git(FetchMethod):
         if ud.rebaseable:
             for name in ud.names:
                 gitsrcname = gitsrcname + '_' + ud.revisions[name]
-        ud.mirrortarball = 'git2_%s.tar.gz' % (gitsrcname)
+        ud.mirrortarball = 'git2_%s.tar.gz' % gitsrcname
         ud.fullmirror = os.path.join(d.getVar("DL_DIR"), ud.mirrortarball)
         gitdir = d.getVar("GITDIR") or (d.getVar("DL_DIR") + "/git2/")
         ud.clonedir = os.path.join(gitdir, gitsrcname)
@@ -240,7 +240,7 @@ class Git(FetchMethod):
         # If the checkout doesn't exist and the mirror tarball does, extract it
         if not os.path.exists(ud.clonedir) and os.path.exists(ud.fullmirror):
             bb.utils.mkdirhier(ud.clonedir)
-            runfetchcmd("tar -xzf %s" % (ud.fullmirror), d, workdir=ud.clonedir)
+            runfetchcmd("tar -xzf %s" % ud.fullmirror, d, workdir=ud.clonedir)
 
         repourl = self._get_repo_url(ud)
 
@@ -292,14 +292,14 @@ class Git(FetchMethod):
 
             logger.info("Creating tarball of git repository")
             runfetchcmd("tar -czf %s %s" % (ud.fullmirror, os.path.join(".") ), d, workdir=ud.clonedir)
-            runfetchcmd("touch %s.done" % (ud.fullmirror), d, workdir=ud.clonedir)
+            runfetchcmd("touch %s.done" % ud.fullmirror, d, workdir=ud.clonedir)
 
     def unpack(self, ud, destdir, d):
         """ unpack the downloaded src to destdir"""
 
         subdir = ud.parm.get("subpath", "")
         if subdir != "":
-            readpathspec = ":%s" % (subdir)
+            readpathspec = ":%s" % subdir
             def_destsuffix = "%s/" % os.path.basename(subdir.rstrip('/'))
         else:
             readpathspec = ""
@@ -469,7 +469,7 @@ class Git(FetchMethod):
             if not os.path.exists(rev_file) or not os.path.getsize(rev_file):
                 from pipes import quote
                 commits = bb.fetch2.runfetchcmd(
-                        "git rev-list %s -- | wc -l" % (quote(rev)),
+                        "git rev-list %s -- | wc -l" % quote(rev),
                         d, quiet=True).strip().lstrip('0')
                 if commits:
                     open(rev_file, "w").write("%d\n" % int(commits))
Signature · 1 line
2.8.0
#3 lore raw

PATCH 3/4 fetch/git: drop pointless os.path.join, workdir=

In reply to Christopher Larson

From: Christopher Larson <[email protected]>

The touch of .done explicitly specifies the path, so there's no need for workdir=, and "os.path.join('.')" is identical to just '.'.

---
 lib/bb/fetch2/git.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/bb/fetch2/git.py +2 -2
index e1e8765..e420232 100644
@@ -291,8 +291,8 @@ class Git(FetchMethod):
                 os.unlink(ud.fullmirror)
 
             logger.info("Creating tarball of git repository")
-            runfetchcmd("tar -czf %s %s" % (ud.fullmirror, os.path.join(".") ), d, workdir=ud.clonedir)
-            runfetchcmd("touch %s.done" % ud.fullmirror, d, workdir=ud.clonedir)
+            runfetchcmd("tar -czf %s ." % ud.fullmirror, d, workdir=ud.clonedir)
+            runfetchcmd("touch %s.done" % ud.fullmirror, d)
 
     def unpack(self, ud, destdir, d):
         """ unpack the downloaded src to destdir"""
Signature · 1 line
2.8.0
#4 lore raw

PATCH 4/4 fetch/git: fix FetchError reference

In reply to Christopher Larson

From: Christopher Larson <[email protected]>

FetchError isn't defined, use bb.fetch2.FetchError in this context.

---
 lib/bb/fetch2/git.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/bb/fetch2/git.py +1 -1
index e420232..a8be859 100644
@@ -484,5 +484,5 @@ class Git(FetchMethod):
         try:
             self._lsremote(ud, d, "")
             return True
-        except FetchError:
+        except bb.fetch2.FetchError:
             return False
Signature · 1 line
2.8.0