libgit2 does not work the same way as vanilla git does for adding files to index#3285
libgit2 does not work the same way as vanilla git does for adding files to index#3285csware wants to merge 13 commits into
Conversation
libgit2-0001 to libgit2-0005 based on libgit2/libgit2#3285, however, w/o tests here. Signed-off-by: Sven Strickroth <email@cs-ware.de>
|
This is an open issue for a very long time? Any comments or don't you care for broken CRLF? |
There was a problem hiding this comment.
Why are we accessing git's private data? If we need the repository, we should store it like we do in every other case (including tests/generate_crlf.sh and use .gitted/ as the git-dir. Looking into this structure is very fragile.
There was a problem hiding this comment.
In my first attempt all the private data was hardcoded, then it was requested that a script should be used for generating the "known good test results". I'm accessing the private data so that I can be sure which objects (ids) were created on adding a file (after the CRLF handling).
If you have a better idea here, I'm open.
There was a problem hiding this comment.
But you don't want the private data, you want to see which objects were created. Ask git for it, don't take it out of .git/.
git ls-files -s | cut -d ' ' -f 2
will give you the object names of whatever is in the index. If you're sure there's only ever one, that will give you the answer already. If you want to clear the index, use
git read-tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904
where that's the empty tree. You can generate it yourself at the beginning of the script with
git hash-object -t tree --stdin </dev/null
if you'd rather not hard-code it.
|
In general, the commits are missing an explanation for why the change is necessary. They don't explain why the old version was wrong or why the new version of the code fixes it. They just claim that they fix something. This makes it much harder to go through the commits and make sense of the changes. It would also help if they mentioned which failing tests they are fixing. |
|
|
👍 auto-crlf affects us a lot over in GitKraken land as well. |
|
This PR is now updated to match with the changed CrLf filter logic of Git 2.9. |
|
I'm sorry that the tests are failing right now as this is dependant on PR #4098. When this is on top of PR #4098 all the tests succeed w/o errors: Rebased commit: bcf497d |
novalis
left a comment
There was a problem hiding this comment.
Also, github makes this unreviewable because of the 3,000 file limit. I do not think that having 5,492 files to test crlf manipulation is reasonable. Nobody could possibly review these files to see if they are correct. I understand that you are starting with 1,369 and that the initial situation is not your fault. But nonetheless, I think that the moment that we bust github's ability to display code is a good moment to sit back and reflect on whether the approach makes any sense.
These files are generated by machine. Why don't we let the machine generate them and not check them in?
| (ca->crlf_action == GIT_CRLF_GUESS || ca->crlf_action == GIT_CRLF_AUTO || ca->crlf_action == GIT_CRLF_TEXT) && ca->eol == GIT_EOL_LF || | ||
| (ca->auto_crlf == GIT_AUTO_CRLF_INPUT && (ca->crlf_action == GIT_CRLF_GUESS)) || | ||
| (ca->auto_crlf == GIT_AUTO_CRLF_INPUT && (ca->crlf_action == GIT_CRLF_AUTO || ca->crlf_action == GIT_CRLF_TEXT) && ca->eol == GIT_EOL_UNSET) || | ||
| (GIT_EOL_NATIVE != GIT_EOL_CRLF && ca->auto_crlf == GIT_AUTO_CRLF_FALSE && (ca->crlf_action == GIT_CRLF_AUTO || ca->crlf_action == GIT_CRLF_TEXT) && ca->eol == GIT_EOL_UNSET)) { |
There was a problem hiding this comment.
This seems overcomplicated to me. For one thing, you sometimes have the action test before the auto_crlf test and sometimes after. This means that you miss some commonalities like the duplicated ca->crlf_action == auto || ca->crlf_action == text. We could also make it easier to read by breaking out sa->action, sa->eol, and sa->auto_crlf into separate variables. And we could define a helper GIT_EOF_NATIVE_IS_LF = GIT_EOL_NATIVE != GIT_EOL_CRLF, just to make that bit a bit shorter and clearer. I made these changes and I was still unable to make heads or tails of it. So then I thought: what if we make a function?
static int is_crlf_reasonable(sa) {
switch (sa->crlf_action) {
case GIT_CRLF_INPUT:
return 1;
break;
case GIT_CRLF_GUESS:
return sa->eol == GIT_EOL_LF || sa->auto_crlf == GIT_AUTO_CRLF_INPUT;
case GIT_CRLF_AUTO: /* FALL-THROUGH */
case GIT_CRLF_TEXT:
switch (sa->eol) {
case GIT_EOL_LF:
return 1;
case GIT_EOL_UNSET:
return sa->auto_crlf == GIT_AUTO_CRLF_INPUT;
case GIT_EOL_UNSET:
return GIT_EOL_NATIVE_IS_LF && sa->auto_crlf == GIT_AUTO_CRLF_FALSE;
}
}
return 0;
}
I have not yet actually tested this to ensure that it is identical, but I think the overall approach is much easier to read. Plus it's clear from the function name that success means that the check passed. Perhaps we need a better function name -- I don't really understand what this code is doing, but I can tell that I would be unable to debug it.
There was a problem hiding this comment.
| cl_git_pass(git_index_clear(g_index)); | ||
|
|
||
| git_buf_joinpath(&expected_dirname, "crlf_data", "checkin_results"); | ||
| git_buf_joinpath(&expected_dirname, "crlf_data/checkin_results", systype); |
There was a problem hiding this comment.
If you're doing joinpath anyway, don't use a slash. add another joinpath.
| if (ca->crlf_action == GIT_CRLF_INPUT || | ||
| (ca->auto_crlf == GIT_AUTO_CRLF_INPUT && | ||
| (ca->crlf_action == GIT_CRLF_GUESS || ca->crlf_action == GIT_CRLF_AUTO || | ||
| (ca->crlf_action == GIT_CRLF_TEXT && ca->eol==GIT_EOL_UNSET)))) { |
There was a problem hiding this comment.
nit: missing spaces around the last ==.
But more importantly, this is another case of "sanity-checking" that doesn't make clear what exactly is being checked and which is an if statement with a thousand clauses. This one is somewhat less heinous than the other one, but it does seem to cover a lot of the same ground, so I wonder if you missed some cases here, or if we could extract the common logic between the two, or something.
|
Thanks, that refactor looks much cleaner. |
|
@novalis asked:
I agree that this is unfortunate, but we don't want to add dependencies to the build or test process. We would need a I don't see a path to success that doesn't involve us checking in the test resources. |
pks-t
left a comment
There was a problem hiding this comment.
I've just had a very quick go at this PR. Are you still interested in maintaining it? If not that's fine, it's our fault for not reviewing it sooner. In that case I'll adopt it and move it forward.
| git_oid oid; | ||
| git_error_state error = { 0 }; | ||
|
|
||
| basename = git_path_basename(actual_path->ptr); |
There was a problem hiding this comment.
This may fail due to OOM conditions, so we have to check its return value
| cmp_git = strcmp(basename, ".git"); | ||
| cmp_gitattributes = strcmp(basename, ".gitattributes"); | ||
|
|
||
| if (cmp_git == 0 || cmp_gitattributes == 0) { |
There was a problem hiding this comment.
Stylistic nit: as I can't see these values being used anywhere else, I'd just avoid the use of variables and simply inline the two strcmp calls
There was a problem hiding this comment.
I just copied the coe from checkout/cflf.c: compare_file, there are these two variables and also no OOM check
| cl_git_pass(git_buf_joinpath(&expected_path_oid, cd->dirname, basename)); | ||
| cl_git_pass(git_buf_joinpath(&expected_path_fail, cd->dirname, basename)); | ||
| git_buf_puts(&expected_path_oid, ".obj"); | ||
| git_buf_puts(&expected_path_fail, ".fail"); |
There was a problem hiding this comment.
These should be wrapped in cl_git_pass, as well
| git_buf_puts(&sandboxname, safecrlf); | ||
|
|
||
| git_buf_puts(&sandboxname, ",autocrlf_"); | ||
| git_buf_puts(&sandboxname, autocrlf); |
There was a problem hiding this comment.
All these buffer operations need to be checked via cl_git_pass
| cl_git_pass(git_index_clear(g_index)); | ||
|
|
||
| git_buf_joinpath(&expected_dirname, "crlf_data", "checkin_results"); | ||
| git_buf_joinpath(&expected_fixture, expected_dirname.ptr, sandboxname.ptr); |
|
@pks-t Updated. |
Include a shell script that will generate the expected data of OIDs and failures for calling git.git to capture its output as a test resource. Right now, there is no need to differentiate different systems as git behaves the same on all systems IIRC. Signed-off-by: Sven Strickroth <email@cs-ware.de>
A corpus of files containing the OIDs after adding files to index or errors based on SafeCRLF settings with Git for Windows (2.4.4.windows.1) to ensure that we produce identical data when adding to index using a CRLF filter. Signed-off-by: Sven Strickroth <email@cs-ware.de>
Given a variety of combinations of core.autocrlf, core.safecrlf settings and attributes settings, test that we add files to index the same way (regarding OIDs and fatal errors) as a known-good test resource created by git.git. Signed-off-by: Sven Strickroth <email@cs-ware.de>
…e as vanilla git does Reported-by: Yue Lin Ho <b8732003@student.nsysu.edu.tw> Signed-off-by: Sven Strickroth <email@cs-ware.de>
… file exists and matches Knowing the proper core.autocrlf value is need for deciding whether the CRLF filter needs to be executed... Signed-off-by: Sven Strickroth <email@cs-ware.de>
…es not fail as with vanilla git Signed-off-by: Sven Strickroth <email@cs-ware.de>
Signed-off-by: Sven Strickroth <email@cs-ware.de>
…ion with attributes Based on lots of manual testing (even with "malformed" files and binary) with vanilla git executable... Signed-off-by: Sven Strickroth <email@cs-ware.de>
Update with "git version 2.11.0.windows.3". Signed-off-by: Sven Strickroth <email@cs-ware.de>
Update with vanilla git version 2.11.0 on Debian. Signed-off-by: Sven Strickroth <email@cs-ware.de>
The logic differs on *nix and Windows now. Signed-off-by: Sven Strickroth <email@cs-ware.de>
Signed-off-by: Sven Strickroth <email@cs-ware.de>
Signed-off-by: Sven Strickroth <email@cs-ware.de>
|
@pks-t I addressed all points. Any chance to get a new review? |
|
I already had a look a few days ago and didn't find anything noteworthy. I didn't yet state that as I am still thinking about these 4000 new files, which honestly put me a bit off. But I still ain't got a better idea how to properly do this, at least nothing that's as comprehensive as what you propose. @ethomson, @carlosmn: I'd appreciate if you could have another look at this |
|
I’ve been looking at this as time allows. I have some changes to propose but in the meantime I appreciate all the hard work here. |
|
It took long, but finally fixed with issue #4904. |
This is based on issue #2798 and issue #3199.
The code of issue #2798 is rebased onto current master and uses a similar testing approach as issue #3199.
Hopefully there are better chances for getting this merged than issue #2798.
The files in "checkin_input_files" are directly based on the files used for issue #3199.
/cc @ethomson