Patchwork [bitbake-devel,RFC] WIP: git: prefix with refs/tags/ when revision isn't git hash

login
register
mail settings
Submitter Martin Jansa
Date Aug. 11, 2013, 8:36 a.m.
Message ID <1376210197-10265-1-git-send-email-Martin.Jansa@gmail.com>
Download mbox | patch
Permalink /patch/55453/
State New
Headers show

Comments

Martin Jansa - Aug. 11, 2013, 8:36 a.m.
* many Open webOS components have tag in format
  submissions/N, versions/X.Y.Z
  just by chance I've noticed that git ls-remote behaves a bit different
  than what I've expected:

  We were using tag=18 in SRC_URI.
  librolegen repository doesn't have tag '18'
  $ git tag -l
  submissions/0
  submissions/16
  submissions/17
  submissions/18
  version/2.0.0
  versions/2.1.0

  It was working correctly until now, just because we were lucky.

  From git help ls-remote:
    When <refs>... are specified, only references matching the given
    patterns are displayed.
  $ git ls-remote git://github.com/openwebos/librolegen 18
    cbedc69733f65cd2f498787a621c014e219d38ab        refs/tags/submissions/18
  $ git ls-remote git://github.com/openwebos/librolegen 17
    af5b0e7b514938d5589c89ab9508ad23dce43e98        refs/tags/submissions/17
  $ git ls-remote git://github.com/openwebos/librolegen
    9040954a24115b05219e7dd459dcf91ad05cc739        HEAD
    9040954a24115b05219e7dd459dcf91ad05cc739        refs/heads/master
    85524970dba46557d3c9672455a4a88165efe7f1        refs/notes/review
    fe509e33f5d68c834bce087dff0f6c801d869b68        refs/tags/submissions/0
    04bc2c24ce628de3ac0fba8afce088f2391f96bb        refs/tags/submissions/0^{}
    7aa394eea6bd76618337772894f7615d0ae8e13a        refs/tags/submissions/16
    af5b0e7b514938d5589c89ab9508ad23dce43e98        refs/tags/submissions/17
    cbedc69733f65cd2f498787a621c014e219d38ab        refs/tags/submissions/18
    9040954a24115b05219e7dd459dcf91ad05cc739        refs/tags/submissions/18^{}
    7aa394eea6bd76618337772894f7615d0ae8e13a        refs/tags/version/2.0.0
    af5b0e7b514938d5589c89ab9508ad23dce43e98        refs/tags/versions/2.1.0

    So if someone creates tag 'foo/18' ls-remote will return both lines and
    build will fail.

    Prefixing with 'refs/tags/' will work in this case, but I haven't tested
    if this code breaks AUTOREV or other use-cases -> that's why it's RFC + WIP.

Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
---
 lib/bb/fetch2/git.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Richard Purdie - Aug. 12, 2013, 11:26 a.m.
On Sun, 2013-08-11 at 10:36 +0200, Martin Jansa wrote:
> * many Open webOS components have tag in format
>   submissions/N, versions/X.Y.Z
>   just by chance I've noticed that git ls-remote behaves a bit different
>   than what I've expected:
> 
>   We were using tag=18 in SRC_URI.
>   librolegen repository doesn't have tag '18'
>   $ git tag -l
>   submissions/0
>   submissions/16
>   submissions/17
>   submissions/18
>   version/2.0.0
>   versions/2.1.0
> 
>   It was working correctly until now, just because we were lucky.
> 
>   From git help ls-remote:
>     When <refs>... are specified, only references matching the given
>     patterns are displayed.
>   $ git ls-remote git://github.com/openwebos/librolegen 18
>     cbedc69733f65cd2f498787a621c014e219d38ab        refs/tags/submissions/18
>   $ git ls-remote git://github.com/openwebos/librolegen 17
>     af5b0e7b514938d5589c89ab9508ad23dce43e98        refs/tags/submissions/17
>   $ git ls-remote git://github.com/openwebos/librolegen
>     9040954a24115b05219e7dd459dcf91ad05cc739        HEAD
>     9040954a24115b05219e7dd459dcf91ad05cc739        refs/heads/master
>     85524970dba46557d3c9672455a4a88165efe7f1        refs/notes/review
>     fe509e33f5d68c834bce087dff0f6c801d869b68        refs/tags/submissions/0
>     04bc2c24ce628de3ac0fba8afce088f2391f96bb        refs/tags/submissions/0^{}
>     7aa394eea6bd76618337772894f7615d0ae8e13a        refs/tags/submissions/16
>     af5b0e7b514938d5589c89ab9508ad23dce43e98        refs/tags/submissions/17
>     cbedc69733f65cd2f498787a621c014e219d38ab        refs/tags/submissions/18
>     9040954a24115b05219e7dd459dcf91ad05cc739        refs/tags/submissions/18^{}
>     7aa394eea6bd76618337772894f7615d0ae8e13a        refs/tags/version/2.0.0
>     af5b0e7b514938d5589c89ab9508ad23dce43e98        refs/tags/versions/2.1.0
> 
>     So if someone creates tag 'foo/18' ls-remote will return both lines and
>     build will fail.
> 
>     Prefixing with 'refs/tags/' will work in this case, but I haven't tested
>     if this code breaks AUTOREV or other use-cases -> that's why it's RFC + WIP.
> 
> Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
> ---
>  lib/bb/fetch2/git.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/bb/fetch2/git.py b/lib/bb/fetch2/git.py
> index 6175e4c..ebb5722 100644
> --- a/lib/bb/fetch2/git.py
> +++ b/lib/bb/fetch2/git.py
> @@ -124,7 +124,7 @@ class Git(FetchMethod):
>              # Ensure anything that doesn't look like a sha256 checksum/revision is translated into one
>              if not ud.revisions[name] or len(ud.revisions[name]) != 40  or (False in [c in "abcdef0123456789" for c in ud.revisions[name]]):
>                  if ud.revisions[name]:
> -                    ud.branches[name] = ud.revisions[name]
> +                    ud.branches[name] = "refs/tags/%s" % ud.revisions[name]
>                  ud.revisions[name] = self.latest_revision(ud.url, ud, d, name)
>  
>          gitsrcname = '%s%s' % (ud.host.replace(':','.'), ud.path.replace('/', '.').replace('*', '.'))

This may need to test "refs/heads/%s" before checking "refs/tags/%s"
since a head name or tag name are currently equally accepted in
revisions.

Also, what if ud.branches was already set to something, shouldn't we
error in that case? (I appreciate you haven't introduced that issue).

Cheers,

Richard

Patch

diff --git a/lib/bb/fetch2/git.py b/lib/bb/fetch2/git.py
index 6175e4c..ebb5722 100644
--- a/lib/bb/fetch2/git.py
+++ b/lib/bb/fetch2/git.py
@@ -124,7 +124,7 @@  class Git(FetchMethod):
             # Ensure anything that doesn't look like a sha256 checksum/revision is translated into one
             if not ud.revisions[name] or len(ud.revisions[name]) != 40  or (False in [c in "abcdef0123456789" for c in ud.revisions[name]]):
                 if ud.revisions[name]:
-                    ud.branches[name] = ud.revisions[name]
+                    ud.branches[name] = "refs/tags/%s" % ud.revisions[name]
                 ud.revisions[name] = self.latest_revision(ud.url, ud, d, name)
 
         gitsrcname = '%s%s' % (ud.host.replace(':','.'), ud.path.replace('/', '.').replace('*', '.'))