From: Junio C Hamano <gitster@pobox.com>
To: Chris Packham <judge.packham@gmail.com>
Cc: git@vger.kernel.org, jrnieder@gmail.com, gitster@pobox.com,
bebarino@gmail.com
Subject: Re: [PATCHv2 1/2] Add git alternate command
Date: Mon, 29 Mar 2010 00:32:29 -0700 [thread overview]
Message-ID: <7vr5n37fci.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: 1269497251-13103-2-git-send-email-judge.packham@gmail.com
Chris Packham <judge.packham@gmail.com> writes:
> +abspath()
> +{
> + cd "$1"
> + pwd
> + cd - > /dev/null
> +}
I do not think "cd -" is all that portable. As you will be always using this in
this form:
somevariable=$(abspath "$it")
you are in a subshell and won't affect the caller anyway. Why not drop
the "go back to where we came from"?
Also a shell built-in "pwd" tends to be fooled by $PWD especially since
you are running "cd" without -P.
> +#
> +# Runs through the alternates file calling the callback function $1
> +# with the name of the alternate as the first argument to the callback
> +# any additional arguments are passed to the callback function.
> +#
> +walk_alternates()
This is more like "for_each_alternates"; "walk" can be mistaken as if you
are recursively looking at alternates defined in alternate repositories
of the repository you start from.
> +{
> + alternates=$GIT_DIR/objects/info/alternates
> + callback=$1
> + shift
> +
> + if test -f "$alternates"
> + then
> + while read line
> + do
> + $callback "$line" "$@"
> + done< "$alternates"
done <"$alternates"
How well does this handle relative alternate object stores? Shouldn't it
be more like this?
while read altdir
do
case "$altdir" in
/*) ;; # full path
*) altdir="$GIT_DIR/objects/$altdir" ;;
esac &&
$callback "$altdir" "$@"
done <"$alternates"
> +# Walk function to display one alternate object store and, if the user
> +# has specified -r, recursively call show_alternates on the git
> +# repository that the object store belongs to.
> +#
> +show_alternates_walk()
> +{
> + say "Object store $1"
> + say " referenced via $GIT_DIR"
> +
> + new_git_dir=${line%%/objects}
Do you need double-% here, not a single one?
> +# Add a new alternate
> +add_alternate()
> +{
> + if test ! -d "$dir"; then
> + die "fatal: $dir is not a directory"
> + fi
> +
> + abs_dir=$(abspath "$dir")
> + walk_alternates check_current_alternate_walk "$abs_dir"
> +
> + # At this point we know that $dir is a directory that exists
> + # and that its not already being used as an alternate. We could
s/its/(it's|it is)/;
But I don't think it is true that you have verified that it is not used.
You are running abspath on the input from the end user, but you are using
existing entries in the alternates file that may not be absolute. They
can be relative to $GIT_DIR/objects/.
> + say " use 'git repack -adl' to remove duplicate objects"
Good.
> +# Deletes the name alternate from the alternates file.
> +# If there are no more alternates the alternates file will be removed
> +del_alternate()
> +{
> + if test ! $force = "true"; then
> + say "Not forced, use"
> + say " 'git repack -a' to fetch missing objects, then "
> + say " '$dashless -f -d $dir' to remove the alternate"
> + die
Hmm, I am afraid that this will end up training users to always say -f
without even thinking. Shouldn't this code be doing whatever necessary
steps to make sure this repository has all the necessary objects without
the named alternates and then removing the file? An easiest might be to
temporarily remove the entry and run fsck, perhaps?
next prev parent reply other threads:[~2010-03-29 7:32 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-22 17:26 Question about .git/objects/info/alternates Chris Packham
2010-03-23 2:42 ` Jonathan Nieder
2010-03-24 18:53 ` Chris Packham
2010-03-24 19:23 ` Jonathan Nieder
2010-03-24 19:58 ` Junio C Hamano
2010-03-24 20:35 ` Chris Packham
2010-03-25 6:07 ` Chris Packham
2010-03-25 6:07 ` [PATCHv2 1/2] Add git alternate command Chris Packham
2010-03-29 7:32 ` Junio C Hamano [this message]
2010-03-31 4:35 ` Chris Packham
2010-03-25 6:07 ` [PATCHv2 2/2] tests for " Chris Packham
2010-03-25 7:38 ` Johannes Sixt
2010-03-25 18:51 ` Chris Packham
2010-03-26 0:48 ` Miklos Vajna
2010-03-26 6:44 ` Johannes Sixt
2010-03-24 20:16 ` Question about .git/objects/info/alternates Stephen Boyd
2010-03-24 20:37 ` Chris Packham
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=7vr5n37fci.fsf@alter.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=bebarino@gmail.com \
--cc=git@vger.kernel.org \
--cc=jrnieder@gmail.com \
--cc=judge.packham@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.
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 NNTP newsgroup(s).