On Monday 12 May 2008 06:24:15 John Lee wrote:

> Actually I use SRCDATE in openmoko-linux because I want a increasing
> number even across different repositories.  The persistent data is
> specific to the build machine so I decided not to use that.

Hey John,
very reasonable. I have the attached patch in the making. It will use 
git-rev-list rev -- | wc -l to get a sortable revision. It doesn't come 
without issues though:

        - You will need a local git repository for the time being
        - It assumes that only fast forwards are done on the tree

z.



Index: lib/bb/fetch/__init__.py
===================================================================
--- lib/bb/fetch/__init__.py	(Revision 1067)
+++ lib/bb/fetch/__init__.py	(Arbeitskopie)
@@ -500,6 +500,7 @@
         """
         Look in the cache for the latest revision, if not present ask the SCM.
         """
+
         if not hasattr(self, "_latest_revision"):
             raise ParameterError
 
@@ -517,8 +518,14 @@
         """
         
         """
-        if hasattr(self, "_sortable_revision"):
+        has_want_sortable = hasattr(self, "_want_sortable_revision")
+        has_sortable = hasattr(self, "_sortable_revision")
+
+        if not has_want_sortable and has_sortable:
             return self._sortable_revision(url, ud, d)
+        elif has_want_sortable and self._want_sortable_revision(url, ud, d) and has_sortable:
+            return self._sortable_revision(url, ud, d)
+        
 
         pd = persist_data.PersistData(d)
         key = self._revision_key(url, ud, d)
Index: lib/bb/fetch/git.py
===================================================================
--- lib/bb/fetch/git.py	(Revision 1067)
+++ lib/bb/fetch/git.py	(Arbeitskopie)
@@ -71,7 +71,7 @@
     def go(self, loc, ud, d):
         """Fetch url"""
 
-        if Fetch.try_mirror(d, ud.localfile):
+        if os.access(os.path.join(data.getVar("DL_DIR", d, True), ud.localfile), os.R_OK):
             bb.msg.debug(1, bb.msg.domain.Fetcher, "%s already exists (or was stashed). Skipping git checkout." % ud.localpath)
             return
 
@@ -140,3 +140,24 @@
     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)
+
+        self.go(None, ud, d)
+
+        cwd = os.getcwd()
+        os.chdir(repodir)
+        output = runfetchcmd("git rev-list %s -- | wc -l" % ud.tag, d, quiet=True)
+        os.chdir(cwd)
+        return "%s+%s" % (output.split()[0], ud.tag)
+        
+

Reply via email to