8000 git_tree_entry_byname fails apparently because of wrong sort order (in some cases) · Issue #127 · libgit2/libgit2 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
git_tree_entry_byname fails apparently because of wrong sort order (in some cases) #127
Closed
@jdavid

Description

@jdavid

git_tree_entry_byname returns NULL when it should not in some specific cases. Apparently
this is because the sort order of the tree is wrong, for instance with libgit2, within the 'include' folder, the entries are ordered this way:

git2.h
git2

While it should be the inverse, first the shortest string. And then bsearch fails (in function git_vector_bsearch2).

Below a test program that reproduces the problem. It prints "git2.h not found" while it should print "git2.h found".

#include <git2.h>
#include <stdio.h>

#define REPO "/home/jdavid/sandboxes/libgit2/.git"
#define TREE "693753506198e2d7832475975f6dc5ada3a502f3"
#define NAME "git2.h"

void main()
{
    int err;
    git_repository *repo;
    git_oid tree_id;
    git_object *tree;
    const git_tree_entry *entry;

    err = git_repository_open(&repo, REPO);
    err = git_oid_mkstr(&tree_id, TREE);
    err = git_object_lookup(&tree, repo, &tree_id, GIT_OBJ_TREE);
    entry = git_tree_entry_byname((git_tree*)tree, NAME);
    printf("%s %s\n", NAME, (entry == NULL ? "not found" : "found"));
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0