Open Suarhae opened 4 years ago
versmisse/libgit2@8ee19a2
to test the solution and it works fine with git_tree_entry_byname. But it is not very clean (i change a private member (_cmp)) and incomplete (we must find a solution for all bsearch2 in the code
I found the problem: git_tree.entries uses 2 different algos to sort the entries:
entry_search_cmp and entry_sort_cmp entry_search_cmp makes an alphabetic sort, but entry_sort_cmp is more sophisticated (directories and files are not sorted the same way).
So i see 3 solutions: 1- We need to sort the list alphabetically before make the search (problem: git_vector_bsearch2 makes a sort) 2- We split entry_search_cmp into 2 functions: entry_search_file_cmp and entry_search_dir_cmp, we use gitfo_cmp_path and we search for a file and after for a directory. 3- Maybe we can always (everywhere) use an alphabetic sort??? 4- An other better solution, ...
I made this patch:
https://github.com/versmisse/libgit2/commit/8ee19a25ab4b54ff583bb46093610db0f53d2ab5
to test the solution and it works fine with git_tree_entry_byname. But it is not very clean (i change a private member (_cmp)) and incomplete (we must find a solution for all bsearch2 in the code).
Originally posted by @versmisse in https://github.com/libgit2/libgit2/issues/127#issuecomment-1038775