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

Re: [PATCH v5 4/5] setup: Add 'abspath_part_inside_repo' function

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 4, 2014, 18:09 UTC
Message-ID
<xmqqlhxqagwt.fsf@gitster.dls.corp.google.com>
In-Reply-To
<20140203231659.GC15607@mule>
Martin Erik Werner <martinerikwerner@gmail.com> writes:
> Will you add that test or should I place it in the series with you as
> author?
Either is fine.  Thanks.
Show 15 quoted lines
> On Mon, Feb 03, 2014 at 01:00:48PM -0800, Junio C Hamano wrote:
>> Martin Erik Werner <martinerikwerner@gmail.com> writes:
>> 
>> > The path being exactly equal to the work tree is handled separately,
>> > since then there is no directory separator between the work tree and
>> > in-repo part.
>> 
>> What is an "in-repo part"?  Whatever it is, I am not sure if I
>> follow that logic.  After the while (*path) loop checks each level,
>> you check the whole path---wouldn't that code handle that special
>> case already?
>
> Given "/dir1/repo/dir2/file" I've used 'in-repo' to refer to
> "dir2/file", sometimes interchangably with "part inside the work tree"
> which might be better terminology, and should replace it?

Yes, "inside the working tree" is much clearer than "inside repo", because the word "repository" often is used to mean only the stuff inside $GIT_DIR, i.e. what controls the working tree files.

Show 7 quoted lines
> I was trying to convey that if path is simply "/dir/repo", then the while
> loop method of replacing a '/' and checking from the beginning won't
> work for the last level, since it has no terminating '/' to replace, so
> hence it's a special case, mentioning the "part inside the work tree"
> is arguably confusing in that case, since there isn't really one, maybe
> it should be left out completely, since the "check each level"
> explanation covers it already?

I dunno about the explanation, but it still looks strange to have the special case to deal with "/dir/repo" before you enter the while loop, and then also have code immediately after the loop that seems to handle the same case. Isn't the latter one redundant?

Show 13 quoted lines
>> Because it is probably the normal case not to have any symbolic link
>> in the leading part (hence not having to dereference them), I think
>> checking "is work_tree[] a prefix of path[]" early is justified from
>> performance point of view, though.
>> 
>> >  /*
>> > + * No checking if the path is in fact an absolute path is done, and it must
>> > + * already be normalized.
>> 
>> This is not quite parsable to me.
> Hmm, what about
> 	The input parameter must contain an absolute path, and it must
> 	already be normalized.
OK.
Show 11 quoted lines
>> > +	const char* work_tree = get_git_work_tree();
>> > +	if (!work_tree)
>> > +		return -1;
>> > +	wtlen = strlen(work_tree);
>> > +	len = strlen(path);
>> 
>> I expect that this is called from a callsite that _knows_ how long
>> path[] is.  Shouldn't len be a parameter to this function instead?
>
> Currently, it actually doesn't, since 'normalize_path_copy_len' is
> called on it prior, which can mess with the string length.
OK, strlen() here is perfectly fine, then.
Show 9 quoted lines
>> Hmph....  How do our callers treat an empty path?  In other words,
>> should these three be equivalent?
>> 
>> 	cd /a && git ls-files /a
>> 	cd /a && git ls-files ""
>> 	cd /a && git ls-files .
>
> Here I have only gone by the assumption that previous code did the right
> thing,...

Good to know. And the answer to the above question I think is yes, these should be equivalent.

Thanks.
Previous: Martin Erik WernerNext: Martin Erik Werner
Message 34 of 56 in “git-mv with absolute path derefereces symlinks”
  1. Martin Erik WernerJan 15, 2014
  2. 0/2 in-tree symlink handling with absolute pathsMartin Erik Werner, Jan 26, 2014
  3. 1/2 t0060: Add test for manipulating symlinks via absolute pathsMartin Erik Werner, Jan 26, 2014
  4. 2/2 setup: Don't dereference in-tree symlinks for absolute pathsMartin Erik Werner, Jan 26, 2014
  5. Torsten BögershausenJan 26, 2014
  6. Martin Erik WernerJan 27, 2014
  7. 2/2 setup: Don't dereference in-tree symlinks for absolute pathsMartin Erik Werner, Jan 27, 2014
  8. Duy NguyenJan 27, 2014
  9. Junio C HamanoJan 27, 2014
  10. 0/4 setup: Don't dereference in-tree symlinks for absolute pathsMartin Erik Werner, Jan 31, 2014
  11. 0/4 Handling of in-tree symlinks for absolute pathsMartin Erik Werner, Feb 2, 2014
  12. 1/4 t0060: Add test for manipulating symlinks via absolute pathsMartin Erik Werner, Feb 2, 2014
  13. 2/4 t0060: Add test for prefix_path when path == work treeMartin Erik Werner, Feb 2, 2014
  14. 3/4 setup: Add 'abspath_part_inside_repo' functionMartin Erik Werner, Feb 2, 2014
  15. Duy NguyenFeb 2, 2014
  16. Duy NguyenFeb 2, 2014
  17. Martin Erik WernerFeb 2, 2014
  18. David KastrupFeb 2, 2014
  19. Torsten BögershausenFeb 2, 2014
  20. Martin Erik WernerFeb 2, 2014
  21. Torsten BögershausenFeb 2, 2014
  22. Duy NguyenFeb 2, 2014
  23. 4/4 setup: Don't dereference in-tree symlinks for absolute pathsMartin Erik Werner, Feb 2, 2014
  24. 0/5 Handling of in-tree symlinks for absolute pathsMartin Erik Werner, Feb 2, 2014
  25. 1/5 t0060: Add test for manipulating symlinks via absolute pathsMartin Erik Werner, Feb 2, 2014
  26. Junio C HamanoFeb 3, 2014
  27. Junio C HamanoFeb 3, 2014
  28. Martin Erik WernerFeb 3, 2014
  29. 2/5 t0060: Add test for prefix_path when path == work treeMartin Erik Werner, Feb 2, 2014
  30. 3/5 t0060: Add tests for prefix_path when path begins with work treeMartin Erik Werner, Feb 2, 2014
  31. 4/5 setup: Add 'abspath_part_inside_repo' functionMartin Erik Werner, Feb 2, 2014
  32. Junio C HamanoFeb 3, 2014
  33. Martin Erik WernerFeb 3, 2014
  34. Junio C HamanoFeb 4, 2014
  35. Martin Erik WernerFeb 4, 2014
  36. 5/5 setup: Don't dereference in-tree symlinks for absolute pathsMartin Erik Werner, Feb 2, 2014
  37. Duy NguyenFeb 3, 2014
  38. Martin Erik WernerFeb 3, 2014
  39. Junio C HamanoFeb 4, 2014
  40. 0/6 Handling of in-tree symlinks for absolute pathsMartin Erik Werner, Feb 4, 2014
  41. 1/6 t3004: Add test for ls-files on symlinks via absolute pathsMartin Erik Werner, Feb 4, 2014
  42. 2/6 t0060: Add test for prefix_path on symlinks via absolute pathsMartin Erik Werner, Feb 4, 2014
  43. 3/6 t0060: Add test for prefix_path when path == work treeMartin Erik Werner, Feb 4, 2014
  44. 4/6 t0060: Add tests for prefix_path when path begins with work treeMartin Erik Werner, Feb 4, 2014
  45. Torsten BögershausenFeb 4, 2014
  46. Junio C HamanoFeb 4, 2014
  47. 5/6 setup: Add 'abspath_part_inside_repo' functionMartin Erik Werner, Feb 4, 2014
  48. Junio C HamanoFeb 4, 2014
  49. 6/6 setup: Don't dereference in-tree symlinks for absolute pathsMartin Erik Werner, Feb 4, 2014
  50. 1/4 t0060: Add test for manipulating symlinks via absolute pathsMartin Erik Werner, Jan 31, 2014
  51. 2/4 t0060: Add test for prefix_path when path == work treeMartin Erik Werner, Jan 31, 2014
  52. 3/4 setup: Add 'abspath_part_inside_repo' functionMartin Erik Werner, Jan 31, 2014
  53. Torsten BögershausenJan 31, 2014
  54. Martin Erik WernerFeb 1, 2014
  55. Duy NguyenFeb 1, 2014
  56. 4/4 setup: Don't dereference in-tree symlinks for absolute pathsMartin Erik Werner, Jan 31, 2014

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.