sha1-name.c: remove the_repo from get_oid_1()

There is a cyclic dependency between one of these functions so they
cannot be converted one by one, so all related functions are converted
at once.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Nguyễn Thái Ngọc Duy 2019-04-16 16:33:32 +07:00 committed by Junio C Hamano
parent 49281cf544
commit 2b1790f5ab
2 changed files with 36 additions and 30 deletions

View File

@ -1491,8 +1491,11 @@ extern void *read_object_with_reference(const struct object_id *oid,
unsigned long *size,
struct object_id *oid_ret);
extern struct object *peel_to_type(const char *name, int namelen,
struct object *o, enum object_type);
struct object *repo_peel_to_type(struct repository *r,
const char *name, int namelen,
struct object *o, enum object_type);
#define peel_to_type(name, namelen, obj, type) \
repo_peel_to_type(the_repository, name, namelen, obj, type)
enum date_mode_type {
DATE_NORMAL = 0,

View File

@ -770,7 +770,7 @@ static inline int push_mark(const char *string, int len)
return at_mark(string, len, suffix, ARRAY_SIZE(suffix));
}
static enum get_oid_result get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags);
static enum get_oid_result get_oid_1(struct repository *r, const char *name, int len, struct object_id *oid, unsigned lookup_flags);
static int interpret_nth_prior_checkout(struct repository *r, const char *name, int namelen, struct strbuf *buf);
static int get_oid_basic(struct repository *r, const char *str, int len,
@ -921,18 +921,19 @@ static int get_oid_basic(struct repository *r, const char *str, int len,
return 0;
}
static enum get_oid_result get_parent(const char *name, int len,
static enum get_oid_result get_parent(struct repository *r,
const char *name, int len,
struct object_id *result, int idx)
{
struct object_id oid;
enum get_oid_result ret = get_oid_1(name, len, &oid,
enum get_oid_result ret = get_oid_1(r, name, len, &oid,
GET_OID_COMMITTISH);
struct commit *commit;
struct commit_list *p;
if (ret)
return ret;
commit = lookup_commit_reference(the_repository, &oid);
commit = lookup_commit_reference(r, &oid);
if (parse_commit(commit))
return MISSING_OBJECT;
if (!idx) {
@ -950,7 +951,8 @@ static enum get_oid_result get_parent(const char *name, int len,
return MISSING_OBJECT;
}
static enum get_oid_result get_nth_ancestor(const char *name, int len,
static enum get_oid_result get_nth_ancestor(struct repository *r,
const char *name, int len,
struct object_id *result,
int generation)
{
@ -958,10 +960,10 @@ static enum get_oid_result get_nth_ancestor(const char *name, int len,
struct commit *commit;
int ret;
ret = get_oid_1(name, len, &oid, GET_OID_COMMITTISH);
ret = get_oid_1(r, name, len, &oid, GET_OID_COMMITTISH);
if (ret)
return ret;
commit = lookup_commit_reference(the_repository, &oid);
commit = lookup_commit_reference(r, &oid);
if (!commit)
return MISSING_OBJECT;
@ -974,20 +976,20 @@ static enum get_oid_result get_nth_ancestor(const char *name, int len,
return FOUND;
}
struct object *peel_to_type(const char *name, int namelen,
struct object *o, enum object_type expected_type)
struct object *repo_peel_to_type(struct repository *r, const char *name, int namelen,
struct object *o, enum object_type expected_type)
{
if (name && !namelen)
namelen = strlen(name);
while (1) {
if (!o || (!o->parsed && !parse_object(the_repository, &o->oid)))
if (!o || (!o->parsed && !parse_object(r, &o->oid)))
return NULL;
if (expected_type == OBJ_ANY || o->type == expected_type)
return o;
if (o->type == OBJ_TAG)
o = ((struct tag*) o)->tagged;
else if (o->type == OBJ_COMMIT)
o = &(get_commit_tree(((struct commit *)o))->object);
o = &(repo_get_commit_tree(r, ((struct commit *)o))->object);
else {
if (name)
error("%.*s: expected %s type, but the object "
@ -999,8 +1001,8 @@ struct object *peel_to_type(const char *name, int namelen,
}
}
static int peel_onion(const char *name, int len, struct object_id *oid,
unsigned lookup_flags)
static int peel_onion(struct repository *r, const char *name, int len,
struct object_id *oid, unsigned lookup_flags)
{
struct object_id outer;
const char *sp;
@ -1050,15 +1052,15 @@ static int peel_onion(const char *name, int len, struct object_id *oid,
else if (expected_type == OBJ_TREE)
lookup_flags |= GET_OID_TREEISH;
if (get_oid_1(name, sp - name - 2, &outer, lookup_flags))
if (get_oid_1(r, name, sp - name - 2, &outer, lookup_flags))
return -1;
o = parse_object(the_repository, &outer);
o = parse_object(r, &outer);
if (!o)
return -1;
if (!expected_type) {
o = deref_tag(the_repository, o, name, sp - name - 2);
if (!o || (!o->parsed && !parse_object(the_repository, &o->oid)))
o = deref_tag(r, o, name, sp - name - 2);
if (!o || (!o->parsed && !parse_object(r, &o->oid)))
return -1;
oidcpy(oid, &o->oid);
return 0;
@ -1069,7 +1071,7 @@ static int peel_onion(const char *name, int len, struct object_id *oid,
* if we do not get the needed object, we should
* barf.
*/
o = peel_to_type(name, len, o, expected_type);
o = repo_peel_to_type(r, name, len, o, expected_type);
if (!o)
return -1;
@ -1089,7 +1091,7 @@ static int peel_onion(const char *name, int len, struct object_id *oid,
prefix = xstrndup(sp + 1, name + len - 1 - (sp + 1));
commit_list_insert((struct commit *)o, &list);
ret = get_oid_oneline(the_repository, prefix, oid, list);
ret = get_oid_oneline(r, prefix, oid, list);
free(prefix);
return ret;
}
@ -1120,7 +1122,8 @@ static int get_describe_name(struct repository *r,
return -1;
}
static enum get_oid_result get_oid_1(const char *name, int len,
static enum get_oid_result get_oid_1(struct repository *r,
const char *name, int len,
struct object_id *oid,
unsigned lookup_flags)
{
@ -1149,25 +1152,25 @@ static enum get_oid_result get_oid_1(const char *name, int len,
if (!num && len1 == len - 1)
num = 1;
if (has_suffix == '^')
return get_parent(name, len1, oid, num);
return get_parent(r, name, len1, oid, num);
/* else if (has_suffix == '~') -- goes without saying */
return get_nth_ancestor(name, len1, oid, num);
return get_nth_ancestor(r, name, len1, oid, num);
}
ret = peel_onion(name, len, oid, lookup_flags);
ret = peel_onion(r, name, len, oid, lookup_flags);
if (!ret)
return FOUND;
ret = get_oid_basic(the_repository, name, len, oid, lookup_flags);
ret = get_oid_basic(r, name, len, oid, lookup_flags);
if (!ret)
return FOUND;
/* It could be describe output that is "SOMETHING-gXXXX" */
ret = get_describe_name(the_repository, name, len, oid);
ret = get_describe_name(r, name, len, oid);
if (!ret)
return FOUND;
return get_short_oid(the_repository, name, len, oid, lookup_flags);
return get_short_oid(r, name, len, oid, lookup_flags);
}
/*
@ -1741,7 +1744,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
memset(oc, 0, sizeof(*oc));
oc->mode = S_IFINVALID;
strbuf_init(&oc->symlink_path, 0);
ret = get_oid_1(name, namelen, oid, flags);
ret = get_oid_1(repo, name, namelen, oid, flags);
if (!ret)
return ret;
/*
@ -1822,7 +1825,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
sub_flags &= ~GET_OID_DISAMBIGUATORS;
sub_flags |= GET_OID_TREEISH;
if (!get_oid_1(name, len, &tree_oid, sub_flags)) {
if (!get_oid_1(repo, name, len, &tree_oid, sub_flags)) {
const char *filename = cp+1;
char *new_filename = NULL;