git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jonathon Mah <me@jonathonmah.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Charles Bailey <charles@hashpling.org>,
	David Aguilar <davvid@gmail.com>
Subject: Re: [PATCH] mergetool: Teach about submodules
Date: Wed, 13 Apr 2011 03:00:15 -0700	[thread overview]
Message-ID: <C411FA8C-8E26-4DB8-BC2A-B95CDBB2CF38@jonathonmah.com> (raw)
In-Reply-To: <7v62qkwomk.fsf@alter.siamese.dyndns.org>

Hi Junio,

On 2011-04-11, at 12:53, Junio C Hamano wrote:

>> +resolve_submodule_merge () {
>> +    while true; do
>> +	printf "Use (l)ocal or (r)emote, or (a)bort? "
>> +	read ans
>> +	case "$ans" in
>> +	    [lL]*)
>> +		local_mode=$(git ls-files -u -- "$MERGED" | awk '{if ($3==2) print $1;}')
>> +		if is_submodule "$local_mode"; then
>> +		    stage_submodule "$MERGED" $(git ls-files -u -- "$MERGED" | awk '{if ($3==2) print $2;}')
> 
> If the version we had checked out and merging into has a submodule at the
> path, use that.  This part of the logic seem sensible.
> 
> Don't you already have local_mode from the caller here?  For that matter,
> don't you also have access to local_sha1 the caller already has computed?

Thanks for the feedback. I'm not particularly experienced with shell scripts, so I don't usually think of the lack of variable scope.

>> +		else
>> +		    git checkout-index -f --stage=2 -- "$MERGED"
>> +		    git add -- "$MERGED"
> 
> If what we had is not a submodule, then do a checkout-index.  Here you
> assume that we _must_ have a stage #2 entry, but is that always the case?

Indeed, it may not have. A v2 patch is following that handles the submodule path without a stage 2 (either because the submodule was deleted, or turned into a regular directory).

>> +stage_submodule () {
>> +    path="$1"
>> +    submodule_sha1="$2"
>> +
>> +    submodule_basename=$(basename "$path")
>> +    tree_with_module=$(echo "160000 commit $submodule_sha1	\"$submodule_basename\"" | git mktree --missing 2>/dev/null)
>> +    if test -z "$tree_with_module" ; then
>> +	echo "$path: unable to stage commit $sha1"
>> +	return 1
>> +    fi
>> +    git checkout $tree_with_module -- "$path"
> 
> Are you looking for "git update-index --cacheinfo 160000 $sha1 $name"

Yes, this is the command I was intending. I needed it a while back when I was converting a monolithic repo into a super/submodule configuration, but couldn't find a better way than the kludge above. I had hoped someone would show me the clean way to do it!



Jonathon Mah
me@JonathonMah.com

  reply	other threads:[~2011-04-13 10:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-09  3:59 [PATCH] mergetool: Teach about submodules Jonathon Mah
2011-04-09 12:03 ` David Aguilar
2011-04-10 10:15   ` Jonathon Mah
2011-04-10 10:18     ` [PATCH] mergetool: Added tests for submodule Jonathon Mah
2011-04-11 19:53 ` [PATCH] mergetool: Teach about submodules Junio C Hamano
2011-04-13 10:00   ` Jonathon Mah [this message]
2011-04-13 10:00   ` [PATCH v2] " Jonathon Mah

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=C411FA8C-8E26-4DB8-BC2A-B95CDBB2CF38@jonathonmah.com \
    --to=me@jonathonmah.com \
    --cc=charles@hashpling.org \
    --cc=davvid@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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).