mirror of
https://git.proxmox.com/git/libgit2
synced 2025-08-12 12:00:29 +00:00
Added error for ambiguous oid prefixes. Added methods to compare the first nth hexadecimal characters (i.e. packets of 4 bits) of OIDs.
This commit is contained in:
parent
ecd6fdf1f7
commit
53c0bd81a2
@ -119,6 +119,9 @@ typedef enum {
|
|||||||
|
|
||||||
/** The specified object has its data corrupted */
|
/** The specified object has its data corrupted */
|
||||||
GIT_EOBJCORRUPTED = -28,
|
GIT_EOBJCORRUPTED = -28,
|
||||||
|
|
||||||
|
/** The given short oid is ambiguous */
|
||||||
|
GIT_EAMBIGUOUSOIDPREFIX = -29,
|
||||||
} git_error;
|
} git_error;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -132,6 +132,16 @@ GIT_EXTERN(void) git_oid_cpy(git_oid *out, const git_oid *src);
|
|||||||
*/
|
*/
|
||||||
GIT_EXTERN(int) git_oid_cmp(const git_oid *a, const git_oid *b);
|
GIT_EXTERN(int) git_oid_cmp(const git_oid *a, const git_oid *b);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compare the first 'len' hexadecimal characters (packets of 4 bits)
|
||||||
|
* of two oid structures.
|
||||||
|
* @param len the number of hex chars to compare
|
||||||
|
* @param a first oid structure.
|
||||||
|
* @param b second oid structure.
|
||||||
|
* @return 1 in case of a match
|
||||||
|
*/
|
||||||
|
GIT_EXTERN(int) gid_oid_match(unsigned int len, git_oid *a, git_oid *b);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OID Shortener object
|
* OID Shortener object
|
||||||
*/
|
*/
|
||||||
|
@ -42,6 +42,11 @@ GIT_INLINE(int) git_cached_obj_compare(git_cached_obj *obj, const git_oid *oid)
|
|||||||
return git_oid_cmp(&obj->oid, oid);
|
return git_oid_cmp(&obj->oid, oid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GIT_INLINE(int) git_cached_obj_match(unsigned int len, git_cached_obj *obj, const git_oid *oid)
|
||||||
|
{
|
||||||
|
return git_oid_match(len, &obj->oid, oid);
|
||||||
|
}
|
||||||
|
|
||||||
GIT_INLINE(void) git_cached_obj_incref(git_cached_obj *obj)
|
GIT_INLINE(void) git_cached_obj_incref(git_cached_obj *obj)
|
||||||
{
|
{
|
||||||
git_atomic_inc(&obj->refcount);
|
git_atomic_inc(&obj->refcount);
|
||||||
|
@ -61,6 +61,7 @@ static struct {
|
|||||||
{GIT_EEXISTS, "A reference with this name already exists"},
|
{GIT_EEXISTS, "A reference with this name already exists"},
|
||||||
{GIT_EOVERFLOW, "The given integer literal is too large to be parsed"},
|
{GIT_EOVERFLOW, "The given integer literal is too large to be parsed"},
|
||||||
{GIT_ENOTNUM, "The given literal is not a valid number"},
|
{GIT_ENOTNUM, "The given literal is not a valid number"},
|
||||||
|
{GIT_EAMBIGUOUSOIDPREFIX, "The given oid prefix is ambiguous"},
|
||||||
};
|
};
|
||||||
|
|
||||||
const char *git_strerror(int num)
|
const char *git_strerror(int num)
|
||||||
|
20
src/oid.c
20
src/oid.c
@ -173,6 +173,26 @@ int git_oid_cmp(const git_oid *a, const git_oid *b)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int git_oid_match_raw(unsigned int len, const unsigned char *a, const unsigned char *b)
|
||||||
|
{
|
||||||
|
do {
|
||||||
|
if (*a != *b)
|
||||||
|
return 0;
|
||||||
|
a++;
|
||||||
|
b++;
|
||||||
|
len -= 2;
|
||||||
|
} while (len > 1);
|
||||||
|
if (len)
|
||||||
|
if ((*a ^ *b) & 0xf0)
|
||||||
|
return 0;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int gid_oid_match(unsigned int len, git_oid *a, git_oid *b)
|
||||||
|
{
|
||||||
|
return git_oid_match_raw(len, a->id, b->id);
|
||||||
|
}
|
||||||
|
|
||||||
typedef short node_index;
|
typedef short node_index;
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
|
Loading…
Reference in New Issue
Block a user