Skip to contentSkip to conversation

fetch2/git: always use premirror first if update is required

PATCH In review Pascal Bach 3 participants 8 messages Sep 16, 2016 – Sep 22, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fetch2/git: always use premirror first if update is required

When an update of the local copy is required always try to fetch the update from a premirror first.
The premirror should always have precedence over the upstream repository as updating from there might not work if BB_FETCH_PREMIRRORONLY, BB_NO_NBB_ALLOWED_NETWORKS or BB_NO_NETWORK is set.

This also gets rid of the special case for BB_FETCH_PREMIRRORONLY.

---
 lib/bb/fetch2/git.py | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
lib/bb/fetch2/git.py +2 -7
index 1bec60a..cac2a87 100644
@@ -227,13 +227,8 @@ class Git(FetchMethod):
         return False
 
     def try_premirror(self, ud, d):
-        # If we don't do this, updating an existing checkout with only premirrors
-        # is not possible
-        if d.getVar("BB_FETCH_PREMIRRORONLY", True) is not None:
-            return True
-        if os.path.exists(ud.clonedir):
-            return False
-        return True
+        # Always try premirror if an update is required
+        return self.need_update(ud, d)
 
     def download(self, ud, d):
         """Fetch url"""
Signature · 1 line
2.1.4
#1 lore raw
Quoted 24 lines · Pascal Bach

When an update of the local copy is required always try to fetch the update from a premirror first.
The premirror should always have precedence over the upstream repository as updating from there might not work if BB_FETCH_PREMIRRORONLY, BB_NO_NBB_ALLOWED_NETWORKS or BB_NO_NETWORK is set.

This also gets rid of the special case for BB_FETCH_PREMIRRORONLY.

---
 lib/bb/fetch2/git.py | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
lib/bb/fetch2/git.py +0 -1
index 1bec60a..cac2a87 100644
@@ -227,13 +227,8 @@ class Git(FetchMethod):
         return False
 
     def try_premirror(self, ud, d):
-        # If we don't do this, updating an existing checkout with only

premirrors

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

Quoted 8 lines
lib/bb/fetch2/git.py +2 -6
-        # is not possible
-        if d.getVar("BB_FETCH_PREMIRRORONLY", True) is not None:
-            return True
-        if os.path.exists(ud.clonedir):
-            return False
-        return True
+        # Always try premirror if an update is required
+        return self.need_update(ud, d)

Will this result in fetching a mirror tarball even if you already have a clone in ud.clonedir? The previous logic always returned False if the clonedir existed..

Signature · 5 lines
Christopher Larson
clarson at kergoth dot com
Founder - BitBake, OpenEmbedded, OpenZaurus
Maintainer - Tslib
Senior Software Engineer, Mentor Graphics
#2 lore raw
Quoted 35 lines · Christopher Larson

On Fri, Sep 16, 2016 at 1:58 AM, Pascal Bach <[email protected] <mailto:[email protected]>> wrote:

When an update of the local copy is required always try to fetch the update from a premirror first.
The premirror should always have precedence over the upstream repository as updating from there might not work if BB_FETCH_PREMIRRORONLY, BB_NO_NBB_ALLOWED_NETWORKS or BB_NO_NETWORK is set.

This also gets rid of the special case for BB_FETCH_PREMIRRORONLY.

Signed-off-by Pascal Bach <[email protected] <mailto:[email protected]>>

---
lib/bb/fetch2/git.py | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/lib/bb/fetch2/git.py b/lib/bb/fetch2/git.py index 1bec60a..cac2a87 100644
--- a/lib/bb/fetch2/git.py
+++ b/lib/bb/fetch2/git.py
@@ -227,13 +227,8 @@ class Git(FetchMethod):
return False

def try_premirror(self, ud, d):
- # If we don't do this, updating an existing checkout with only premirrors
- # is not possible
- if d.getVar("BB_FETCH_PREMIRRORONLY", True) is not None:
- return True
- if os.path.exists(ud.clonedir):
- return False
- return True
+ # Always try premirror if an update is required
+ return self.need_update(ud, d)

Quoted 1 line

Will this result in fetching a mirror tarball even if you already have a clone in ud.clonedir? The previous logic always returned False if the clonedir existed..

The tarball should only be fetched if the local ud.clonedir is out of date, this means the revision that is requested via SRCREV is not in the local repository. In the case the revision is present the tarball should not be fetched again, at least that was the intention and my local tests didn't indicate otherwise.

Without this change the git fetcher would directly fall back to do a git fetch from the original source, which doesn't work if the build machine doesn't have access to the internet.

#3 lore raw
Quoted 43 lines · Pascal Bach
Quoted 2 lines · Christopher Larson

On Fri, Sep 16, 2016 at 1:58 AM, Pascal Bach <[email protected]

Quoted 2 lines · <mailto:[email protected]>> wrote:

When an update of the local copy is required always try to fetch the

update

Quoted 2 lines

from a premirror first.
The premirror should always have precedence over the upstream

repository

Quoted 6 lines

as updating from there might not work if BB_FETCH_PREMIRRORONLY, BB_NO_NBB_ALLOWED_NETWORKS or BB_NO_NETWORK is set.

This also gets rid of the special case for BB_FETCH_PREMIRRORONLY.

[email protected]>>

Quoted 5 lines
    ---
     lib/bb/fetch2/git.py | 9 ++-------
     1 file changed, 2 insertions(+), 7 deletions(-)

    diff --git a/lib/bb/fetch2/git.py b/lib/bb/fetch2/git.py
Quoted 8 lines
    index 1bec60a..cac2a87 100644
    --- a/lib/bb/fetch2/git.py
    +++ b/lib/bb/fetch2/git.py
    @@ -227,13 +227,8 @@ class Git(FetchMethod):
             return False

         def try_premirror(self, ud, d):
    -        # If we don't do this, updating an existing checkout with

only premirrors

Quoted 11 lines

- # is not possible
- if d.getVar("BB_FETCH_PREMIRRORONLY", True) is not None:
- return True
- if os.path.exists(ud.clonedir):
- return False
- return True
+ # Always try premirror if an update is required
+ return self.need_update(ud, d)

Will this result in fetching a mirror tarball even if you already have a

Quoted 9 lines

clone in ud.clonedir? The previous logic always returned False if the clonedir existed..
The tarball should only be fetched if the local ud.clonedir is out of date, this means the revision that is requested via SRCREV is not in the local repository.
In the case the revision is present the tarball should not be fetched again, at least that was the intention and my local tests didn't indicate otherwise.

Yes, but it’s better to run ‘git fetch’ in an out of date clone than to re-download a 1gb mirror tarball which may well be out of date too.

Signature · 5 lines
Christopher Larson
clarson at kergoth dot com
Founder - BitBake, OpenEmbedded, OpenZaurus
Maintainer - Tslib
Senior Software Engineer, Mentor Graphics
#4 lore raw
Quoted 40 lines · Christopher Larson

On Mon, Sep 19, 2016 at 12:22 AM, Pascal Bach <[email protected] <mailto:[email protected]>> wrote:

On 16.09.2016 18:20, Christopher Larson wrote:

>
> On Fri, Sep 16, 2016 at 1:58 AM, Pascal Bach <[email protected] <mailto:[email protected]> <mailto:[email protected] <mailto:[email protected]>>> wrote:
>
> When an update of the local copy is required always try to fetch the update
> from a premirror first.
> The premirror should always have precedence over the upstream repository
> as updating from there might not work if BB_FETCH_PREMIRRORONLY,
> BB_NO_NBB_ALLOWED_NETWORKS or BB_NO_NETWORK is set.
>
> This also gets rid of the special case for BB_FETCH_PREMIRRORONLY.
>
> Signed-off-by: Pascal Bach <[email protected] <mailto:[email protected]> <mailto:[email protected] <mailto:[email protected]>>>
> ---
> lib/bb/fetch2/git.py | 9 ++-------
> 1 file changed, 2 insertions(+), 7 deletions(-)
>
> diff --git a/lib/bb/fetch2/git.py b/lib/bb/fetch2/git.py
> index 1bec60a..cac2a87 100644
> --- a/lib/bb/fetch2/git.py
> +++ b/lib/bb/fetch2/git.py
> @@ -227,13 +227,8 @@ class Git(FetchMethod):
> return False
>
> def try_premirror(self, ud, d):
> - # If we don't do this, updating an existing checkout with only premirrors
> - # is not possible
> - if d.getVar("BB_FETCH_PREMIRRORONLY", True) is not None:
> - return True
> - if os.path.exists(ud.clonedir):
> - return False
> - return True
> + # Always try premirror if an update is required
> + return self.need_update(ud, d)
>
>

Quoted 6 lines

> Will this result in fetching a mirror tarball even if you already have a clone in ud.clonedir? The previous logic always returned False if the clonedir existed.. The tarball should only be fetched if the local ud.clonedir is out of date, this means the revision that is requested via SRCREV is not in the local repository. In the case the revision is present the tarball should not be fetched again, at least that was the intention and my local tests didn't indicate otherwise.

Yes, but it’s better to run ‘git fetch’ in an out of date clone than to re-download a 1gb mirror tarball which may well be out of date too.

Agreed, but this doesn't work in the case where the machine doesn't have access to the upstream git repository. For example in the case where BB_ALLOWED_NETWORKS = "*.my.company". The fetcher would still got to to github.com which is not allowed, in that case it should fall back to fetch the tarball from "mirror.my.company".

I'm open for suggestions how to make this more efficient.

Pascal

#5 lore raw
Quoted 9 lines
Quoted 6 lines

The tarball should only be fetched if the local ud.clonedir is out of date, this means the revision that is requested via SRCREV is not in the local repository. In the case the revision is present the tarball should not be fetched again, at least that was the intention and my local tests didn't indicate otherwise.

Yes, but it’s better to run ‘git fetch’ in an out of date clone than to re-download a 1gb mirror tarball which may well be out of date too.

Agreed, but this doesn't work in the case where the machine doesn't have access to the upstream git repository. For example in the case where BB_ALLOWED_NETWORKS = "*.my.company". The fetcher would still got to to github.com which is not allowed, in that case it should fall back to fetch the tarball from "mirror.my.company".

I'm open for suggestions how to make this more efficient.

Does anyone have a suggestion how this should behave in the ideal case? In my opinion if there is an internal mirror defined it should always have precedence even if it might be less efficient.

Pascal

#6 lore raw
Quoted 19 lines · Pascal Bach
Quoted 19 lines
Quoted 10 lines

    The tarball should only be fetched if the local ud.clonedir is out of date, this means the revision that is requested via SRCREV is not in the local repository.
    In the case the revision is present the tarball should not be fetched again, at least that was the intention and my local tests didn't indicate otherwise.

Quoted 3 lines

Yes, but it’s better to run ‘git fetch’ in an out of date clone than to re-download a 1gb mirror tarball which may well be out of date too.

Agreed, but this doesn't work in the case where the machine doesn't have access to the upstream git repository. For example in the case where BB_ALLOWED_NETWORKS = "*.my.company". The fetcher would still got to to github.com which is not allowed, in that case it should fall back to fetch the tarball from "mirror.my.company".

Quoted 4 lines
Quoted 1 line

I'm open for suggestions how to make this more efficient.

Does anyone have a suggestion how this should behave in the ideal case? In my opinion if there is an internal mirror defined it should always have precedence even if it might be less efficient.

"less efficient" in this case translates a few seconds of git fetch operation on something like linux-yocto into a hundreds of megabytes download.

Much as you might not like it, I really don't think we can change the code as your patch does as it would badly affect standard usage for many users.

We need to find an alternative which allows your use case to work but I'm not sure what that is. Much as I hate it, we may just have to have a setting which you can set which changes the behaviour. If we do that, I will want to see test cases added for it though as the fetcher code is a mass of different configurations and its very very difficult to maintain as it is without yet more different code paths :(.

Cheers,

Richard

#7 lore raw
Quoted 42 lines · Richard Purdie
Quoted 28 lines · Pascal Bach
Quoted 28 lines
Quoted 15 lines

    The tarball should only be fetched if the local ud.clonedir is out of date, this means the revision that is requested via SRCREV is not in the local repository.
    In the case the revision is present the tarball should not be
fetched again, at least that was the intention and my local tests
didn't indicate otherwise.

Quoted 4 lines

Yes, but it’s better to run ‘git fetch’ in an out of date clone than to re-download a 1gb mirror tarball which may well be out of
date too.

Agreed, but this doesn't work in the case where the machine doesn't
have access to the upstream git repository. For example in the case
where BB_ALLOWED_NETWORKS = "*.my.company". The fetcher would still
got to to github.com which is not allowed, in that case it should fall back to fetch the tarball from "mirror.my.company".

Quoted 5 lines
Quoted 1 line

I'm open for suggestions how to make this more efficient.

Does anyone have a suggestion how this should behave in the ideal case? In my opinion if there is an internal mirror defined it should
always have precedence even if it might be less efficient.

"less efficient" in this case translates a few seconds of git fetch operation on something like linux-yocto into a hundreds of megabytes download.

Much as you might not like it, I really don't think we can change the code as your patch does as it would badly affect standard usage for many users.

Quoted 8 lines

We need to find an alternative which allows your use case to work but I'm not sure what that is. Much as I hate it, we may just have to have
a setting which you can set which changes the behaviour. If we do that,
I will want to see test cases added for it though as the fetcher code is a mass of different configurations and its very very difficult to maintain as it is without yet more different code paths :(.

FWIW there is an open bug which I believe is related to this:

https://bugzilla.yoctoproject.org/show_bug.cgi?id=9061

It might be worth making the code aware of git aware premirror sources compared to other things like mirror tarballs as a start at fixing this.

Cheers,

Richard