mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-29 09:36:47 +00:00
Changed return value of git_oid_match to be consistent with the other compare methods (0 means oids match). Added method to compare prefixes of hex formatted oids.
This commit is contained in:
parent
ac2b94ad76
commit
da03c9f35b
@ -142,7 +142,7 @@ GIT_EXTERN(int) git_oid_cmp(const git_oid *a, const git_oid *b);
|
|||||||
* @param len the number of hex chars to compare
|
* @param len the number of hex chars to compare
|
||||||
* @param a first oid structure.
|
* @param a first oid structure.
|
||||||
* @param b second oid structure.
|
* @param b second oid structure.
|
||||||
* @return 1 in case of a match
|
* @return 0 in case of a match
|
||||||
*/
|
*/
|
||||||
GIT_EXTERN(int) gid_oid_match(unsigned int len, git_oid *a, git_oid *b);
|
GIT_EXTERN(int) gid_oid_match(unsigned int len, git_oid *a, git_oid *b);
|
||||||
|
|
||||||
|
11
src/oid.c
11
src/oid.c
@ -177,15 +177,20 @@ int git_oid_match_raw(unsigned int len, const unsigned char *a, const unsigned c
|
|||||||
{
|
{
|
||||||
do {
|
do {
|
||||||
if (*a != *b)
|
if (*a != *b)
|
||||||
return 0;
|
return 1;
|
||||||
a++;
|
a++;
|
||||||
b++;
|
b++;
|
||||||
len -= 2;
|
len -= 2;
|
||||||
} while (len > 1);
|
} while (len > 1);
|
||||||
if (len)
|
if (len)
|
||||||
if ((*a ^ *b) & 0xf0)
|
if ((*a ^ *b) & 0xf0)
|
||||||
return 0;
|
return 1;
|
||||||
return 1;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int git_oid_match_hex(unsigned int len, const unsigned char *a, const unsigned char *b)
|
||||||
|
{
|
||||||
|
return memcmp(a, b, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
int gid_oid_match(unsigned int len, git_oid *a, git_oid *b)
|
int gid_oid_match(unsigned int len, git_oid *a, git_oid *b)
|
||||||
|
12
src/oid.h
12
src/oid.h
@ -1,7 +1,17 @@
|
|||||||
#ifndef INCLUDE_oid_h__
|
#ifndef INCLUDE_oid_h__
|
||||||
#define INCLUDE_oid_h__
|
#define INCLUDE_oid_h__
|
||||||
|
|
||||||
/* This can be useful for internal use */
|
/**
|
||||||
|
* Compare the first ('len'*4) bits of two raw formatted oids.
|
||||||
|
* This can be useful for internal use.
|
||||||
|
* Return 0 if they match.
|
||||||
|
*/
|
||||||
int git_oid_match_raw(unsigned int len, const unsigned char *a, const unsigned char *b);
|
int git_oid_match_raw(unsigned int len, const unsigned char *a, const unsigned char *b);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compare the first 'len' characters of two hex formatted oids.
|
||||||
|
* Return 0 if they match.
|
||||||
|
*/
|
||||||
|
int git_oid_match_hex(unsigned int len, const unsigned char *a, const unsigned char *b);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user