Skip to contentSkip to conversation

bitbake: fetch2: Make SRCREV_FORMAT name substitution safer

PATCH In review Ulf Magnusson 1 participant 2 messages Sep 12, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bitbake: fetch2: Make SRCREV_FORMAT name substitution safer

Given two names "foo" and "foobar" and SRCREV_FORMAT = "foo_foobar", "foo" might currently get substituted twice. Work around the issue by sorting the list of names by length and substituting longer names first.

---
 bitbake/lib/bb/fetch2/__init__.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
bitbake/lib/bb/fetch2/__init__.py +4 -1
index 11c75cc..4ca024e 100644
@@ -764,7 +764,10 @@ def get_srcrev(d, method_name='sortable_revision'):
     seenautoinc = False
     for scm in scms:
         ud = urldata[scm]
-        for name in ud.names:
+        # Sort the list of names and replace the longest names first. Given two
+        # names "foo" and "foobar", this prevents "foo" being substituted twice
+        # in "foo_foobar" (and "foobar" from not being substituted at all).
+        for name in sorted(ud.names, key=len, reverse=True):
             autoinc, rev = getattr(ud.method, method_name)(ud, d, name)
             seenautoinc = seenautoinc or autoinc
             if len(rev) > 10:
Signature · 1 line
2.5.0
#1 lore raw
Quoted 26 lines · Ulf Magnusson

Given two names "foo" and "foobar" and SRCREV_FORMAT = "foo_foobar", "foo" might currently get substituted twice. Work around the issue by sorting the list of names by length and substituting longer names first.

---
 bitbake/lib/bb/fetch2/__init__.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
bitbake/lib/bb/fetch2/__init__.py +4 -2
index 11c75cc..4ca024e 100644
@@ -764,7 +764,10 @@ def get_srcrev(d, method_name='sortable_revision'):
     seenautoinc = False
     for scm in scms:
         ud = urldata[scm]
-        for name in ud.names:
+        # Sort the list of names and replace the longest names first. Given two
+        # names "foo" and "foobar", this prevents "foo" being substituted twice
+        # in "foo_foobar" (and "foobar" from not being substituted at all).
+        for name in sorted(ud.names, key=len, reverse=True):
             autoinc, rev = getattr(ud.method, method_name)(ud, d, name)
             seenautoinc = seenautoinc or autoinc
             if len(rev) > 10:
--
Quoted 2 lines

2.5.0

Hrm... the bitbake-devel mailing list would be a better fit. Sent it there too.

Cheers,
Ulf