Skip to contentSkip to conversation

fetch2/git: Handle srcrevs for annotated tags in tag check

PATCH In review Richard Purdie 2 participants 4 messages Apr 2, 2025 – Apr 3, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fetch2/git: Handle srcrevs for annotated tags in tag check

If SRCREV points at an annotated tag, the comparision code can fail as the resolved tag might not be the same sha.

Handle this by also resolving the SRCREV. We only need to do this if they don't match in the first place for a minor performance win.

Also add a test for this.

---
 lib/bb/fetch2/git.py  | 7 ++++++-
 lib/bb/tests/fetch.py | 7 +++++++
 2 files changed, 13 insertions(+), 1 deletion(-)
lib/bb/fetch2/git.py +6 -1
index 3a4ae6df45..5f4ec6128c 100644
@@ -730,7 +730,12 @@ class Git(FetchMethod):
             output = runfetchcmd("%s rev-list -n 1 %s" % (ud.basecmd, ud.parm['tag']), d, workdir=destdir)
             output = output.strip()
             if output != ud.revision:
-                raise bb.fetch2.FetchError("The revision the git tag '%s' resolved to didn't match the SRCREV in use (%s vs %s)" % (ud.parm['tag'], output, ud.revision), ud.url)
+                # It is possible ud.revision is the revision on an annotated tag which won't match the output of rev-list
+                # If it resolves to the same thing there isn't a problem.
+                output2 = runfetchcmd("%s rev-list -n 1 %s" % (ud.basecmd, ud.revision), d, workdir=destdir)
+                output2 = output2.strip()
+                if output != output2:
+                    raise bb.fetch2.FetchError("The revision the git tag '%s' resolved to didn't match the SRCREV in use (%s vs %s)" % (ud.parm['tag'], output, ud.revision), ud.url)
 
         repourl = self._get_repo_url(ud)
         runfetchcmd("%s remote set-url origin %s" % (ud.basecmd, shlex.quote(repourl)), d, workdir=destdir)
lib/bb/tests/fetch.py +7 -0
index 8de6862482..196d93c414 100644
@@ -3139,6 +3139,13 @@ class GitTagVerificationTests(FetcherTest):
         fetcher.download()
         fetcher.unpack(self.unpackdir)
 
+    def test_annotated_tag_rev_match(self):
+        # Test a url with rev= and tag= set works
+        # rev is the annotated tag revision in this case
+        fetcher = bb.fetch.Fetch(["git://git.openembedded.org/bitbake;branch=2.8;protocol=https;rev=6d363159e4b7dc566fc40d069b2615e61774a7d8;tag=2.8.7"], self.d)
+        fetcher.download()
+        fetcher.unpack(self.unpackdir)
+
     @skipIfNoNetwork()
     def test_tag_rev_match2(self):
         # Test a url with SRCREV and tag= set works
#1 lore raw
Quoted 25 lines

-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of Richard Purdie via lists.openembedded.org
Sent: den 2 april 2025 16:01
To: [email protected]
Subject: [bitbake-devel] [PATCH] fetch2/git: Handle srcrevs for annotated tags in tag check

If SRCREV points at an annotated tag, the comparision code can fail as the resolved tag might not be the same sha.

Handle this by also resolving the SRCREV. We only need to do this if they don't match in the first place for a minor performance win.

Also add a test for this.

---
 lib/bb/fetch2/git.py  | 7 ++++++-
 lib/bb/tests/fetch.py | 7 +++++++
 2 files changed, 13 insertions(+), 1 deletion(-)
lib/bb/fetch2/git.py +0 -0
index 3a4ae6df45..5f4ec6128c 100644

lib/bb/fetch2/git.py class Git(FetchMethod): · line 730

Quoted 1 line
lib/bb/fetch2/git.py +0 -0
@@ -730,7 +730,12 @@ class Git(FetchMethod):
             output = runfetchcmd("%s rev-list -n 1 %s" % (ud.basecmd, ud.parm['tag']), d, workdir=destdir)

I recommend using Git's syntax for getting the SHA-1 for the commit directly from the tag instead, "tag^{}". That should work in both cases:

            output = runfetchcmd("%s rev-list -n 1 %s^{}" % (ud.basecmd, ud.parm['tag']), d, workdir=destdir)
Quoted 30 lines
lib/bb/fetch2/git.py +6 -1
             output = output.strip()
             if output != ud.revision:
-                raise bb.fetch2.FetchError("The revision the git tag '%s' resolved to didn't match the SRCREV in use (%s vs %s)" % (ud.parm['tag'], output, ud.revision), ud.url)
+                # It is possible ud.revision is the revision on an annotated tag which won't match the output of rev-list
+                # If it resolves to the same thing there isn't a problem.
+                output2 = runfetchcmd("%s rev-list -n 1 %s" % (ud.basecmd, ud.revision), d, workdir=destdir)
+                output2 = output2.strip()
+                if output != output2:
+                    raise bb.fetch2.FetchError("The revision the git tag '%s' resolved to didn't match the SRCREV in use (%s vs %s)" % (ud.parm['tag'], output, ud.revision), ud.url)
 
         repourl = self._get_repo_url(ud)
         runfetchcmd("%s remote set-url origin %s" % (ud.basecmd, shlex.quote(repourl)), d, workdir=destdir)
lib/bb/tests/fetch.py +7 -0
index 8de6862482..196d93c414 100644
@@ -3139,6 +3139,13 @@ class GitTagVerificationTests(FetcherTest):
         fetcher.download()
         fetcher.unpack(self.unpackdir)
 
+    def test_annotated_tag_rev_match(self):
+        # Test a url with rev= and tag= set works
+        # rev is the annotated tag revision in this case
+        fetcher = bb.fetch.Fetch(["git://git.openembedded.org/bitbake;branch=2.8;protocol=https;rev=6d363159e4b7dc566fc40d069b2615e61774a7d8;tag=2.8.7"], self.d)
+        fetcher.download()
+        fetcher.unpack(self.unpackdir)
+
     @skipIfNoNetwork()
     def test_tag_rev_match2(self):
         # Test a url with SRCREV and tag= set works
#2 lore raw
Quoted 30 lines · Peter Kjellerstedt
Quoted 25 lines

-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of Richard Purdie via lists.openembedded.org
Sent: den 2 april 2025 16:01
To: [email protected]
Subject: [bitbake-devel] [PATCH] fetch2/git: Handle srcrevs for annotated tags in tag check

If SRCREV points at an annotated tag, the comparision code can fail as the resolved tag might not be the same sha.

Handle this by also resolving the SRCREV. We only need to do this if they don't match in the first place for a minor performance win.

Also add a test for this.

---
 lib/bb/fetch2/git.py  | 7 ++++++-
 lib/bb/tests/fetch.py | 7 +++++++

 2 files changed, 13 insertions(+), 1 deletion(-)
lib/bb/fetch2/git.py +0 -0
index 3a4ae6df45..5f4ec6128c 100644

lib/bb/fetch2/git.py class Git(FetchMethod): · line 730

Quoted 1 line
lib/bb/fetch2/git.py +0 -0
@@ -730,7 +730,12 @@ class Git(FetchMethod):
              output = runfetchcmd("%s rev-list -n 1 %s" % (ud.basecmd, ud.parm['tag']), d, workdir=destdir)

I recommend using Git's syntax for getting the SHA-1 for the commit directly from the tag instead, "tag^{}". That should work in both cases:

Quoted 1 line

            output = runfetchcmd("%s rev-list -n 1 %s^{}" % (ud.basecmd, ud.parm['tag']), d, workdir=destdir)

We can't know if the srcrev used in the recipe is the annotated tag or the commit sha so you have to potentially resolve both and I'm not sure how this helps?

Cheers,

Richard

#3 lore raw
Quoted 44 lines

-----Original Message-----
From: Richard Purdie <[email protected]>
Sent: den 2 april 2025 16:24
To: Peter Kjellerstedt <[email protected]>; bitbake- [email protected]
Subject: Re: [bitbake-devel] [PATCH] fetch2/git: Handle srcrevs for annotated tags in tag check

Quoted 2 lines · Peter Kjellerstedt
Quoted 2 lines

-----Original Message-----
From: [email protected] <bitbake-

[email protected]> On Behalf Of Richard Purdie via lists.openembedded.org

Quoted 3 lines
Quoted 3 lines

Sent: den 2 april 2025 16:01
To: [email protected]
Subject: [bitbake-devel] [PATCH] fetch2/git: Handle srcrevs for

annotated tags in tag check

Quoted 25 lines
Quoted 20 lines

If SRCREV points at an annotated tag, the comparision code can fail as the resolved tag might not be the same sha.

Handle this by also resolving the SRCREV. We only need to do this if they don't match in the first place for a minor performance win.

Also add a test for this.

---
 lib/bb/fetch2/git.py  | 7 ++++++-
 lib/bb/tests/fetch.py | 7 +++++++

 2 files changed, 13 insertions(+), 1 deletion(-)
lib/bb/fetch2/git.py +0 -0
index 3a4ae6df45..5f4ec6128c 100644

lib/bb/fetch2/git.py class Git(FetchMethod): · line 730

Quoted 1 line
lib/bb/fetch2/git.py +0 -0
@@ -730,7 +730,12 @@ class Git(FetchMethod):
              output = runfetchcmd("%s rev-list -n 1 %s" % (ud.basecmd, ud.parm['tag']), d, workdir=destdir)

I recommend using Git's syntax for getting the SHA-1 for the commit directly from the tag instead, "tag^{}". That should work in both cases:

Quoted 1 line

            output = runfetchcmd("%s rev-list -n 1 %s^{}" % (ud.basecmd, ud.parm['tag']), d, workdir=destdir)

Quoted 7 lines

We can't know if the srcrev used in the recipe is the annotated tag or the commit sha so you have to potentially resolve both and I'm not sure how this helps?

Cheers,

Richard

Sorry, my bad. I misinterpreted what the code was doing.

//Peter