Patchwork [bitbake-devel] fetch2/git: Clean up sortable_revision

login
register
mail settings
Submitter Richard Purdie
Date May 19, 2013, 10:17 a.m.
Message ID <1368958678.32727.92.camel@ted>
Download mbox | patch
Permalink /patch/50083/
State New
Headers show

Comments

Richard Purdie - May 19, 2013, 10:17 a.m.
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.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
Darren Hart - May 19, 2013, 4:59 p.m.
On 05/19/2013 03:17 AM, Richard Purdie wrote:
> 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.
> 
> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
> ---
> diff --git a/bitbake/lib/bb/fetch2/__init__.py b/bitbake/lib/bb/fetch2/__init__.py
> index dd1cc93..f8f8244 100644
> --- a/bitbake/lib/bb/fetch2/__init__.py
> +++ b/bitbake/lib/bb/fetch2/__init__.py
> @@ -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+'


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?


> +    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


autoinc_templ here?

Thanks,

--
Darren

> +                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)
> diff --git a/bitbake/lib/bb/fetch2/bzr.py b/bitbake/lib/bb/fetch2/bzr.py
> index 58e80c8..5d9e5f9 100644
> --- a/bitbake/lib/bb/fetch2/bzr.py
> +++ b/bitbake/lib/bb/fetch2/bzr.py
> @@ -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
> diff --git a/bitbake/lib/bb/fetch2/svn.py b/bitbake/lib/bb/fetch2/svn.py
> index cbf929e..9a779d2 100644
> --- a/bitbake/lib/bb/fetch2/svn.py
> +++ b/bitbake/lib/bb/fetch2/svn.py
> @@ -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
> 
>
Saul Wold - May 22, 2013, 10:27 p.m.
On 05/19/2013 03:17 AM, Richard Purdie wrote:
> 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.
>
> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
> ---
> diff --git a/bitbake/lib/bb/fetch2/__init__.py b/bitbake/lib/bb/fetch2/__init__.py
> index dd1cc93..f8f8244 100644
> --- a/bitbake/lib/bb/fetch2/__init__.py
> +++ b/bitbake/lib/bb/fetch2/__init__.py
> @@ -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
Should this be: seenautoinc = True  ??

Sau!

>               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)
> diff --git a/bitbake/lib/bb/fetch2/bzr.py b/bitbake/lib/bb/fetch2/bzr.py
> index 58e80c8..5d9e5f9 100644
> --- a/bitbake/lib/bb/fetch2/bzr.py
> +++ b/bitbake/lib/bb/fetch2/bzr.py
> @@ -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
> diff --git a/bitbake/lib/bb/fetch2/svn.py b/bitbake/lib/bb/fetch2/svn.py
> index cbf929e..9a779d2 100644
> --- a/bitbake/lib/bb/fetch2/svn.py
> +++ b/bitbake/lib/bb/fetch2/svn.py
> @@ -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
> bitbake-devel@lists.openembedded.org
> http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/bitbake-devel
>

Patch

diff --git a/bitbake/lib/bb/fetch2/__init__.py b/bitbake/lib/bb/fetch2/__init__.py
index dd1cc93..f8f8244 100644
--- a/bitbake/lib/bb/fetch2/__init__.py
+++ b/bitbake/lib/bb/fetch2/__init__.py
@@ -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)
diff --git a/bitbake/lib/bb/fetch2/bzr.py b/bitbake/lib/bb/fetch2/bzr.py
index 58e80c8..5d9e5f9 100644
--- a/bitbake/lib/bb/fetch2/bzr.py
+++ b/bitbake/lib/bb/fetch2/bzr.py
@@ -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
diff --git a/bitbake/lib/bb/fetch2/svn.py b/bitbake/lib/bb/fetch2/svn.py
index cbf929e..9a779d2 100644
--- a/bitbake/lib/bb/fetch2/svn.py
+++ b/bitbake/lib/bb/fetch2/svn.py
@@ -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