]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
[git] Optionally use git-rev-list to get a sortable revision
authorHolger Hans Peter Freyther <zecke@selfish.org>
Sun, 12 Oct 2008 22:14:09 +0000 (22:14 +0000)
committerHolger Hans Peter Freyther <zecke@selfish.org>
Sun, 12 Oct 2008 22:14:09 +0000 (22:14 +0000)
    With setting BB_GIT_CLONE_FOR_SRCREV="1" you can get a sensible
    and global (per repository with only fast forwards) revision. The downsides
    are you will have to have a repository at parse time which means you will
    git-clone certain trees you don't even use. This is also the reason why
    this is optional. This also means you might need to download your git
    checkouts to get this feature working.

lib/bb/fetch/git.py

index af16732d3dc282ea660a179c26e5183df63c0a23..ff4b7dcdbb58c8d8ee321e6dd7668c0b0f8dd673 100644 (file)
@@ -136,3 +136,38 @@ class Git(Fetch):
     def _build_revision(self, url, ud, d):
         return ud.tag
 
+    def _want_sortable_revision(self, url, ud, d):
+        return bb.data.getVar("BB_GIT_CLONE_FOR_SRCREV", d, True) or False
+
+    def _sortable_revision(self, url, ud, d):
+        """
+        This is only called when _want_sortable_revision called true
+
+        We will have to get the updated revision.
+        """
+        gitsrcname = '%s%s' % (ud.host, ud.path.replace('/', '.'))
+        repodir = os.path.join(data.expand('${GITDIR}', d), gitsrcname)
+
+
+        # Runtime warning on wrongly configured sources
+        if ud.tag == "1":
+            bb.msg.error(1, bb.msg.domain.Fetcher, "SRCREV is '1'. This indicates a configuration error of %s" % url)
+            return "0+1"
+
+        cwd = os.getcwd()
+
+        # Check if we have the rev already
+        if not os.path.exists(repodir):
+            print "no repo"
+            self.go(None, ud, d)
+
+        os.chdir(repodir)
+        if not self._contains_ref(ud.tag, d):
+            self.go(None, ud, d)
+
+        output = runfetchcmd("git rev-list %s -- 2> /dev/null | wc -l" % ud.tag, d, quiet=True)
+        os.chdir(cwd)
+
+        return "%s+%s" % (output.split()[0], ud.tag)
+        
+