Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Yann E. MORIN <yann.morin.1998@free.fr>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH 2/6 v2] download/git: try to recover from utterly-broken repositories
Date: Sun, 22 Apr 2018 11:46:06 +0200	[thread overview]
Message-ID: <20180422094606.GH12688@scaer> (raw)
In-Reply-To: <8f347509db00c8c2108a5a9fef1b8862fcf3b8b0.1524388060.git.yann.morin.1998@free.fr>

All,

On 2018-04-22 11:07 +0200, Yann E. MORIN spake thusly:
> In some cases, the repository may be in a state we can't automatically
> recover from, especially since we must still support oldish git versions
> that do not provide the necessary commands or options thereof.
> 
> As a last-ditch recovery, delete the repository and recreate the cache
> from scratch.

As Thomas noticed on IRC, this commit would remove the local git cache
in case the user enters an invalid changeset (typo in sha1 or tag name,
or whatnot).

A missing commit should not be considered as a broken repository,
especially since re-cloning from scratch would not help solve the
issue.

I already have a local change that will avoid trashing a git cache in
that case (using git rev-parse). I'll wait for some more reviews before
submitting again...

Regards,
Yann E. MORIN.

> Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
> Cc: Maxime Hadjinlian <maxime.hadjinlian@gmail.com>
> Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
> Cc: Ricardo Martincoski <ricardo.martincoski@gmail.com>
> Cc: Arnout Vandecappelle <arnout@mind.be>
> ---
>  support/download/git | 27 +++++++++++++++++++++++++++
>  1 file changed, 27 insertions(+)
> 
> diff --git a/support/download/git b/support/download/git
> index 19a3e8ebee..ebd04bc7b3 100755
> --- a/support/download/git
> +++ b/support/download/git
> @@ -16,6 +16,30 @@ set -e
>  # Environment:
>  #   GIT      : the git command to call
>  
> +# Save out path and options in case we need to call ourselves again
> +myname="${0}"
> +declare -a OPTS=("${@}")
> +
> +# This function is called when an error occurs. Its job is to attempt a
> +# clone from scratch (only once!) in case the git tree is borked, or in
> +# case an unexpected and unsupported situation arises with submodules
> +# or uncomitted stuff (e.g. if the user manually mucked around in the
> +# git cache).
> +_on_error() {
> +    local ret=${?}
> +
> +    if ${BR_GIT_BACKEND_FIRST_FAULT:-false}; then
> +        printf "Double-fault in git-cache"
> +        exit ${ret}
> +    fi
> +    export BR_GIT_BACKEND_FIRST_FAULT=true
> +
> +    popd >/dev/null
> +    rm -rf "${git_cache}"
> +
> +    exec "${myname}" "${OPTS[@]}" || exit ${ret}
> +}
> +
>  verbose=
>  recurse=0
>  while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
> @@ -39,6 +63,9 @@ git_cache="${dl_dir}/git"
>  mkdir -p "${git_cache}"
>  pushd "${git_cache}" >/dev/null
>  
> +# Any error now should try to recover
> +trap _on_error ERR
> +
>  # Caller needs to single-quote its arguments to prevent them from
>  # being expanded a second time (in case there are spaces in them)
>  _git() {
> -- 
> 2.14.1
> 
> _______________________________________________
> buildroot mailing list
> buildroot at busybox.net
> http://lists.busybox.net/mailman/listinfo/buildroot

-- 
.-----------------.--------------------.------------------.--------------------.
|  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.  |
'------------------------------^-------^------------------^--------------------'

  reply	other threads:[~2018-04-22  9:46 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-22  9:07 [Buildroot] [PATCH 0/6 v2] support/download: make the git backend even more robust Yann E. MORIN
2018-04-22  9:07 ` [Buildroot] [PATCH 1/6 v2] download/git: run all git commands in the current directory Yann E. MORIN
2018-04-22  9:07 ` [Buildroot] [PATCH 2/6 v2] download/git: try to recover from utterly-broken repositories Yann E. MORIN
2018-04-22  9:46   ` Yann E. MORIN [this message]
2018-04-22  9:07 ` [Buildroot] [PATCH 3/6 v2] download/git: ensure we checkout to a clean state Yann E. MORIN
2018-04-22  9:07 ` [Buildroot] [PATCH 4/6 v2] download/git: ensure we can checkout repos with submodule conversions Yann E. MORIN
2018-04-22  9:07 ` [Buildroot] [PATCH 5/6 v2] download/git: always do full-clone Yann E. MORIN
2018-04-22  9:07 ` [Buildroot] [PATCH 6/6 v2] download/git: add warning not to use or git cache Yann E. MORIN

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180422094606.GH12688@scaer \
    --to=yann.morin.1998@free.fr \
    --cc=buildroot@busybox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox