mirror of
https://github.com/git/git.git
synced 2024-09-08 03:50:44 +02:00
refs: pass repo when peeling objects
Both `peel_object()` and `peel_iterated_oid()` implicitly rely on `the_repository` to look up objects. Despite the fact that we want to get rid of `the_repository`, it also leads to some restrictions in our ref iterators when trying to retrieve the peeled value for a repository other than `the_repository`. Refactor these functions such that both take a repository as argument and remove the now-unnecessary restrictions. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
19c76e8235
commit
30aaff437f
@ -200,7 +200,7 @@ static int get_name(const char *path, const struct object_id *oid,
|
||||
}
|
||||
|
||||
/* Is it annotated? */
|
||||
if (!peel_iterated_oid(oid, &peeled)) {
|
||||
if (!peel_iterated_oid(the_repository, oid, &peeled)) {
|
||||
is_annotated = !oideq(oid, &peeled);
|
||||
} else {
|
||||
oidcpy(&peeled, oid);
|
||||
|
@ -846,7 +846,7 @@ static int dfs_on_ref(const char *refname UNUSED,
|
||||
struct commit_list *stack = NULL;
|
||||
struct commit *commit;
|
||||
|
||||
if (!peel_iterated_oid(oid, &peeled))
|
||||
if (!peel_iterated_oid(the_repository, oid, &peeled))
|
||||
oid = &peeled;
|
||||
if (oid_object_info(the_repository, oid, NULL) != OBJ_COMMIT)
|
||||
return 0;
|
||||
|
@ -779,7 +779,7 @@ static int mark_tagged(const char *path UNUSED, const struct object_id *oid,
|
||||
|
||||
if (entry)
|
||||
entry->tagged = 1;
|
||||
if (!peel_iterated_oid(oid, &peeled)) {
|
||||
if (!peel_iterated_oid(the_repository, oid, &peeled)) {
|
||||
entry = packlist_find(&to_pack, &peeled);
|
||||
if (entry)
|
||||
entry->tagged = 1;
|
||||
@ -3125,7 +3125,7 @@ static int add_ref_tag(const char *tag UNUSED, const struct object_id *oid,
|
||||
{
|
||||
struct object_id peeled;
|
||||
|
||||
if (!peel_iterated_oid(oid, &peeled) && obj_is_packed(&peeled))
|
||||
if (!peel_iterated_oid(the_repository, oid, &peeled) && obj_is_packed(&peeled))
|
||||
add_tag_chain(oid);
|
||||
return 0;
|
||||
}
|
||||
@ -4074,7 +4074,7 @@ static int mark_bitmap_preferred_tip(const char *refname,
|
||||
struct object_id peeled;
|
||||
struct object *object;
|
||||
|
||||
if (!peel_iterated_oid(oid, &peeled))
|
||||
if (!peel_iterated_oid(the_repository, oid, &peeled))
|
||||
oid = &peeled;
|
||||
|
||||
object = parse_object_or_die(oid, refname);
|
||||
|
@ -673,7 +673,7 @@ static int midx_snapshot_ref_one(const char *refname UNUSED,
|
||||
struct midx_snapshot_ref_data *data = _data;
|
||||
struct object_id peeled;
|
||||
|
||||
if (!peel_iterated_oid(oid, &peeled))
|
||||
if (!peel_iterated_oid(the_repository, oid, &peeled))
|
||||
oid = &peeled;
|
||||
|
||||
if (oidset_insert(&data->seen, oid))
|
||||
|
@ -50,7 +50,7 @@ static void show_one(const struct show_one_options *opts,
|
||||
if (!opts->deref_tags)
|
||||
return;
|
||||
|
||||
if (!peel_iterated_oid(oid, &peeled)) {
|
||||
if (!peel_iterated_oid(the_repository, oid, &peeled)) {
|
||||
hex = repo_find_unique_abbrev(the_repository, &peeled, opts->abbrev);
|
||||
printf("%s %s^{}\n", hex, refname);
|
||||
}
|
||||
|
@ -1821,7 +1821,7 @@ static int add_ref_to_set(const char *refname UNUSED,
|
||||
struct object_id peeled;
|
||||
struct refs_cb_data *data = (struct refs_cb_data *)cb_data;
|
||||
|
||||
if (!peel_iterated_oid(oid, &peeled))
|
||||
if (!peel_iterated_oid(the_repository, oid, &peeled))
|
||||
oid = &peeled;
|
||||
if (oid_object_info(the_repository, oid, NULL) == OBJ_COMMIT)
|
||||
oidset_insert(data->commits, oid);
|
||||
|
@ -110,7 +110,7 @@ static int send_ref(const char *refname, const struct object_id *oid,
|
||||
|
||||
if (data->peel && oid) {
|
||||
struct object_id peeled;
|
||||
if (!peel_iterated_oid(oid, &peeled))
|
||||
if (!peel_iterated_oid(the_repository, oid, &peeled))
|
||||
strbuf_addf(&data->buf, " peeled:%s", oid_to_hex(&peeled));
|
||||
}
|
||||
|
||||
|
@ -664,7 +664,7 @@ static int add_ref_to_pending(const char *refname,
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!peel_iterated_oid(oid, &peeled))
|
||||
if (!peel_iterated_oid(the_repository, oid, &peeled))
|
||||
oid = &peeled;
|
||||
|
||||
object = parse_object_or_die(oid, refname);
|
||||
|
10
object.c
10
object.c
@ -207,12 +207,14 @@ struct object *lookup_object_by_type(struct repository *r,
|
||||
}
|
||||
}
|
||||
|
||||
enum peel_status peel_object(const struct object_id *name, struct object_id *oid)
|
||||
enum peel_status peel_object(struct repository *r,
|
||||
const struct object_id *name,
|
||||
struct object_id *oid)
|
||||
{
|
||||
struct object *o = lookup_unknown_object(the_repository, name);
|
||||
struct object *o = lookup_unknown_object(r, name);
|
||||
|
||||
if (o->type == OBJ_NONE) {
|
||||
int type = oid_object_info(the_repository, name, NULL);
|
||||
int type = oid_object_info(r, name, NULL);
|
||||
if (type < 0 || !object_as_type(o, type, 0))
|
||||
return PEEL_INVALID;
|
||||
}
|
||||
@ -220,7 +222,7 @@ enum peel_status peel_object(const struct object_id *name, struct object_id *oid
|
||||
if (o->type != OBJ_TAG)
|
||||
return PEEL_NON_TAG;
|
||||
|
||||
o = deref_tag_noverify(o);
|
||||
o = deref_tag_noverify(r, o);
|
||||
if (!o)
|
||||
return PEEL_INVALID;
|
||||
|
||||
|
3
object.h
3
object.h
@ -288,7 +288,8 @@ enum peel_status {
|
||||
* or is not valid, return PEEL_NON_TAG or PEEL_INVALID, respectively,
|
||||
* and leave oid unchanged.
|
||||
*/
|
||||
enum peel_status peel_object(const struct object_id *name, struct object_id *oid);
|
||||
enum peel_status peel_object(struct repository *r,
|
||||
const struct object_id *name, struct object_id *oid);
|
||||
|
||||
struct object_list *object_list_insert(struct object *item,
|
||||
struct object_list **list_p);
|
||||
|
@ -2520,7 +2520,7 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
|
||||
* If it is a tag object, see if we use the peeled value. If we do,
|
||||
* grab the peeled OID.
|
||||
*/
|
||||
if (need_tagged && peel_iterated_oid(&obj->oid, &oi_deref.oid))
|
||||
if (need_tagged && peel_iterated_oid(the_repository, &obj->oid, &oi_deref.oid))
|
||||
die("bad tag");
|
||||
|
||||
return get_object(ref, 1, &obj, &oi_deref, err);
|
||||
|
4
refs.c
4
refs.c
@ -2064,14 +2064,14 @@ int refs_pack_refs(struct ref_store *refs, struct pack_refs_opts *opts)
|
||||
return refs->be->pack_refs(refs, opts);
|
||||
}
|
||||
|
||||
int peel_iterated_oid(const struct object_id *base, struct object_id *peeled)
|
||||
int peel_iterated_oid(struct repository *r, const struct object_id *base, struct object_id *peeled)
|
||||
{
|
||||
if (current_ref_iter &&
|
||||
(current_ref_iter->oid == base ||
|
||||
oideq(current_ref_iter->oid, base)))
|
||||
return ref_iterator_peel(current_ref_iter, peeled);
|
||||
|
||||
return peel_object(base, peeled) ? -1 : 0;
|
||||
return peel_object(r, base, peeled) ? -1 : 0;
|
||||
}
|
||||
|
||||
int refs_create_symref(struct ref_store *refs,
|
||||
|
5
refs.h
5
refs.h
@ -127,13 +127,14 @@ void ref_store_release(struct ref_store *ref_store);
|
||||
* Return the peeled value of the oid currently being iterated via
|
||||
* for_each_ref(), etc. This is equivalent to calling:
|
||||
*
|
||||
* peel_object(oid, &peeled);
|
||||
* peel_object(r, oid, &peeled);
|
||||
*
|
||||
* with the "oid" value given to the each_ref_fn callback, except
|
||||
* that some ref storage may be able to answer the query without
|
||||
* actually loading the object in memory.
|
||||
*/
|
||||
int peel_iterated_oid(const struct object_id *base, struct object_id *peeled);
|
||||
int peel_iterated_oid(struct repository *r,
|
||||
const struct object_id *base, struct object_id *peeled);
|
||||
|
||||
/**
|
||||
* Resolve refname in the nested "gitlink" repository in the specified
|
||||
|
@ -953,16 +953,13 @@ static int packed_ref_iterator_peel(struct ref_iterator *ref_iterator,
|
||||
struct packed_ref_iterator *iter =
|
||||
(struct packed_ref_iterator *)ref_iterator;
|
||||
|
||||
if (iter->repo != the_repository)
|
||||
BUG("peeling for non-the_repository is not supported");
|
||||
|
||||
if ((iter->base.flags & REF_KNOWS_PEELED)) {
|
||||
oidcpy(peeled, &iter->peeled);
|
||||
return is_null_oid(&iter->peeled) ? -1 : 0;
|
||||
} else if ((iter->base.flags & (REF_ISBROKEN | REF_ISSYMREF))) {
|
||||
return -1;
|
||||
} else {
|
||||
return peel_object(&iter->oid, peeled) ? -1 : 0;
|
||||
return peel_object(iter->repo, &iter->oid, peeled) ? -1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1421,7 +1418,8 @@ static int write_with_updates(struct packed_ref_store *refs,
|
||||
i++;
|
||||
} else {
|
||||
struct object_id peeled;
|
||||
int peel_error = peel_object(&update->new_oid,
|
||||
int peel_error = peel_object(refs->base.repo,
|
||||
&update->new_oid,
|
||||
&peeled);
|
||||
|
||||
if (write_packed_entry(out, update->refname,
|
||||
|
@ -441,10 +441,7 @@ static int cache_ref_iterator_peel(struct ref_iterator *ref_iterator,
|
||||
{
|
||||
struct cache_ref_iterator *iter =
|
||||
(struct cache_ref_iterator *)ref_iterator;
|
||||
|
||||
if (iter->repo != the_repository)
|
||||
BUG("peeling for non-the_repository is not supported");
|
||||
return peel_object(ref_iterator->oid, peeled) ? -1 : 0;
|
||||
return peel_object(iter->repo, ref_iterator->oid, peeled) ? -1 : 0;
|
||||
}
|
||||
|
||||
static int cache_ref_iterator_abort(struct ref_iterator *ref_iterator)
|
||||
|
@ -1144,7 +1144,7 @@ static int write_transaction_table(struct reftable_writer *writer, void *cb_data
|
||||
ref.refname = (char *)u->refname;
|
||||
ref.update_index = ts;
|
||||
|
||||
peel_error = peel_object(&u->new_oid, &peeled);
|
||||
peel_error = peel_object(arg->refs->base.repo, &u->new_oid, &peeled);
|
||||
if (!peel_error) {
|
||||
ref.value_type = REFTABLE_REF_VAL2;
|
||||
memcpy(ref.value.val2.target_value, peeled.hash, GIT_MAX_RAWSZ);
|
||||
@ -2045,6 +2045,7 @@ static int reftable_be_delete_reflog(struct ref_store *ref_store,
|
||||
}
|
||||
|
||||
struct reflog_expiry_arg {
|
||||
struct reftable_ref_store *refs;
|
||||
struct reftable_stack *stack;
|
||||
struct reftable_log_record *records;
|
||||
struct object_id update_oid;
|
||||
@ -2073,7 +2074,7 @@ static int write_reflog_expiry_table(struct reftable_writer *writer, void *cb_da
|
||||
ref.refname = (char *)arg->refname;
|
||||
ref.update_index = ts;
|
||||
|
||||
if (!peel_object(&arg->update_oid, &peeled)) {
|
||||
if (!peel_object(arg->refs->base.repo, &arg->update_oid, &peeled)) {
|
||||
ref.value_type = REFTABLE_REF_VAL2;
|
||||
memcpy(ref.value.val2.target_value, peeled.hash, GIT_MAX_RAWSZ);
|
||||
memcpy(ref.value.val2.value, arg->update_oid.hash, GIT_MAX_RAWSZ);
|
||||
@ -2235,6 +2236,7 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
|
||||
reftable_ref_record_val1(&ref_record))
|
||||
oidread(&arg.update_oid, last_hash);
|
||||
|
||||
arg.refs = refs;
|
||||
arg.records = rewritten;
|
||||
arg.len = logs_nr;
|
||||
arg.stack = stack,
|
||||
|
@ -62,7 +62,7 @@ int cmd__reach(int ac, const char **av)
|
||||
die("failed to resolve %s", buf.buf + 2);
|
||||
|
||||
orig = parse_object(r, &oid);
|
||||
peeled = deref_tag_noverify(orig);
|
||||
peeled = deref_tag_noverify(the_repository, orig);
|
||||
|
||||
if (!peeled)
|
||||
die("failed to load commit for input %s resulting in oid %s\n",
|
||||
|
4
tag.c
4
tag.c
@ -91,10 +91,10 @@ struct object *deref_tag(struct repository *r, struct object *o, const char *war
|
||||
return o;
|
||||
}
|
||||
|
||||
struct object *deref_tag_noverify(struct object *o)
|
||||
struct object *deref_tag_noverify(struct repository *r, struct object *o)
|
||||
{
|
||||
while (o && o->type == OBJ_TAG) {
|
||||
o = parse_object(the_repository, &o->oid);
|
||||
o = parse_object(r, &o->oid);
|
||||
if (o && o->type == OBJ_TAG && ((struct tag *)o)->tagged)
|
||||
o = ((struct tag *)o)->tagged;
|
||||
else
|
||||
|
2
tag.h
2
tag.h
@ -16,7 +16,7 @@ int parse_tag_buffer(struct repository *r, struct tag *item, const void *data, u
|
||||
int parse_tag(struct tag *item);
|
||||
void release_tag_memory(struct tag *t);
|
||||
struct object *deref_tag(struct repository *r, struct object *, const char *, int);
|
||||
struct object *deref_tag_noverify(struct object *);
|
||||
struct object *deref_tag_noverify(struct repository *r, struct object *);
|
||||
int gpg_verify_tag(const struct object_id *oid,
|
||||
const char *name_to_report, unsigned flags);
|
||||
struct object_id *get_tagged_oid(struct tag *tag);
|
||||
|
@ -1269,7 +1269,7 @@ static void write_v0_ref(struct upload_pack_data *data,
|
||||
packet_fwrite_fmt(stdout, "%s %s\n", oid_to_hex(oid), refname_nons);
|
||||
}
|
||||
capabilities = NULL;
|
||||
if (!peel_iterated_oid(oid, &peeled))
|
||||
if (!peel_iterated_oid(the_repository, oid, &peeled))
|
||||
packet_fwrite_fmt(stdout, "%s %s^{}\n", oid_to_hex(&peeled), refname_nons);
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user