mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-11 20:13:24 +00:00
Add git_tree_entry_cmp and git_tree_entry_icmp
This adds a new external API git_tree_entry_cmp and a new internal API git_tree_entry_icmp for sorting tree entries. The case insensitive one is internal only because general users should never be seeing case-insensitively sorted trees.
This commit is contained in:
parent
23594c1dae
commit
98527b5b24
@ -208,6 +208,15 @@ GIT_EXTERN(git_otype) git_tree_entry_type(const git_tree_entry *entry);
|
|||||||
*/
|
*/
|
||||||
GIT_EXTERN(git_filemode_t) git_tree_entry_filemode(const git_tree_entry *entry);
|
GIT_EXTERN(git_filemode_t) git_tree_entry_filemode(const git_tree_entry *entry);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compare two tree entries
|
||||||
|
*
|
||||||
|
* @param e1 first tree entry
|
||||||
|
* @param e2 second tree entry
|
||||||
|
* @return <0 if e1 is before e2, 0 if e1 == e2, >0 if e1 is after e2
|
||||||
|
*/
|
||||||
|
GIT_EXTERN(int) git_tree_entry_cmp(const git_tree_entry *e1, const git_tree_entry *e2);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a tree entry to the git_object it points too.
|
* Convert a tree entry to the git_object it points too.
|
||||||
*
|
*
|
||||||
|
21
src/tree.c
21
src/tree.c
@ -55,14 +55,23 @@ static int valid_entry_name(const char *filename)
|
|||||||
strcmp(filename, DOT_GIT) != 0));
|
strcmp(filename, DOT_GIT) != 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int git_tree_entry_cmp(const git_tree_entry *e1, const git_tree_entry *e2)
|
||||||
|
{
|
||||||
|
return git_path_cmp(
|
||||||
|
e1->filename, e1->filename_len, git_tree_entry__is_tree(e1),
|
||||||
|
e2->filename, e2->filename_len, git_tree_entry__is_tree(e2));
|
||||||
|
}
|
||||||
|
|
||||||
|
int git_tree_entry_icmp(const git_tree_entry *e1, const git_tree_entry *e2)
|
||||||
|
{
|
||||||
|
return git_path_icmp(
|
||||||
|
e1->filename, e1->filename_len, git_tree_entry__is_tree(e1),
|
||||||
|
e2->filename, e2->filename_len, git_tree_entry__is_tree(e2));
|
||||||
|
}
|
||||||
|
|
||||||
static int entry_sort_cmp(const void *a, const void *b)
|
static int entry_sort_cmp(const void *a, const void *b)
|
||||||
{
|
{
|
||||||
const git_tree_entry *entry_a = (const git_tree_entry *)(a);
|
return git_tree_entry_cmp((const git_tree_entry *)a, (const git_tree_entry *)b);
|
||||||
const git_tree_entry *entry_b = (const git_tree_entry *)(b);
|
|
||||||
|
|
||||||
return git_path_cmp(
|
|
||||||
entry_a->filename, entry_a->filename_len, git_tree_entry__is_tree(entry_a),
|
|
||||||
entry_b->filename, entry_b->filename_len, git_tree_entry__is_tree(entry_b));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static git_tree_entry *alloc_entry(const char *filename)
|
static git_tree_entry *alloc_entry(const char *filename)
|
||||||
|
@ -39,6 +39,8 @@ GIT_INLINE(bool) git_tree_entry__is_tree(const struct git_tree_entry *e)
|
|||||||
return (S_ISDIR(e->attr) && !S_ISGITLINK(e->attr));
|
return (S_ISDIR(e->attr) && !S_ISGITLINK(e->attr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern int git_tree_entry_icmp(const git_tree_entry *e1, const git_tree_entry *e2);
|
||||||
|
|
||||||
void git_tree__free(git_tree *tree);
|
void git_tree__free(git_tree *tree);
|
||||||
int git_tree__parse(git_tree *tree, git_odb_object *obj);
|
int git_tree__parse(git_tree *tree, git_odb_object *obj);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user