summaryrefslogtreecommitdiffstats
path: root/lib/bb/fetch2/git.py
diff options
context:
space:
mode:
authorAníbal Limón <anibal.limon@linux.intel.com>2014-11-05 12:10:28 -0600
committerRichard Purdie <richard.purdie@linuxfoundation.org>2014-11-08 11:01:43 +0000
commitf71c8c0354e87fed80bc845db6728e6e18ce9c4d (patch)
treef314ce5692b7f5c642fc9a20389c90bbef47d49c /lib/bb/fetch2/git.py
parent9f171ea755644ecd9d2b3d7ed13bf8ec09ec917a (diff)
downloadopenembedded-core-contrib-f71c8c0354e87fed80bc845db6728e6e18ce9c4d.tar.gz
fetch/git: Add latest_versionstring method
Being able to generate a version string representing the most recent git commit given git is useful, not least for the package reporting system. This adds in a latest_versionstring method to the git fetcher which allows users to query the latest version using ls-remote and filtering the responses. The patch also adds unittests for this function so that if improvements are made, the original test urls can be used to evaulate the those changes. This is based on code from Irina Patru <irina.patru@intel.com>. Signed-off-by: Saul Wold <sgw@linux.intel.com> Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'lib/bb/fetch2/git.py')
-rw-r--r--lib/bb/fetch2/git.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/bb/fetch2/git.py b/lib/bb/fetch2/git.py
index 66a77a8376..f771fd02b6 100644
--- a/lib/bb/fetch2/git.py
+++ b/lib/bb/fetch2/git.py
@@ -67,6 +67,7 @@ Supported SRC_URI options are:
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import os
+import re
import bb
from bb import data
from bb.fetch2 import FetchMethod
@@ -346,6 +347,43 @@ class Git(FetchMethod):
output = self._lsremote(ud, d, search)
return output.split()[0]
+ def latest_versionstring(self, ud, d):
+ """
+ Compute the latest release name like "x.y.x" in "x.y.x+gitHASH"
+ by searching through the tags output of ls-remote, comparing
+ versions and returning the highest match.
+ """
+ verstring = ""
+ tagregex = re.compile(d.getVar('GITTAGREGEX', True) or "(?P<pver>([0-9][\.|_]?)+)")
+ try:
+ output = self._lsremote(ud, d, "refs/tags/*^{}")
+ except bb.fetch2.FetchError or bb.fetch2.NetworkAccess:
+ return ""
+
+ for line in output.split("\n"):
+ if not line:
+ break
+
+ line = line.split("/")[-1]
+ # Ignore non-released branches
+ m = re.search("(alpha|beta|rc|final)+", line)
+ if m:
+ continue
+
+ # search for version in the line
+ tag = tagregex.search(line)
+ if tag == None:
+ continue
+
+ tag = tag.group('pver')
+ tag = tag.replace("_", ".")
+
+ if verstring and bb.utils.vercmp(("0", tag, ""), ("0", verstring, "")) < 0:
+ continue
+ verstring = tag
+
+ return verstring
+
def _build_revision(self, ud, d, name):
return ud.revisions[name]