git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 2/2] submodules: always use a relative path from gitdir to work tree

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 14, 2012, 20:34 UTC
Message-ID
<7vzkcl5f37.fsf@alter.siamese.dyndns.org>
In-Reply-To
<7v4nut6u4s.fsf@alter.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
Show 11 quoted lines
> Jens Lehmann <Jens.Lehmann@web.de> writes:
>
>> After adding a comment, using test instead of [], testing both $a and
>> $b and assigning each variable on it's own line I get the following
>> interdiff. Does that make more sense?
>
> My earlier request for comment was to say
>
> 	# $a is always longer than $b for such and such reasons
>
> to explain why testing $b without testing $a was sufficient.

Heh, after I follow the entire module_clone, $gitdir is defined in earlier parts of the function to be "$(rev-parse --git-dir)/modules/$path", so it is clear that it is longer than $path. Unless "cd $there && pwd" does not result in a funny situation (such as $something/modules is a symbolic link to another place that is much closer to the root of the filesystem), that is.

And in such a case, the prefix part of $a and $b would be different from the very beginning hopefully.

Show 25 quoted lines
> It is obvious (at least to me) that the loop continues as long as $a and
> $b begin with the same string before their first '/' and removes that
> common segment from both of them, so I do not think the new comment is
> absolutely necessary, but it would not hurt to have it, especially it is
> short enough and to the point.
>
> Thanks.
>
>> diff --git a/git-submodule.sh b/git-submodule.sh
>> index 3463d6d..ed76ce2 100755
>> --- a/git-submodule.sh
>> +++ b/git-submodule.sh
>> @@ -172,9 +172,11 @@ module_clone()
>>
>>         a=$(cd "$gitdir" && pwd)
>>         b=$(cd "$path" && pwd)
>> -       while [ "$b" ] && [ "${a%%/*}" = "${b%%/*}" ]
>> +       # Remove all common leading directories
>> +       while test -n "$a" && test -n "$b" && test "${a%%/*}" = "${b%%/*}"
>>         do
>> -               a=${a#*/} b=${b#*/};
>> +               a=${a#*/}
>> +               b=${b#*/}
>>         done
>>         rel=$(echo $a | sed -e 's|[^/]*|..|g')

Perhaps aseert that $a never becomes empty before this line (or set it explicitly to "." when $a is empty), as otherwise

>>         (clear_local_git_env; cd "$path" && git config core.worktree "$rel/$b")
this will refer to "/$b" from the root?
Previous: Junio C HamanoNext: Jens Lehmann
Message 12 of 21 in “submodules: Use relative paths to gitdir and work tree”
  1. 0/2 submodules: Use relative paths to gitdir and work treeJens Lehmann, Feb 8, 2012
  2. 1/2 submodules: always use a relative path to gitdirJens Lehmann, Feb 8, 2012
  3. 1/2 submodules: always use a relative path to gitdirJens Lehmann, Feb 9, 2012
  4. Junio C HamanoFeb 9, 2012
  5. Junio C HamanoFeb 9, 2012
  6. Jens LehmannFeb 9, 2012
  7. 2/2 submodules: always use a relative path from gitdir to work treeJens Lehmann, Feb 8, 2012
  8. 2/2 submodules: always use a relative path from gitdir to work treeJens Lehmann, Feb 9, 2012
  9. Junio C HamanoFeb 13, 2012
  10. Jens LehmannFeb 14, 2012
  11. Junio C HamanoFeb 14, 2012
  12. Junio C HamanoFeb 14, 2012
  13. Jens LehmannFeb 15, 2012
  14. Johannes SixtFeb 26, 2012
  15. Jens LehmannFeb 26, 2012
  16. Johannes SixtFeb 27, 2012
  17. Johannes SchindelinFeb 27, 2012
  18. Johannes SixtFeb 28, 2012
  19. Junio C HamanoFeb 28, 2012
  20. Jens LehmannFeb 28, 2012
  21. Jens LehmannFeb 28, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.