git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Stefan Beller <sbeller@google.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: "git@vger.kernel.org" <git@vger.kernel.org>,
	Jens Lehmann <Jens.Lehmann@web.de>,
	Dave Borowitz <dborowitz@google.com>,
	Jacob Keller <jacob.keller@gmail.com>
Subject: Re: [PATCH 2/2] submodule: Try harder to fetch needed sha1 by direct fetching sha1
Date: Mon, 22 Feb 2016 16:28:03 -0800	[thread overview]
Message-ID: <CAGZ79ka-iAHvopwp==fTiuL13sJ_KzqotCNoOgQLJzvpNGH2HA@mail.gmail.com> (raw)
In-Reply-To: <xmqqzius2t31.fsf@gitster.mtv.corp.google.com>

On Mon, Feb 22, 2016 at 4:01 PM, Junio C Hamano <gitster@pobox.com> wrote:
>
> Stefan Beller <sbeller@google.com> writes:
>
> > We may want to discuss the error message. It is the same as in the case
> > before (git-fetch <no args>), this is good for translation, but may be bad
> > for the user as we may want to give extra information.
> > ("We fetched for you and it worked, however the sha1 was not included,
> > so we fetched again the server broke it, so we error out.  You used to
> > see error message: ....")
> >
> > Although this may be too much information?
>
> Now the "go to that submodule directory and see if $sha1 is
> reachable from any of the ref" check is written twice exactly the
> same way, it deserves to become a small helper function, I think.
>
> Perhaps something along this line?

This looks very readable.

Feel free to drop both my patches and just introduce this patch as yours!

>
>  git-submodule.sh | 29 ++++++++++++++++++++++++++---
>  1 file changed, 26 insertions(+), 3 deletions(-)
>
> diff --git a/git-submodule.sh b/git-submodule.sh
> index 9bc5c5f..836348f 100755
> --- a/git-submodule.sh
> +++ b/git-submodule.sh
> @@ -591,6 +591,24 @@ cmd_deinit()
>         done
>  }
>
> +is_tip_reachable () (
> +       clear_local_git_env
> +       cd "$1" &&
> +       rev=$(git rev-list -n 1 "$2" --not --all 2>/dev/null) &&
> +       test -z "$rev"

While we're talking about this code anyway, I wondered if we can make it
more cryptic again (just kidding!) and shorten it a bit by using the

    is_tip_reachable () (
        clear_local_git_env
        test -z $(git -C $1 rev-list -n 1 "$2" --not --all 2>/dev/null)
    )

> +)
> +
> +fetch_in_submodule () (
> +       clear_local_git_env
> +       cd "$1" &&
> +       case "$2" in
> +       '')
> +               git fetch ;;
> +       *)
> +               git fetch $(get_default_remote) "$2" ;;
> +       esac
> +)
> +
>  #
>  # Update each submodule path to correct revision, using clone and checkout as needed
>  #
> @@ -745,9 +763,14 @@ Maybe you want to use 'update --init'?")"
>                         then
>                                 # Run fetch only if $sha1 isn't present or it
>                                 # is not reachable from a ref.
> -                               (clear_local_git_env; cd "$sm_path" &&
> -                                       ( (rev=$(git rev-list -n 1 $sha1 --not --all 2>/dev/null) &&
> -                                        test -z "$rev") || git-fetch)) ||
> +                               is_tip_reachable "$sm_path" "$sha1" ||
> +                               fetch_in_submodule "$sm_path" ||
> +                               die "$(eval_gettext "Unable to fetch in submodule path '\$displaypath'")"
> +
> +                               # Now we tried the usual fetch, but $sha1 may
> +                               # not be reachable from any of the refs
> +                               is_tip_reachable "$sm_path" "$sha1" ||
> +                               fetch_in_submodule "$sm_path" "$sha1" ||

For another split second I wondered about the return code of is_tip_reachable,
if the result is actually negated, but reading the chaining here, makes sense.

Thanks,
Stefan

>                                 die "$(eval_gettext "Unable to fetch in submodule path '\$displaypath'")"
>                         fi
>

  reply	other threads:[~2016-02-23  0:28 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-22 22:35 [PATCH 0/2] Submodule harden fetches (WAS: submodule: Fetch the direct sha1 first) Stefan Beller
2016-02-22 22:35 ` [PATCH 1/2] submodule: Include check for objects when fetching Stefan Beller
2016-02-22 22:54   ` Junio C Hamano
2016-02-22 23:06     ` Junio C Hamano
2016-02-22 23:18       ` Junio C Hamano
2016-02-22 22:35 ` [PATCH 2/2] submodule: Try harder to fetch needed sha1 by direct fetching sha1 Stefan Beller
2016-02-23  0:01   ` Junio C Hamano
2016-02-23  0:28     ` Stefan Beller [this message]
2016-02-23  6:38       ` Junio C Hamano
2016-02-24  3:32         ` [PATCH] " Stefan Beller

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to='CAGZ79ka-iAHvopwp==fTiuL13sJ_KzqotCNoOgQLJzvpNGH2HA@mail.gmail.com' \
    --to=sbeller@google.com \
    --cc=Jens.Lehmann@web.de \
    --cc=dborowitz@google.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jacob.keller@gmail.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).