summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2011-06-16 02:48:48 +0200
committerVicent Marti <tanoku@gmail.com>2011-06-16 02:50:08 +0200
commitf1d018513aced2fb4e6c87f2d417b6f826dbe998 (patch)
treeed3f93db76dc70f854f20f4b3bd7f627c0ca6d19 /src
parentfa48608ec30758dbf6d0d26d3c4f8efba8efe8e9 (diff)
downloadlibgit2-f1d018513aced2fb4e6c87f2d417b6f826dbe998.tar.gz
oid: Uniformize ncmp methods
Drop redundant methods. The ncmp method is now public
Diffstat (limited to 'src')
-rw-r--r--src/odb_loose.c10
-rw-r--r--src/odb_pack.c6
-rw-r--r--src/oid.c40
-rw-r--r--src/oid.h17
4 files changed, 27 insertions, 46 deletions
diff --git a/src/odb_loose.c b/src/odb_loose.c
index 006ba9cc8..510712bd8 100644
--- a/src/odb_loose.c
+++ b/src/odb_loose.c
@@ -26,10 +26,10 @@
#include "common.h"
#include "git2/zlib.h"
#include "git2/object.h"
+#include "git2/oid.h"
#include "fileops.h"
#include "hash.h"
#include "odb.h"
-#include "oid.h"
#include "delta-apply.h"
#include "filebuf.h"
@@ -491,8 +491,12 @@ int fn_locate_object_short_oid(void *state, char *pathbuf) {
}
if (!gitfo_exists(pathbuf) && gitfo_isdir(pathbuf)) {
- /* We are already in the directory matching the 2 first hex characters */
- if (!git_oid_ncmp_hex(sstate->short_oid_len-2, sstate->short_oid+2, (unsigned char *)pathbuf + sstate->dir_len)) {
+ /* We are already in the directory matching the 2 first hex characters,
+ * compare the first ncmp characters of the oids */
+ if (!memcmp(sstate->short_oid + 2,
+ (unsigned char *)pathbuf + sstate->dir_len,
+ sstate->short_oid_len - 2)) {
+
if (!sstate->found) {
sstate->res_oid[0] = sstate->short_oid[0];
sstate->res_oid[1] = sstate->short_oid[1];
diff --git a/src/odb_pack.c b/src/odb_pack.c
index d02338d62..8a88a0baa 100644
--- a/src/odb_pack.c
+++ b/src/odb_pack.c
@@ -26,10 +26,10 @@
#include "common.h"
#include "git2/zlib.h"
#include "git2/repository.h"
+#include "git2/oid.h"
#include "fileops.h"
#include "hash.h"
#include "odb.h"
-#include "oid.h"
#include "delta-apply.h"
#include "sha1_lookup.h"
@@ -1011,7 +1011,7 @@ static int pack_entry_find_offset(
if (pos < (int)p->num_objects) {
current = index + pos * stride;
- if (!git_oid_ncmp_raw(len, short_oid->id, current)) {
+ if (!git_oid_ncmp(short_oid, (const git_oid *)current, len)) {
found = 1;
}
}
@@ -1021,7 +1021,7 @@ static int pack_entry_find_offset(
/* Check for ambiguousity */
const unsigned char *next = current + stride;
- if (!git_oid_ncmp_raw(len, short_oid->id, next)) {
+ if (!git_oid_ncmp(short_oid, (const git_oid *)next, len)) {
found = 2;
}
}
diff --git a/src/oid.c b/src/oid.c
index 031be0617..3e3237f9c 100644
--- a/src/oid.c
+++ b/src/oid.c
@@ -172,30 +172,24 @@ int git_oid_cmp(const git_oid *a, const git_oid *b)
return memcmp(a->id, b->id, sizeof(a->id));
}
-
-int git_oid_ncmp_raw(unsigned int len, const unsigned char *a, const unsigned char *b)
-{
- do {
- if (*a != *b)
- return 1;
- a++;
- b++;
- len -= 2;
- } while (len > 1);
- if (len)
- if ((*a ^ *b) & 0xf0)
- return 1;
- return 0;
-}
-
-int git_oid_ncmp_hex(unsigned int len, const unsigned char *a, const unsigned char *b)
-{
- return memcmp(a, b, len);
-}
-
-int git_oid_ncmp(unsigned int len, git_oid *a, git_oid *b)
+int git_oid_ncmp(const git_oid *oid_a, const git_oid *oid_b, unsigned int len)
{
- return git_oid_ncmp_raw(len, a->id, b->id);
+ const unsigned char *a = oid_a->id;
+ const unsigned char *b = oid_b->id;
+
+ do {
+ if (*a != *b)
+ return 1;
+ a++;
+ b++;
+ len -= 2;
+ } while (len > 1);
+
+ if (len)
+ if ((*a ^ *b) & 0xf0)
+ return 1;
+
+ return 0;
}
typedef short node_index;
diff --git a/src/oid.h b/src/oid.h
deleted file mode 100644
index afdfcf9ba..000000000
--- a/src/oid.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef INCLUDE_oid_h__
-#define INCLUDE_oid_h__
-
-/**
- * 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_ncmp_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_ncmp_hex(unsigned int len, const unsigned char *a, const unsigned char *b);
-
-#endif