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

Re: RFC: git cat-file --follow-symlinks?

From
Jeff King <peff@peff.net>
Date
Apr 30, 2015, 03:37 UTC
Message-ID
<20150430033725.GB12361@peff.net>
In-Reply-To
<1430358345.14907.62.camel@ubuntu>
On Wed, Apr 29, 2015 at 06:45:45PM -0700, David Turner wrote:
Show 19 quoted lines
> On Wed, 2015-04-29 at 21:16 -0400, Jeff King wrote:
> > On Wed, Apr 29, 2015 at 06:06:23PM -0700, David Turner wrote:
> >   3. Ditto for out-of-tree. Note that this would be the _raw_ symlink
> >      contents, not any kind of simplification (so if you asked for
> >      "foo/bar/baz" and it was "../../../../out", you would the full path
> >      with all those dots, not a simplified "../out", which I think is
> >      what you were trying to show in earlier examples).
> 
> Unfortunately, we need the simplified version, because we otherwise
> don't know what the ..s are relative to in the case of a link to a link:
> 
>   echo content >dest ;# actual blob
>   mkdir -p foo/bar
>   ln -s foo/bar/baz fleem             # in-tree link-to-link 
>   ln -s ../../../external foo/bar/baz # out-of-tree link
> 
> If echo HEAD^{resolve}:fleem were to return ../../../external (after
> following the first symlink to the second), we would have lost
> information.
Urgh, yeah, thanks for the counter-example.
Here are some possible alternatives:
  1. If we can't resolve fully, don't resolve anything. I.e., return the
     "fleem" object here, and the caller can recurse if they want. This is
     simple and correct, but not as helpful to somebody who wants to follow
     the out-of-tree link (they have to re-traverse the fleem->foo/bar/baz
     link themselves).
  2. Consider it can error if resolution fails. If you ask for
     "HEAD^{tree}^{commit}", that does not resolve to anything (because
     we can't peel the tree to a commit). Like (1), this is simple and
     correct, but probably not all that helpful. The caller has to
     start from scratch and resolve themselves, rather than getting an
     intermediate result.
  3. Return an object with the symlink relative to the original
     filename (so "../external" in this case). This is kind of weird,
     though, because we're not just returning a string from the name
     resolution. It's an actual object.  So we'd be generating a fake
     object that doesn't actually exist in the object db and
     returning that. Feeding that sha1 to another program would fail.
  4. Return the last object we could resolve, as I described. So
     foo/bar/baz (with "../../../external" as its content) in this case.
     When you resolve a name, you can ask for the context we discovered
     along the way by traversing the tree. The mode is one example we've
     already discussed, but the path name is another. So something like:
       echo "HEAD^{resolve}:fleem" |
       git cat-file --batch="%(objectname) %(size) %(intreepath)"
     would show:
       1234abcd 17 foo/bar/baz
       ../../../external
     And then the caller knows that the path is not relative to the
     original "fleem", but rather to "foo/bar/baz".
     The problem is that although this context lookup is already part of
     get_sha1_with_context, that is not exposed through every interface.
     E.g., "git rev-parse HEAD^{resolve}:fleem" will give you an object,
     but you have no way of knowing the context.

I can't say that I'm excited about any of them. Perhaps you or somebody else can think of a more clever solution.

Note that the complication with (3) does come from my trying to push this down into the name-resolution code.

-Peff
Previous: David TurnerNext: Junio C Hamano
Message 17 of 43 in “RFC: git cat-file --follow-symlinks?”
  1. David TurnerApr 29, 2015
  2. Jonathan NiederApr 29, 2015
  3. David TurnerApr 29, 2015
  4. Junio C HamanoApr 29, 2015
  5. David TurnerApr 29, 2015
  6. Jeff KingApr 29, 2015
  7. Jonathan NiederApr 29, 2015
  8. Jeff KingApr 29, 2015
  9. David TurnerApr 29, 2015
  10. Jeff KingApr 29, 2015
  11. Jeff KingApr 30, 2015
  12. David TurnerApr 30, 2015
  13. Jeff KingApr 30, 2015
  14. Junio C HamanoApr 30, 2015
  15. Jeff KingApr 30, 2015
  16. David TurnerApr 30, 2015
  17. Jeff KingApr 30, 2015
  18. Junio C HamanoApr 30, 2015
  19. Michael HaggertyApr 30, 2015
  20. David TurnerApr 30, 2015
  21. Junio C HamanoApr 30, 2015
  22. David TurnerApr 30, 2015
  23. Jeff KingApr 30, 2015
  24. David TurnerApr 30, 2015
  25. Jeff KingApr 30, 2015
  26. David TurnerApr 30, 2015
  27. Jeff KingApr 30, 2015
  28. David TurnerApr 30, 2015
  29. Andreas SchwabApr 30, 2015
  30. Jeff KingApr 30, 2015
  31. Junio C HamanoApr 30, 2015
  32. David TurnerApr 30, 2015
  33. Junio C HamanoApr 30, 2015
  34. Jeff KingApr 30, 2015
  35. Junio C HamanoApr 30, 2015
  36. David TurnerMay 1, 2015
  37. Jeff KingMay 1, 2015
  38. David TurnerMay 1, 2015
  39. Jeff KingMay 1, 2015
  40. David TurnerMay 1, 2015
  41. Junio C HamanoApr 29, 2015
  42. David TurnerApr 29, 2015
  43. Michael HaggertyApr 30, 2015

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.