Unverified Commit 4f1923e8 by Patrick Steinhardt Committed by GitHub

Merge pull request #5390 from pks-t/pks/sha1-lookup

sha1_lookup: inline its only function into "pack.c"
parents 8aa04a37 f0f1cd1d
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include "hash.h" #include "hash.h"
#include "odb.h" #include "odb.h"
#include "delta.h" #include "delta.h"
#include "sha1_lookup.h"
#include "mwindow.h" #include "mwindow.h"
#include "pack.h" #include "pack.h"
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "mwindow.h" #include "mwindow.h"
#include "odb.h" #include "odb.h"
#include "oid.h" #include "oid.h"
#include "sha1_lookup.h"
/* Option to bypass checking existence of '.keep' files */ /* Option to bypass checking existence of '.keep' files */
bool git_disable_pack_keep_file_checks = false; bool git_disable_pack_keep_file_checks = false;
...@@ -1239,6 +1238,27 @@ int git_pack_foreach_entry( ...@@ -1239,6 +1238,27 @@ int git_pack_foreach_entry(
return error; return error;
} }
static int sha1_position(const void *table, size_t stride, unsigned lo,
unsigned hi, const unsigned char *key)
{
const unsigned char *base = table;
while (lo < hi) {
unsigned mi = (lo + hi) / 2;
int cmp = git_oid__hashcmp(base + mi * stride, key);
if (!cmp)
return mi;
if (cmp > 0)
hi = mi;
else
lo = mi+1;
}
return -((int)lo)-1;
}
static int pack_entry_find_offset( static int pack_entry_find_offset(
off64_t *offset_out, off64_t *offset_out,
git_oid *found_oid, git_oid *found_oid,
......
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#include "sha1_lookup.h"
#include <stdio.h>
#include "oid.h"
int sha1_position(const void *table,
size_t stride,
unsigned lo, unsigned hi,
const unsigned char *key)
{
const unsigned char *base = table;
while (lo < hi) {
unsigned mi = (lo + hi) / 2;
int cmp = git_oid__hashcmp(base + mi * stride, key);
if (!cmp)
return mi;
if (cmp > 0)
hi = mi;
else
lo = mi+1;
}
return -((int)lo)-1;
}
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_sha1_lookup_h__
#define INCLUDE_sha1_lookup_h__
#include "common.h"
#include <stdlib.h>
int sha1_position(const void *table,
size_t stride,
unsigned lo, unsigned hi,
const unsigned char *key);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment