pathspec: remove check_path_for_gitlink
PATCH 1/1 pathspec: remove check_path_for_gitlink
check_path_for_gitlink was introduced in 9d67b61f739a (2013-01-06, add.c: extract check_path_for_gitlink() from treat_gitlinks() for reuse) but the implementation was removed in 5a76aff1a6 (2013-07-14, add:
convert to use parse_pathspec).
Remove the declaration from the header as well.
--- pathspec.h | 1 - 1 file changed, 1 deletion(-)
pathspec.h +0 -1
@@ -96,7 +96,6 @@ static inline int ps_strcmp(const struct pathspec_item *item,extern char *find_pathspecs_matching_against_index (const struct pathspec *pathspec);extern void add_pathspec_matches_against_index (const struct pathspec *pathspec,char *seen); -extern const char *check_path_for_gitlink (const char *path);extern void die_if_path_beyond_symlink (const char *path,const char *prefix);#endif /* PATHSPEC_H */
Signature · 1 line
2.8.0.1.g3af9c03
Quoted 17 lines · Stefan Beller
check_path_for_gitlinkwas introduced in9d67b61f739a(2013-01-06,add.c: extractcheck_path_for_gitlink()fromtreat_gitlinks()for reuse) but the implementation was removed in5a76aff1a6(2013-07-14, add:
convert to useparse_pathspec).Remove the declaration from the header as well.
Signed-off-by Stefan Beller <[email protected]>--- pathspec.h | 1 - 1 file changed, 1 deletion(-)pathspec.h +0
-0
pathspec.h static inline int ps_strcmp(const struct pathspec_item *item, · line 101
Quoted 7 lines
pathspec.h +0
-1@@ -96,7 +96,6 @@ static inline int ps_strcmp(const struct pathspec_item *item,extern char *find_pathspecs_matching_against_index (const struct pathspec *pathspec);extern void add_pathspec_matches_against_index (const struct pathspec *pathspec,char *seen); -extern const char *check_path_for_gitlink (const char *path);extern void die_if_path_beyond_symlink (const char *path,const char *prefix);#endif /* PATHSPEC_H */
Interesting.
I wonder if the patches mentioned have something to do with the "git add deep/in/the/tree" that fails to notice deep/in/ is an unrelated repository in some way?
Quoted 25 lines · Junio C Hamano
Quoted 23 lines · Stefan Beller
check_path_for_gitlinkwas introduced in9d67b61f739a(2013-01-06,add.c: extractcheck_path_for_gitlink()fromtreat_gitlinks()for reuse) but the implementation was removed in5a76aff1a6(2013-07-14, add:
convert to useparse_pathspec).Remove the declaration from the header as well.
Signed-off-by Stefan Beller <[email protected]>--- pathspec.h | 1 - 1 file changed, 1 deletion(-)pathspec.h +0
-1@@ -96,7 +96,6 @@ static inline int ps_strcmp(const struct pathspec_item *item,extern char *find_pathspecs_matching_against_index (const struct pathspec *pathspec);extern void add_pathspec_matches_against_index (const struct pathspec *pathspec,char *seen); -extern const char *check_path_for_gitlink (const char *path);extern void die_if_path_beyond_symlink (const char *path,const char *prefix);
Quoted 7 lines
pathspec.h static inline int ps_strcmp(const struct pathspec_item *item, · line 101
Quoted 1 line
pathspec.h +0
-0#endif /* PATHSPEC_H */ Interesting.
I wonder if the patches mentioned have something to do with the "git add deep/in/the/tree" that fails to notice deep/in/ is an unrelated repository in some way?
Which is considered a feature now. Maybe we should add tests for that?
http://debuggable.com/posts/git-fake-submodules:4b563ee4-f3cc-4061-967e-0e48cbdd56cb
Quoted 7 lines · Stefan Beller
Quoted 3 lines
I wonder if the patches mentioned have something to do with the "git add deep/in/the/tree" that fails to notice deep/in/ is an unrelated repository in some way?
Which is considered a feature now. Maybe we should add tests for that?
http://debuggable.com/posts/git-fake-submodules:4b563ee4-f3cc-4061-967e-0e48cbdd56cb
That is a bug, plain and simple. Duy any ideas where we went wrong?
I think we already have code to avoid adding beyond symlinks. "git add deep/in/the/tree" should refuse if deep/in is a symbolic link (and happens to point at a directory that has the/tree in it). We used not to catch that long time ago, but I think we fixed it.
The logic and the places to do the checks for "no, that thing may be a directory but is an unrelated repository" should be the same.
Quoted 11 lines · Junio C Hamano
Quoted 7 lines · Stefan Beller
Quoted 3 lines
I wonder if the patches mentioned have something to do with the "git add deep/in/the/tree" that fails to notice deep/in/ is an unrelated repository in some way?
Which is considered a feature now. Maybe we should add tests for that?
http://debuggable.com/posts/git-fake-submodules:4b563ee4-f3cc-4061-967e-0e48cbdd56cb
That is a bug, plain and simple. Duy any ideas where we went wrong?
That was my first reaction as well. However after a while of thought I actually like that bug. Consider the possibilities how gitk/git-gui or other subsystems can be developed. When accepting a patch for that you can either apply the patch in the outer or inner repository, depending on what the sender used.
I am not so sure if it is a bug plain and simple, but devolved into a "feature" now.
Quoted 8 lines
I think we already have code to avoid adding beyond symlinks. "git add deep/in/the/tree" should refuse if deep/in is a symbolic link (and happens to point at a directory that has the/tree in it). We used not to catch that long time ago, but I think we fixed it.
The logic and the places to do the checks for "no, that thing may be a directory but is an unrelated repository" should be the same.
Quoted 7 lines · Stefan Beller
That was my first reaction as well. However after a while of thought I actually like that bug. Consider the possibilities how gitk/git-gui or other subsystems can be developed. When accepting a patch for that you can either apply the patch in the outer or inner repository, depending on what the sender used.
I am not so sure if it is a bug plain and simple, but devolved into a "feature" now.
I'd freely admit that I have not considered its possible upsides at all. When deep/in/ is an unrelated repository, and running either
git add deep/in/the
git add deep/in/the/tree
would add deep/in/the/tree/is-a-leaf.txt to my index, but if I did
git add deep/in
I'd lose that and suddenly everything there turns into a submodule.
And that is enough for me to declare that it is not worth my time to consider possible upside of that hole. Can you tell offhand what would happen if you do "git add deep" (before adding deep/in as a submodule) without experimenting?
Quoted 7 lines · Junio C Hamano
Quoted 5 lines · Stefan Beller
That was my first reaction as well. However after a while of thought I actually like that bug. Consider the possibilities how gitk/git-gui or other subsystems can be developed. When accepting a patch for that you can either apply the patch in the outer or inner repository, depending on what the sender used.
Quoted 8 lines
Quoted 2 lines
I am not so sure if it is a bug plain and simple, but devolved into a "feature" now.
I'd freely admit that I have not considered its possible upsides at all. When deep/in/ is an unrelated repository, and running either
git add deep/in/the
git add deep/in/the/tree
I think that doesn't work (I did not test), but the crucial part is to add a trailing '/'. E.g. git add deep/in/the/ adds the 'the/**' tree of the nested
repository.
Quoted 6 lines
would add
deep/in/the/tree/is-a-leaf.txtto my index, but if I didgit add deep/in
I'd lose that and suddenly everything there turns into a submodule.
Yes.
git add deep/in # adds a submodule
however:
git add deep/in/ # adds all files of the sub-"repo" as indpendent files git commit -a -m "new files"
git -C deep/in reset --hard HEAD^
git diff
# shows a difference in deep/in/the/tree/is-a-leaf.txt
Quoted 6 lines
And that is enough for me to declare that it is not worth my time to consider possible upside of that hole. Can you tell offhand what would happen if you do "git add deep" (before adding deep/in as a submodule) without experimenting?
Not really. My expectation is to add everything *but* the deep/in/ repo as this is not exercising the bug/feature.
Quoted 10 lines · Junio C Hamano
When deep/in/ is an unrelated repository, and running either
git add deep/in/the
git add deep/in/the/treewould add
deep/in/the/tree/is-a-leaf.txtto my index, but if I didgit add deep/in
I'd lose that and suddenly everything there turns into a submodule.
Also, I recall that you floated an idea to declare that
git add deep/in/the/tree/is-a-leaf.txt
must always behave as if this is done instead:
git -C deep/in/the/tree/ add is-a-leaf.txt
Even though I am not a huge fan of an operation that crosses module boundaries, I think that is a sensible semantics of a "cross module boundary operation" (the actual implementation should not be iterating over pathspecs and chdir(2)ing around for each and every one of them, though), if we need "cross module boundary operation" in order to support end users working on a project with one or more submodules at the same time.
But treating the bug under discussion as a "feature" will destroy that future.
Quoted 13 lines · Junio C Hamano
Quoted 10 lines · Junio C Hamano
When deep/in/ is an unrelated repository, and running either
git add deep/in/the
git add deep/in/the/treewould add
deep/in/the/tree/is-a-leaf.txtto my index, but if I didgit add deep/in
I'd lose that and suddenly everything there turns into a submodule.
Quoted 7 lines
Also, I recall that you floated an idea to declare that
git add
deep/in/the/tree/is-a-leaf.txtmust always behave as if this is done instead:
git -C deep/in/the/tree/ add is-a-leaf.txt
In a different thread, yeah. I am not sure about that any more.
Quoted 8 lines
Even though I am not a huge fan of an operation that crosses module boundaries, I think that is a sensible semantics of a "cross module boundary operation" (the actual implementation should not be iterating over pathspecs and chdir(2)ing around for each and every one of them, though), if we need "cross module boundary operation" in order to support end users working on a project with one or more submodules at the same time.
I agree.
Quoted 3 lines
But treating the bug under discussion as a "feature" will destroy that future.
The bug under discussion was blogged about in 2010 and still persists. I'll try to find out if people actually use it.
If that bug was fixed, but I still wanted to enjoy the upsides of it, I could to that with pointing core.worktree into deep/in/tree. e.g. I have git.git and gitk-git as separate repositories, then I could still do a
GIT_DIR=gitk-git/.git git -C git.git/gitk-git git checkout
<sha1-of-gitk-repo>
This looks more complicated than this bug/feature though.
There are 2 fundamental cases though.
(1) The bug we're talking about (as explained in that blog), refers to 2 independent repositories, whose work trees are nested
(2) You seemed to bring in the notion that the nested repo is considered a submodule of the outer repo, i.e. they have a relationship.
I don't mind (1). It's a neat hack as these 2 repos are totally unrelated (except for the working tree in the file system being the same files). You could also achieve a similar handling by hardlinking gitk-git/gitk and git.git/gitk-git/gitk.
In (2), we have a gitlink, which by definition takes up the whole directory. So any file in that directory in the file system which represents the root of the submodule should belong to the submodule.
Quoted 6 lines · Stefan Beller
There are 2 fundamental cases though.
(1) The bug we're talking about (as explained in that blog), refers to 2 independent repositories, whose work trees are nested
(2) You seemed to bring in the notion that the nested repo is considered a submodule of the outer repo, i.e. they have a relationship.
Quoted 8 lines
I don't mind (1). It's a neat hack as these 2 repos are totally unrelated (except for the working tree in the file system being the same files). You could also achieve a similar handling by hardlinking gitk-git/gitk and git.git/gitk-git/gitk.
In (2), we have a gitlink, which by definition takes up the whole directory. So any file in that directory in the file system which represents the root of the submodule should belong to the submodule.
I certainly didn't mean to "bring in the notion" as if it is something entirely alien to the discussion. Before you "git add", it may be a "nested independent" repository, but that is merely a submodule that is untracked, yet to be added. Just like tracked files were once untracked before they got added, these are possible submodules that happened to be not tracked yet.
I do not see there is any difference between the two at all.
If deep/in is a repository yet to be added as a submodule,
$ git add deep/in/the/tree/is-a-leaf.txt
$ git add deep/inin the hypothetical "git add A is equivalent to git -C $(dirname A) add $(basename A)" world should behave the same regardless of the order of these two commands (otherwise the behaviour is way too confusing).
Quoted 5 lines · Junio C Hamano
Quoted 3 lines · Stefan Beller
Quoted 3 lines
I wonder if the patches mentioned have something to do with the "git add deep/in/the/tree" that fails to notice deep/in/ is an unrelated repository in some way?
The same functionality is added in 8745024 (parse_pathspec: support stripping/checking submodule paths - 2013-07-14) so if it didn't fail to notice that before 5a76aff1a6 and did after, it's a bug.
Quoted 6 lines
Quoted 4 lines
Which is considered a feature now. Maybe we should add tests for that?
http://debuggable.com/posts/git-fake-submodules:4b563ee4-f3cc-4061-967e-0e48cbdd56cb
That is a bug, plain and simple. Duy any ideas where we went wrong?
I vaguely recall this symptom. It has something to do with the index, the check we do requires a gitlink in the index, I think. So if the gitlink entry is not in the index, our protection line fails. I think doing all this at pathspec level is wrong. We should wait at least after read_directory() is done, by then we have a lot more info to decide.
Quoted 7 lines
I think we already have code to avoid adding beyond symlinks. "git add deep/in/the/tree" should refuse if deep/in is a symbolic link (and happens to point at a directory that has the/tree in it). We used not to catch that long time ago, but I think we fixed it.
The logic and the places to do the checks for "no, that thing may be a directory but is an unrelated repository" should be the same.
Signature · 1 line
Duy
Quoted 10 lines · Duy Nguyen
Quoted 5 lines · Junio C Hamano
Quoted 3 lines · Stefan Beller
Quoted 3 lines
I wonder if the patches mentioned have something to do with the "git add deep/in/the/tree" that fails to notice deep/in/ is an unrelated repository in some way?
The same functionality is added in 8745024 (
parse_pathspec: support stripping/checking submodule paths - 2013-07-14) so if it didn't fail to notice that before5a76aff1a6and did after, it's a bug.
The bug seems to have existed before. However in the bug we are talking about the nested repo is not a submodule yet.
Quoted 20 lines
Quoted 7 lines
Quoted 5 lines
Which is considered a feature now. Maybe we should add tests for that?
http://debuggable.com/posts/git-fake-submodules:4b563ee4-f3cc-4061-967e-0e48cbdd56cb
That is a bug, plain and simple. Duy any ideas where we went wrong?
I vaguely recall this symptom. It has something to do with the index, the check we do requires a gitlink in the index, I think. So if the gitlink entry is not in the index, our protection line fails. I think doing all this at pathspec level is wrong. We should wait at least after
read_directory()is done, by then we have a lot more info to decide.Quoted 5 lines
I think we already have code to avoid adding beyond symlinks. "git add deep/in/the/tree" should refuse if deep/in is a symbolic link (and happens to point at a directory that has the/tree in it). We used not to catch that long time ago, but I think we fixed it.
Quoted 4 lines
Quoted 2 lines
The logic and the places to do the checks for "no, that thing may be a directory but is an unrelated repository" should be the same.
--
Duy
Here are some tests to have a clear picture of what is happening:
(diff against origin/master)
t/t7400-submodule-basic.sh +0 -0
@@ -37,6 +37,22 @@ test_expect_success 'setup - repository in init
subdirectory' '
git add a &&
git commit -m "submodule commit 1" &&
git tag -a -m "rev-1" rev-1
+ ) &&
+ mkdir init_slash1 &&
+ (
+ cd init_slash1 &&
+ git init &&
+ echo a >a &&
+ git add a &&
+ git commit -m "first commit"
+ ) &&
+ mkdir init_slash2 &&
+ (
+ cd init_slash2 &&
+ git init &&
+ echo a >a &&
+ git add a &&
+ git commit -m "first commit"
)'
@@ -44,7 +60,30 @@ test_expect_success 'setup - commit with gitlink' '
echo a >a &&
echo z >z &&
git add a init z &&
- git commit -m "super commit 1"
+ git commit -m "super commit 1" &&
+ git ls-tree HEAD |grep init >actual &&
+ grep "160000 commit" actual
+'
+
+test_expect_success 'setup - commit with gitlink/ in between' '
+ echo a >a &&
+ echo z >z &&
+ git add a init_slash1/ z &&
+ git commit -m "super commit 1" &&
+ git ls-tree HEAD |grep init_slash1 >actual &&
+ grep "160000 commit" actual
+'
+
+test_expect_failure 'setup - commit with gitlink/ only' '
+ git add init_slash2/ &&
+ git commit -m "super commit 1" &&
+ git ls-tree HEAD |grep init_slash2 >actual &&
+ grep "160000 commit" actual+'
+
+test_expect_success 'tear down slash tests' '
+ rm -rf init_slash* &&
+ git commit -a -m "removing init_slash*"
'
test_expect_success 'setup - hide init subdirectory' '
Quoted 8 lines · Stefan Beller
Quoted 7 lines · Duy Nguyen
Quoted 5 lines · Junio C Hamano
Quoted 3 lines · Stefan Beller
Quoted 3 lines
I wonder if the patches mentioned have something to do with the "git add deep/in/the/tree" that fails to notice deep/in/ is an unrelated repository in some way?
Quoted 6 lines
Quoted 3 lines
The same functionality is added in 8745024 (
parse_pathspec: support stripping/checking submodule paths - 2013-07-14) so if it didn't fail to notice that before5a76aff1a6and did after, it's a bug.The bug seems to have existed before. However in the bug we are talking about the nested repo is not a submodule yet.
That agrees with Duy's recollection below:
Quoted 3 lines
Quoted 3 lines
I vaguely recall this symptom. It has something to do with the index, the check we do requires a gitlink in the index, I think. So if the gitlink entry is not in the index, our protection line fails.
So are we all on the same page that this is a bug now?
Quoted 17 lines · Junio C Hamano
Quoted 8 lines · Stefan Beller
Quoted 7 lines · Duy Nguyen
Quoted 5 lines · Junio C Hamano
Quoted 3 lines · Stefan Beller
Quoted 3 lines
I wonder if the patches mentioned have something to do with the "git add deep/in/the/tree" that fails to notice deep/in/ is an unrelated repository in some way?
Quoted 6 lines
Quoted 3 lines
The same functionality is added in 8745024 (
parse_pathspec: support stripping/checking submodule paths - 2013-07-14) so if it didn't fail to notice that before5a76aff1a6and did after, it's a bug.The bug seems to have existed before. However in the bug we are talking about the nested repo is not a submodule yet.
Quoted 7 lines
That agrees with Duy's recollection below:
Quoted 3 lines
Quoted 3 lines
I vaguely recall this symptom. It has something to do with the index, the check we do requires a gitlink in the index, I think. So if the gitlink entry is not in the index, our protection line fails.
So are we all on the same page that this is a bug now?
It was a bug, but now people in the outside world consider it a feature. Search for "Git fake submodules" and you'll find a few users who use this technique successfully.
I do not think fixing this bug would do good. So maybe we just let it slip?
Quoted 24 lines · Stefan Beller
Quoted 23 lines · Junio C Hamano
Quoted 8 lines · Stefan Beller
Quoted 7 lines · Duy Nguyen
Quoted 5 lines · Junio C Hamano
Quoted 3 lines · Stefan Beller
Quoted 3 lines
I wonder if the patches mentioned have something to do with the "git add deep/in/the/tree" that fails to notice deep/in/ is an unrelated repository in some way?
Quoted 6 lines
Quoted 3 lines
The same functionality is added in 8745024 (
parse_pathspec: support stripping/checking submodule paths - 2013-07-14) so if it didn't fail to notice that before5a76aff1a6and did after, it's a bug.The bug seems to have existed before. However in the bug we are talking about the nested repo is not a submodule yet.
That agrees with Duy's recollection below:
Quoted 3 lines
Quoted 3 lines
I vaguely recall this symptom. It has something to do with the index, the check we do requires a gitlink in the index, I think. So if the gitlink entry is not in the index, our protection line fails.
Quoted 7 lines
Quoted 1 line
So are we all on the same page that this is a bug now?
It was a bug, but now people in the outside world consider it a feature. Search for "Git fake submodules" and you'll find a few users who use this technique successfully.
I do not think fixing this bug would do good. So maybe we just let it slip?
I think it's because people do have some use cases for multiple worktrees (typically from different repos) to share the same filesystem portion. We never actually support that. There are a bunch of questions on how these worktrees/repos should interact. Maybe someone will finally add support for that. But this is still a bug, even though nobody has time to fix it yet. So I agree with Junio calling this "undefined behavior", not "feature".
Signature · 1 line
Duy
Quoted 5 lines · Stefan Beller
It was a bug, but now people in the outside world consider it a feature. Search for "Git fake submodules" and you'll find a few users who use this technique successfully.
I do not think fixing this bug would do good. So maybe we just let it slip?
I am OK with leaving it unfixed, iow, we just say this:
If deep/in is a different repository, whether it is a submodule, "git add deep/in/the/tree/is-a-leaf.txt" will give an undefined result.
But that is totally different from accepting it as a feature. If we were to accept it as a feature (and we will not), then
I did "git add deep/in/the/tree/is-a-leaf.txt" and have kept the path tracked. Today I did "git add deep/*" and then the path disappeared from my project--I now only have deep/in as a submodule, which is not what I want.
would become a valid bug report. I do not want to see that happen.
I.e. I am *NOT* OK with polluting the codebase with a hack to respond to such a bug report, e.g. by adding a rule that says "if a file deep/in/the/tree/is-a-leaf.txt is tracked and deep/in is a repository, 'git add deep/in' must fail".
The stance "It is a bug, but we do not fix it right now. The behaviour is undefined" also leaves the door open for a future enhancement that allows 'git add deep/in/the/tree/is-a-leaf.txt' to be an equivalent to 'git -C deep/in/the/tree add is-a-leaf.txt'.