]> git.ipfire.org Git - thirdparty/git.git/commit - Makefile
add chdir-notify API
authorJeff King <peff@peff.net>
Fri, 30 Mar 2018 18:35:04 +0000 (14:35 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 30 Mar 2018 19:49:57 +0000 (12:49 -0700)
commit2b5ed373656c225d2baea09da130531fe7275fa2
tree327717bda81b0494fa78107a3b995cbfb0338211
parentcb50761959c0c30aa9c44098db3a72db06570238
add chdir-notify API

If one part of the code does a permanent chdir(), then this
invalidates any relative paths that may be held by other
parts of the code. For example, setup_work_tree() moves us
to the top of the working tree, which may invalidate a
previously stored relative gitdir.

We've hacked around this case by teaching setup_work_tree()
to re-run set_git_dir() with an adjusted path, but this
stomps all over the idea of module boundaries.
setup_work_tree() shouldn't have to know all of the places
that need to be fed an adjusted path. And indeed, there's at
least one other place (the refs code) which needs adjusting.

Let's provide an API to let code that stores relative paths
"subscribe" to updates to the current working directory.
This means that callers of chdir() don't need to know about
all subscribers ahead of time; they can simply consult a
dynamically built list.

Note that our helper function to reparent relative paths
uses the simple remove_leading_path(). We could in theory
use the much smarter relative_path(), but that led to some
problems as described in 41894ae3a3 (Use simpler
relative_path when set_git_dir, 2013-10-14). Since we're
aiming to replace the setup_work_tree() code here, let's
follow its lead.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Makefile
chdir-notify.c [new file with mode: 0644]
chdir-notify.h [new file with mode: 0644]