Skip to contentSkip to conversation

fetch/git: Separate out an ls-remote function

PATCH In review Richard Purdie 2 participants 3 messages Feb 28, 2014 – Mar 2, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fetch/git: Separate out an ls-remote function

There is other code which can want to run ls-remote style commands with different parameters so split out the function.

---

bitbake/lib/bb/fetch2/git.py +12 -4
index f7c26b3..1edcee4 100644
@@ -317,22 +317,30 @@ class Git(FetchMethod):
         """
         return "git:" + ud.host + ud.path.replace('/', '.') + ud.unresolvedrev[name]
 
-    def _latest_revision(self, ud, d, name):
+    def __lsremote(self, ud, d, search):
         """
-        Compute the HEAD revision for the url
+        Run git ls-remote with the specified search string
         """
         if ud.user:
             username = ud.user + '@'
         else:
             username = ""
 
-        cmd = "%s ls-remote %s://%s%s%s refs/heads/%s refs/tags/%s^{}" % \
-              (ud.basecmd, ud.proto, username, ud.host, ud.path, ud.unresolvedrev[name], ud.unresolvedrev[name])
+        cmd = "%s ls-remote %s://%s%s%s %s" % \
+              (ud.basecmd, ud.proto, username, ud.host, ud.path, search)
         if ud.proto.lower() != 'file':
             bb.fetch2.check_network_access(d, cmd)
         output = runfetchcmd(cmd, d, True)
         if not output:
             raise bb.fetch2.FetchError("The command %s gave empty output unexpectedly" % cmd, ud.url)
+        return output
+
+    def _latest_revision(self, ud, d, name):
+        """
+        Compute the HEAD revision for the url
+        """
+        search = "refs/heads/%s refs/tags/%s^{}" % (ud.unresolvedrev[name], ud.unresolvedrev[name])
+        output = self.__lsremote(ud, d, search)
         return output.split()[0]
 
     def _build_revision(self, ud, d, name):
#1 lore raw

bitbake/lib/bb/fetch2/git.py class Git(FetchMethod): · line 320

Quoted 3 lines · Richard Purdie
bitbake/lib/bb/fetch2/git.py +1 -1
-    def _latest_revision(self, ud, d, name):
+    def __lsremote(self, ud, d, search):

Are we sure we want to use __ here? Double-underscore will trigger python internal name mangling. While using it doesn't break anything, it doesn't really buy us much either vs _, and makes inspection of the class/object rather ugly, IMO :)

Signature · 5 lines
Christopher Larson
clarson at kergoth dot com
Founder - BitBake, OpenEmbedded, OpenZaurus
Maintainer - Tslib
Senior Software Engineer, Mentor Graphics
#2 lore raw
Quoted 7 lines · Chris Larson

On Fri, Feb 28, 2014 at 10:22 AM, Richard Purdie
<[email protected]> wrote:
- def _latest_revision(self, ud, d, name):
+ def __lsremote(self, ud, d, search):

Quoted 5 lines

Are we sure we want to use __ here? Double-underscore will trigger python internal name mangling. While using it doesn't break anything, it doesn't really buy us much either vs _, and makes inspection of the class/object rather ugly, IMO :)

Agreed, I changed it before merging.

Cheers,

Richard