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

Re: [PATCH 2/2] git submodule: Fix adding of submodules at paths with ./

From
Michael J Gruber <git@drmicha.warpmail.net>
Date
Feb 25, 2009, 12:35 UTC
Message-ID
<49A53B15.4060608@drmicha.warpmail.net>
In-Reply-To
<49A529AB.8010700@viscovery.net>
Johannes Sixt venit, vidit, dixit 25.02.2009 12:21:
Show 9 quoted lines
> Michael J Gruber schrieb:
>> +	# strip superfluous ./ from path
>> +	path=$(echo "$path" | sed -e 's|^\(\./\)*||' -e's|/\./|/|g')
> 
> At a minimum:
> 
> 	path=$(echo "$path" | sed -e 's|^/\(\./\)*|/|g' -e's|^\./||')
> 
> Otherwise you would turn "foo./bar" into "foobar", right?
Wrong.

My regexp: echo "foo./bar" | sed -e 's|^\(\./\)*||' -e's|/\./|/|g' foo./bar

echo "foo/./bar" | sed -e 's|^\(\./\)*||' -e's|/\./|/|g' foo/bar

Your regexp: echo "foo./bar" | sed -e 's|^/\(\./\)*|/|g' -e's|^\./||' foo./bar

echo "foo/./bar" | sed -e 's|^/\(\./\)*|/|g' -e's|^\./||' foo/./bar

Testing your claim isn't that hard to do before hand...
> But why only care about ./ but not ../ or /// or trailing / as well?

You really haven't even looked at the included context of the patch (which you stripped), have you? I mean, I'm open for suggestions and criticism, but please don't shoot blindly.

./ have been reported and are a common use case.
Trailing / are dealt with by the code (see context).

Now, the /// are in fact a valid concern[1], although probably not that common an isue. If we really want to cater for that (and more) we need to implement normalize_path_copy() (from path.c). There it says:

* Performs the following normalizations on src, storing the result in dst:
 * - Ensures that components are separated by '/' (Windows only)
 * - Squashes sequences of '/'.
 * - Removes "." components.
 * - Removes ".." components, and the components the precede them.
 * Returns failure (non-zero) if a ".." component appears as first path
 * component anytime during the normalization. Otherwise, returns
success (0).

OK, two more regexps for sed. Thanks, I don't need suggestions for the regexps ;)

I can add /// and .. testing and handling in a v2, but I'll definitely leave the Windoze paths to someone who can actually test on Win.

Michael

[1] git sm init uses git ls-files, which in turn,..., which calls normalize_path_copy. git sm add can't use git ls-files because it has to deal with an as yet unknown path.

Previous: Johannes SixtNext: Johannes Sixt
Message 6 of 35 in “Fwd: Git Submodule Misbehaviour With ./”
  1. Andrei ThorpFeb 24, 2009
  2. 0/2 Fix git submodule add for paths with ./Michael J Gruber, Feb 25, 2009
  3. 1/2 git submodule: Add test cases for git submodule addMichael J Gruber, Feb 25, 2009
  4. 2/2 git submodule: Fix adding of submodules at paths with ./Michael J Gruber, Feb 25, 2009
  5. Johannes SixtFeb 25, 2009
  6. Michael J GruberFeb 25, 2009
  7. Johannes SixtFeb 25, 2009
  8. 0/4 Fix git submodule add for funky pathsMichael J Gruber, Feb 25, 2009
  9. 1/4 git submodule: Add test cases for git submodule addMichael J Gruber, Feb 25, 2009
  10. 2/4 git submodule: Fix adding of submodules at paths with ./Michael J Gruber, Feb 25, 2009
  11. 3/4 git submodule: Add more tests for add with funky pathsMichael J Gruber, Feb 25, 2009
  12. 4/4 git submodule: Fix handling of // and /.. in paths for added submodulesMichael J Gruber, Feb 25, 2009
  13. Johannes SixtFeb 25, 2009
  14. Michael J GruberFeb 25, 2009
  15. Johannes SixtFeb 25, 2009
  16. Junio C HamanoFeb 25, 2009
  17. Michael J GruberFeb 26, 2009
  18. Junio C HamanoFeb 26, 2009
  19. 0/2 git submodule: normalize paths before addingMichael J Gruber, Mar 3, 2009
  20. 1/2 git submodule: Add test cases for git submodule addMichael J Gruber, Mar 3, 2009
  21. 2/2 git submodule: Fix adding of submodules at paths with ./, .. and //Michael J Gruber, Mar 3, 2009
  22. Johannes SixtMar 3, 2009
  23. Michael J GruberMar 3, 2009
  24. 0/2 git submodule: normalize paths before addingMichael J Gruber, Mar 3, 2009
  25. 1/2 git submodule: Add test cases for git submodule addMichael J Gruber, Mar 3, 2009
  26. 2/2 git submodule: Fix adding of submodules at paths with ./, .. and //Michael J Gruber, Mar 3, 2009
  27. Johannes SixtMar 3, 2009
  28. Michael J GruberMar 3, 2009
  29. Junio C HamanoMar 3, 2009
  30. Junio C HamanoMar 3, 2009
  31. Michael J GruberMar 3, 2009
  32. Johannes SchindelinMar 3, 2009
  33. Michael J GruberMar 3, 2009
  34. Junio C HamanoFeb 25, 2009
  35. Junio C HamanoFeb 25, 2009

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.