Skip to contentSkip to conversation

fetch2/git: Clean up sortable_revision

PATCH In review Richard Purdie 3 participants 3 messages May 19, 2013 – May 22, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fetch2/git: Clean up sortable_revision

Now we no longer try and provide increasing values from the fetcher, we can simplify the function structure for the sortable_revision pieces and move the AUTOINC handling directly into the function which needs it, simplifying the code.

---

bitbake/lib/bb/fetch2/__init__.py +10 -17
index dd1cc93..f8f8244 100644
@@ -616,7 +616,10 @@ def get_srcrev(d):
         raise FetchError("SRCREV was used yet no valid SCM was found in SRC_URI")
 
     if len(scms) == 1 and len(urldata[scms[0]].names) == 1:
-        return urldata[scms[0]].method.sortable_revision(scms[0], urldata[scms[0]], d, urldata[scms[0]].names[0])
+        autoinc, rev = urldata[scms[0]].method.sortable_revision(scms[0], urldata[scms[0]], d, urldata[scms[0]].names[0])
+        if autoinc:
+            return "AUTOINC+" + rev
+        return rev
 
     #
     # Mutiple SCMs are in SRC_URI so we resort to SRCREV_FORMAT
@@ -625,18 +628,14 @@ def get_srcrev(d):
     if not format:
         raise FetchError("The SRCREV_FORMAT variable must be set when multiple SCMs are used.")
 
-    autoinc = False
-    autoinc_templ = 'AUTOINC+'
+    seenautoinc = False
     for scm in scms:
         ud = urldata[scm]
         for name in ud.names:
-            rev = ud.method.sortable_revision(scm, ud, d, name)
-            if rev.startswith(autoinc_templ):
-                if not autoinc:
-                    autoinc = True
-                    format = "%s%s" % (autoinc_templ, format)
-                rev = rev[len(autoinc_templ):]
-
+            autoinc, rev = ud.method.sortable_revision(scm, ud, d, name)
+            if autoinc and not seenautoinc:
+                rev = "AUTOINC+" + rev
+                seenautoinc
             format = format.replace(name, rev)
 
     return format
@@ -1280,14 +1279,8 @@ class FetchMethod(object):
             return rev
 
     def sortable_revision(self, url, ud, d, name):
-        """
-
-        """
-        if hasattr(self, "_sortable_revision"):
-            return self._sortable_revision(url, ud, d)
-
         latest_rev = self._build_revision(url, ud, d, name)
-        return 'AUTOINC+%s' % str(latest_rev)
+        return True, str(latest_rev)
 
     def generate_revision_key(self, url, ud, d, name):
         key = self._revision_key(url, ud, d, name)
bitbake/lib/bb/fetch2/bzr.py +2 -2
index 58e80c8..5d9e5f9 100644
@@ -132,12 +132,12 @@ class Bzr(FetchMethod):
 
         return output.strip()
 
-    def _sortable_revision(self, url, ud, d):
+    def sortable_revision(self, url, ud, d, name):
         """
         Return a sortable revision number which in our case is the revision number
         """
 
-        return self._build_revision(url, ud, d)
+        return False, self._build_revision(url, ud, d)
 
     def _build_revision(self, url, ud, d):
         return ud.revision
bitbake/lib/bb/fetch2/svn.py +2 -2
index cbf929e..9a779d2 100644
@@ -178,12 +178,12 @@ class Svn(FetchMethod):
 
         return revision
 
-    def _sortable_revision(self, url, ud, d):
+    def sortable_revision(self, url, ud, d, name):
         """
         Return a sortable revision number which in our case is the revision number
         """
 
-        return self._build_revision(url, ud, d)
+        return False, self._build_revision(url, ud, d)
 
     def _build_revision(self, url, ud, d):
         return ud.revision
#1 lore raw
Quoted 24 lines · Richard Purdie

Now we no longer try and provide increasing values from the fetcher, we can simplify the function structure for the sortable_revision pieces and move the AUTOINC handling directly into the function which needs it, simplifying the code.

---

bitbake/lib/bb/fetch2/__init__.py +4 -1
index dd1cc93..f8f8244 100644
@@ -616,7 +616,10 @@ def get_srcrev(d):
         raise FetchError("SRCREV was used yet no valid SCM was found in SRC_URI")
 
     if len(scms) == 1 and len(urldata[scms[0]].names) == 1:
-        return urldata[scms[0]].method.sortable_revision(scms[0], urldata[scms[0]], d, urldata[scms[0]].names[0])
+        autoinc, rev = urldata[scms[0]].method.sortable_revision(scms[0], urldata[scms[0]], d, urldata[scms[0]].names[0])
+        if autoinc:
+            return "AUTOINC+" + rev
+        return rev
 
     #
     # Mutiple SCMs are in SRC_URI so we resort to SRCREV_FORMAT

bitbake/lib/bb/fetch2/__init__.py def get_srcrev(d): · line 629

Quoted 5 lines
bitbake/lib/bb/fetch2/__init__.py +0 -2
@@ -625,18 +628,14 @@ def get_srcrev(d):
     if not format:
         raise FetchError("The SRCREV_FORMAT variable must be set when multiple SCMs are used.")
 
-    autoinc = False
-    autoinc_templ = 'AUTOINC+'

Could we perhaps make use of the autoinc_tmpl is the previous hunk as well so as to not have the AUTOINC+ string written out explicitly in multiple places? Magic numbers and all that?

Quoted 4 lines
bitbake/lib/bb/fetch2/__init__.py +1 -0
+    seenautoinc = False
     for scm in scms:
         ud = urldata[scm]
         for name in ud.names:

bitbake/lib/bb/fetch2/__init__.py def get_srcrev(d): · line 637

Quoted 10 lines
bitbake/lib/bb/fetch2/__init__.py +3 -7
-            rev = ud.method.sortable_revision(scm, ud, d, name)
-            if rev.startswith(autoinc_templ):
-                if not autoinc:
-                    autoinc = True
-                    format = "%s%s" % (autoinc_templ, format)
-                rev = rev[len(autoinc_templ):]
-
+            autoinc, rev = ud.method.sortable_revision(scm, ud, d, name)
+            if autoinc and not seenautoinc:
+                rev = "AUTOINC+" + rev

autoinc_templ here?

Thanks,

--
Darren

Quoted 60 lines
bitbake/lib/bb/fetch2/__init__.py +2 -7
+                seenautoinc
             format = format.replace(name, rev)
 
     return format
@@ -1280,14 +1279,8 @@ class FetchMethod(object):
             return rev
 
     def sortable_revision(self, url, ud, d, name):
-        """
-
-        """
-        if hasattr(self, "_sortable_revision"):
-            return self._sortable_revision(url, ud, d)
-
         latest_rev = self._build_revision(url, ud, d, name)
-        return 'AUTOINC+%s' % str(latest_rev)
+        return True, str(latest_rev)
 
     def generate_revision_key(self, url, ud, d, name):
         key = self._revision_key(url, ud, d, name)
bitbake/lib/bb/fetch2/bzr.py +2 -2
index 58e80c8..5d9e5f9 100644
@@ -132,12 +132,12 @@ class Bzr(FetchMethod):
 
         return output.strip()
 
-    def _sortable_revision(self, url, ud, d):
+    def sortable_revision(self, url, ud, d, name):
         """
         Return a sortable revision number which in our case is the revision number
         """
 
-        return self._build_revision(url, ud, d)
+        return False, self._build_revision(url, ud, d)
 
     def _build_revision(self, url, ud, d):
         return ud.revision
bitbake/lib/bb/fetch2/svn.py +2 -2
index cbf929e..9a779d2 100644
@@ -178,12 +178,12 @@ class Svn(FetchMethod):
 
         return revision
 
-    def _sortable_revision(self, url, ud, d):
+    def sortable_revision(self, url, ud, d, name):
         """
         Return a sortable revision number which in our case is the revision number
         """
 
-        return self._build_revision(url, ud, d)
+        return False, self._build_revision(url, ud, d)
 
     def _build_revision(self, url, ud, d):
         return ud.revision
Signature · 3 lines
Darren Hart
Intel Open Source Technology Center
Yocto Project - Linux Kernel
#2 lore raw
In reply to Richard Purdie
Quoted 34 lines · Richard Purdie

Now we no longer try and provide increasing values from the fetcher, we can simplify the function structure for the sortable_revision pieces and move the AUTOINC handling directly into the function which needs it, simplifying the code.

---

bitbake/lib/bb/fetch2/__init__.py +5 -4
index dd1cc93..f8f8244 100644
@@ -616,7 +616,10 @@ def get_srcrev(d):
          raise FetchError("SRCREV was used yet no valid SCM was found in SRC_URI")
 
      if len(scms) == 1 and len(urldata[scms[0]].names) == 1:
-        return urldata[scms[0]].method.sortable_revision(scms[0], urldata[scms[0]], d, urldata[scms[0]].names[0])
+        autoinc, rev = urldata[scms[0]].method.sortable_revision(scms[0], urldata[scms[0]], d, urldata[scms[0]].names[0])
+        if autoinc:
+            return "AUTOINC+" + rev
+        return rev
 
      #
      # Mutiple SCMs are in SRC_URI so we resort to SRCREV_FORMAT
@@ -625,18 +628,14 @@ def get_srcrev(d):
      if not format:
          raise FetchError("The SRCREV_FORMAT variable must be set when multiple SCMs are used.")
 
-    autoinc = False
-    autoinc_templ = 'AUTOINC+'
+    seenautoinc = False
      for scm in scms:
          ud = urldata[scm]
          for name in ud.names:
-            rev = ud.method.sortable_revision(scm, ud, d, name)

bitbake/lib/bb/fetch2/__init__.py def get_srcrev(d): · line 638

Quoted 10 lines
bitbake/lib/bb/fetch2/__init__.py +4 -6
-            if rev.startswith(autoinc_templ):
-                if not autoinc:
-                    autoinc = True
-                    format = "%s%s" % (autoinc_templ, format)
-                rev = rev[len(autoinc_templ):]
-
+            autoinc, rev = ud.method.sortable_revision(scm, ud, d, name)
+            if autoinc and not seenautoinc:
+                rev = "AUTOINC+" + rev
+                seenautoinc

Should this be: seenautoinc = True ??

Sau!

Quoted 65 lines
bitbake/lib/bb/fetch2/__init__.py +1 -7
              format = format.replace(name, rev)
 
      return format
@@ -1280,14 +1279,8 @@ class FetchMethod(object):
              return rev
 
      def sortable_revision(self, url, ud, d, name):
-        """
-
-        """
-        if hasattr(self, "_sortable_revision"):
-            return self._sortable_revision(url, ud, d)
-
          latest_rev = self._build_revision(url, ud, d, name)
-        return 'AUTOINC+%s' % str(latest_rev)
+        return True, str(latest_rev)
 
      def generate_revision_key(self, url, ud, d, name):
          key = self._revision_key(url, ud, d, name)
bitbake/lib/bb/fetch2/bzr.py +2 -2
index 58e80c8..5d9e5f9 100644
@@ -132,12 +132,12 @@ class Bzr(FetchMethod):
 
          return output.strip()
 
-    def _sortable_revision(self, url, ud, d):
+    def sortable_revision(self, url, ud, d, name):
          """
          Return a sortable revision number which in our case is the revision number
          """
 
-        return self._build_revision(url, ud, d)
+        return False, self._build_revision(url, ud, d)
 
      def _build_revision(self, url, ud, d):
          return ud.revision
bitbake/lib/bb/fetch2/svn.py +2 -2
index cbf929e..9a779d2 100644
@@ -178,12 +178,12 @@ class Svn(FetchMethod):
 
          return revision
 
-    def _sortable_revision(self, url, ud, d):
+    def sortable_revision(self, url, ud, d, name):
          """
          Return a sortable revision number which in our case is the revision number
          """
 
-        return self._build_revision(url, ud, d)
+        return False, self._build_revision(url, ud, d)
 
      def _build_revision(self, url, ud, d):
          return ud.revision

_______________________________________________
bitbake-devel mailing list
[email protected]
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/bitbake-devel