[Buildroot] [v3 13/13] download: git: introduce cache feature

Yann E. MORIN yann.morin.1998 at free.fr
Sun Apr 1 18:13:49 UTC 2018


Arnout, All,

On 2018-04-01 16:58 +0200, Arnout Vandecappelle spake thusly:
> On 01-04-18 14:57, Yann E. MORIN wrote:
> > On 2018-03-31 16:24 +0200, Maxime Hadjinlian spake thusly:
[--SNIP--]
> >> +# If the cache directory already exists, don't try to clone.
> >> +if [ ! -d "${git_cache}" ]; then
> >> +    # Try a shallow clone, since it is faster than a full clone - but that
> >> +    # only works if the versionis a ref (tag or branch). Before trying to do a
> >> +    # shallow clone we check if ${cset} is in the list provided by git
> >> +    # ls-remote. If not we fall back on a full clone.
> >> +    #
> >> +    # Messages for the type of clone used are provided to ease debugging in
> >> +    # case of problems
> >> +    git_done=0
> >> +    if [ -n "$(_git ls-remote "'${uri}'" "'${cset}'" 2>&1)" ]; then
> >> +        printf "Doing shallow clone\n"
> >> +        if _git clone ${verbose} "${@}" --depth 1 -b "'${cset}'" "'${uri}'" "'${git_cache}'"; then
> >> +            git_done=1
> >> +        else
> >> +            printf "Shallow clone failed, falling back to doing a full clone\n"
> >> +        fi
> >> +    fi
> >> +    if [ ${git_done} -eq 0 ]; then
> >> +        printf "Doing full clone\n"
> >> +        _git clone ${verbose} "${@}" "'${uri}'" "'${git_cache}'"
> 
>  Can't we get rid of all the code above, and instead initialize an empty repository:
> 
> _git init "'${git_cache}'"
> cd "'${git_cache}'"
> _git remote set-url origin "'${uri}'"
> 
>  then do a fetch, and make it support shallow as well:
> 
> if [ -n "$(_git ls-remote origin "'${cset}'" 2>&1)" ]; then
>   if _git fetch "${@}" --depth 1 origin "'${cset}'";
>     git_done=1
>   fi
> fi
> if [ ${git_done} -eq 0 ]; then
>  _git fetch origin -t
> fi
> 
>  Would this work?

As seen IRL, this would work with "extra tweaks left as an exercise to
the reader". ;-)

Regards,
Yann E. MORIN.

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'


More information about the buildroot mailing list