This is an automated email from the ASF dual-hosted git repository.

tvb pushed a commit to branch tristan/prefer-better-version-matches
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit 9df213892acb712cc8826437a608de4c051793be
Author: Tristan van Berkom <[email protected]>
AuthorDate: Wed May 7 15:55:18 2025 +0900

    downloadablefilesource.py: Prefer better qualified version guesses
    
    When observing a typical release tarball URL, prefer versions which
    are more qualified.
    
    E.g. if we have: 
https://flying-ponies.com/releases/1.2/pony-flight-1.2.3.tgz
    
    Then we want to report 1.2.3, and not just 1.2
---
 src/buildstream/downloadablefilesource.py | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/src/buildstream/downloadablefilesource.py 
b/src/buildstream/downloadablefilesource.py
index b382214d7..a47b142b6 100644
--- a/src/buildstream/downloadablefilesource.py
+++ b/src/buildstream/downloadablefilesource.py
@@ -140,7 +140,7 @@ Further, the DownloadableFileSourcebzr source reports the
 for which it reports the sha256 checksum of the remote file content as the 
*version*.
 
 An attempt to guess the version based on the remote filename will be made
-for the reporting of the *guess_version*. Control over how the guess is made
+for the reporting of the *version_guess*. Control over how the guess is made
 or overridden is explained above in the
 :ref:`built-in functionality documentation 
<core_downloadable_source_builtins>`.
 """
@@ -353,13 +353,19 @@ class DownloadableFileSource(Source):
 
     def collect_source_info(self):
         if self._version is None:
-            version_match = self._guess_pattern.search(self.original_url)
-            if not version_match:
-                version_guess = None
-            elif self._guess_pattern.groups == 0:
-                version_guess = version_match.group(0)
-            else:
-                version_guess = ".".join(version_match.groups())
+            version_guess = None
+
+            # Iterate over non-overlapping matches, and prefer a match which 
is more qualified (i.e. 1.2.3 is better than 1.2)
+            for version_match in 
self._guess_pattern.finditer(self.original_url):
+                if not version_match:
+                    iter_guess = None
+                elif self._guess_pattern.groups == 0:
+                    iter_guess = version_match.group(0)
+                else:
+                    iter_guess = ".".join(version_match.groups())
+
+                if version_guess is None or len(iter_guess) > 
len(version_guess):
+                    version_guess = iter_guess
         else:
             version_guess = self._version
 

Reply via email to