mirror of
https://github.com/git/git.git
synced 2025-01-25 17:04:16 +08:00
reftable/refname: refactor binary search over refnames
It is comparatively hard to understand how exactly the binary search over refnames works given that the function and variable names are not exactly easy to grasp. Rename them to make this more obvious. This should not result in any change in behaviour. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
e8b808258e
commit
21767925b0
@ -12,15 +12,15 @@
|
||||
#include "refname.h"
|
||||
#include "reftable-iterator.h"
|
||||
|
||||
struct find_arg {
|
||||
char **names;
|
||||
const char *want;
|
||||
struct refname_needle_lesseq_args {
|
||||
char **haystack;
|
||||
const char *needle;
|
||||
};
|
||||
|
||||
static int find_name(size_t k, void *arg)
|
||||
static int refname_needle_lesseq(size_t k, void *_args)
|
||||
{
|
||||
struct find_arg *f_arg = arg;
|
||||
return strcmp(f_arg->names[k], f_arg->want) >= 0;
|
||||
struct refname_needle_lesseq_args *args = _args;
|
||||
return strcmp(args->needle, args->haystack[k]) <= 0;
|
||||
}
|
||||
|
||||
static int modification_has_ref(struct modification *mod, const char *name)
|
||||
@ -29,21 +29,21 @@ static int modification_has_ref(struct modification *mod, const char *name)
|
||||
int err = 0;
|
||||
|
||||
if (mod->add_len > 0) {
|
||||
struct find_arg arg = {
|
||||
.names = mod->add,
|
||||
.want = name,
|
||||
struct refname_needle_lesseq_args args = {
|
||||
.haystack = mod->add,
|
||||
.needle = name,
|
||||
};
|
||||
size_t idx = binsearch(mod->add_len, find_name, &arg);
|
||||
size_t idx = binsearch(mod->add_len, refname_needle_lesseq, &args);
|
||||
if (idx < mod->add_len && !strcmp(mod->add[idx], name))
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (mod->del_len > 0) {
|
||||
struct find_arg arg = {
|
||||
.names = mod->del,
|
||||
.want = name,
|
||||
struct refname_needle_lesseq_args args = {
|
||||
.haystack = mod->del,
|
||||
.needle = name,
|
||||
};
|
||||
size_t idx = binsearch(mod->del_len, find_name, &arg);
|
||||
size_t idx = binsearch(mod->del_len, refname_needle_lesseq, &args);
|
||||
if (idx < mod->del_len && !strcmp(mod->del[idx], name))
|
||||
return 1;
|
||||
}
|
||||
@ -71,11 +71,11 @@ static int modification_has_ref_with_prefix(struct modification *mod,
|
||||
int err = 0;
|
||||
|
||||
if (mod->add_len > 0) {
|
||||
struct find_arg arg = {
|
||||
.names = mod->add,
|
||||
.want = prefix,
|
||||
struct refname_needle_lesseq_args args = {
|
||||
.haystack = mod->add,
|
||||
.needle = prefix,
|
||||
};
|
||||
size_t idx = binsearch(mod->add_len, find_name, &arg);
|
||||
size_t idx = binsearch(mod->add_len, refname_needle_lesseq, &args);
|
||||
if (idx < mod->add_len &&
|
||||
!strncmp(prefix, mod->add[idx], strlen(prefix)))
|
||||
goto done;
|
||||
@ -90,11 +90,11 @@ static int modification_has_ref_with_prefix(struct modification *mod,
|
||||
goto done;
|
||||
|
||||
if (mod->del_len > 0) {
|
||||
struct find_arg arg = {
|
||||
.names = mod->del,
|
||||
.want = ref.refname,
|
||||
struct refname_needle_lesseq_args args = {
|
||||
.haystack = mod->del,
|
||||
.needle = ref.refname,
|
||||
};
|
||||
size_t idx = binsearch(mod->del_len, find_name, &arg);
|
||||
size_t idx = binsearch(mod->del_len, refname_needle_lesseq, &args);
|
||||
if (idx < mod->del_len &&
|
||||
!strcmp(ref.refname, mod->del[idx]))
|
||||
continue;
|
||||
|
Loading…
Reference in New Issue
Block a user