]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
fetch/git.py: BB_GIT_CLONE_FOR_SRCREV updates
authorRichard Purdie <rpurdie@linux.intel.com>
Sun, 22 Nov 2009 00:04:45 +0000 (00:04 +0000)
committerRichard Purdie <rpurdie@linux.intel.com>
Sun, 22 Nov 2009 00:04:45 +0000 (00:04 +0000)
Based on a patch from Martin Jansa <Martin.Jansa@gmail.com>:

* Add a _sortable_buildindex attribute and return the index separate from
  the revision
* This means the git.py internal cache is no longer needed
* Adds the returned value to the cache so if the mechanism for
  selecting the index changes, the values increase.

Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
lib/bb/fetch/__init__.py
lib/bb/fetch/git.py

index 1639469244cd8f97e645a82386e68fba39aae686..6c8408e1a1bb4f9f26799048e501b4c7c4ce1ed1 100644 (file)
@@ -578,9 +578,7 @@ class Fetch(object):
         """
         
         """
-        has_sortable = hasattr(self, "_sortable_revision")
-
-        if has_sortable:
+        if hasattr(self, "_sortable_revision"):
             return self._sortable_revision(url, ud, d)
 
         pd = persist_data.PersistData(d)
@@ -598,9 +596,13 @@ class Fetch(object):
         if last_rev == latest_rev:
             return str(count + "+" + latest_rev)
 
+        buildindex_provided = hasattr(self, "_sortable_buildindex")
+        if buildindex_provided:
+            count = self._sortable_buildindex(url, ud, d, latest_rev)
+
         if count is None:
             count = "0"
-        elif uselocalcount:
+        elif uselocalcount or buildindex_provided:
             count = str(count)
         else:
             count = str(int(count) + 1)
index ff480ec278b157b4a7d85702dae8e784838c6fe9..e7284d9920339177f6218e2f3420fba728d35324 100644 (file)
@@ -32,8 +32,8 @@ class Git(Fetch):
         #
         # Only enable _sortable revision if the key is set
         #
-        if bb.data.getVar("BB_GIT_CLONE_FOR_SRCREV", d, True):
-            self._sortable_revision = self._sortable_revision_disabled
+        if bb.data.getVar("BB_GIT_CLONE_FOR_SRCREV", d, True) or True:
+            self._sortable_buildindex = self._sortable_buildindex_disabled
     def supports(self, url, ud, d):
         """
         Check to see if a given url can be fetched with git.
@@ -151,41 +151,33 @@ class Git(Fetch):
     def _build_revision(self, url, ud, d):
         return ud.tag
 
-    def _sortable_revision_disabled(self, url, ud, d):
+    def _sortable_buildindex_disabled(self, url, ud, d, rev):
         """
-        This is only called when _sortable_revision_valid called true
-
-        We will have to get the updated revision.
+        Return a suitable buildindex for the revision specified. This is done by counting revisions 
+        using "git rev-list" which may or may not work in different circumstances.
         """
         gitsrcname = '%s%s' % (ud.host, ud.path.replace('/', '.'))
         repodir = os.path.join(data.expand('${GITDIR}', d), gitsrcname)
 
-        key = "GIT_CACHED_REVISION-%s-%s"  % (gitsrcname, ud.tag)
-        if bb.data.getVar(key, d):
-            return bb.data.getVar(key, d)
-
-
-        # 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)
+            if not os.path.exists(repodir):
+                bb.msg.error(bb.msg.domain.Fetcher, "GIT repository for %s doesn't exist in %s, cannot get sortable buildnumber, using old value" % (url, repodir))
+                return None
+
 
         os.chdir(repodir)
-        if not self._contains_ref(ud.tag, d):
+        if not self._contains_ref(rev, d):
             self.go(None, ud, d)
 
-        output = runfetchcmd("git rev-list %s -- 2> /dev/null | wc -l" % ud.tag, d, quiet=True)
+        output = runfetchcmd("git rev-list %s -- 2> /dev/null | wc -l" % rev, d, quiet=True)
         os.chdir(cwd)
 
-        sortable_revision = "%s+%s" % (output.split()[0], ud.tag)
-        bb.data.setVar(key, sortable_revision, d)
-        return sortable_revision
-        
+        buildindex = "%s" % output.split()[0]
+        bb.msg.debug(1, bb.msg.domain.Fetcher, "GIT repository for %s in %s is returning %s revisions in rev-list before %s" % (url, repodir, buildindex, rev))
+        return buildindex