Skip to content

Commit

Permalink
refs: pass down referent in the case of a symbolic ref
Browse files Browse the repository at this point in the history
  • Loading branch information
john-cai committed Mar 26, 2024
1 parent e09f125 commit 72ad036
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 4 deletions.
1 change: 1 addition & 0 deletions builtin/replace.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ struct show_data {
};

static int show_reference(struct repository *r, const char *refname,
const char *referent UNUSED,
const struct object_id *oid,
int flag UNUSED, void *cb_data)
{
Expand Down
20 changes: 19 additions & 1 deletion refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1664,6 +1664,7 @@ struct do_for_each_ref_help {

static int do_for_each_ref_helper(struct repository *r UNUSED,
const char *refname,
const char *referent,
const struct object_id *oid,
int flags,
void *cb_data)
Expand Down Expand Up @@ -1926,8 +1927,9 @@ int refs_read_symbolic_ref(struct ref_store *ref_store, const char *refname,
return ref_store->be->read_symbolic_ref(ref_store, refname, referent);
}

const char *refs_resolve_ref_unsafe(struct ref_store *refs,
const char *refs_resolve_ref_unsafe_with_referent(struct ref_store *refs,
const char *refname,
char **referent,
int resolve_flags,
struct object_id *oid,
int *flags)
Expand Down Expand Up @@ -1989,6 +1991,8 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
}

*flags |= read_flags;
if (referent && read_flags & REF_ISSYMREF && sb_refname.len > 0)
*referent = sb_refname.buf;

if (!(read_flags & REF_ISSYMREF)) {
if (*flags & REF_BAD_NAME) {
Expand All @@ -2013,6 +2017,19 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
}

return NULL;

}

const char *refs_resolve_ref_unsafe(struct ref_store *refs,
const char *refname,
int resolve_flags,
struct object_id *oid,
int *flags)
{
return refs_resolve_ref_unsafe_with_referent(refs, refname, NULL,
resolve_flags,
oid,
flags);
}

/* backend functions */
Expand Down Expand Up @@ -2562,6 +2579,7 @@ struct do_for_each_reflog_help {

static int do_for_each_reflog_helper(struct repository *r UNUSED,
const char *refname,
const char *referent,
const struct object_id *oid UNUSED,
int flags,
void *cb_data)
Expand Down
9 changes: 9 additions & 0 deletions refs.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ struct pack_refs_opts {
struct string_list *includes;
};

const char *refs_resolve_ref_unsafe_with_referent(struct ref_store *refs,
const char *refname,
char **referent,
int resolve_flags,
struct object_id *oid,
int *flags);


const char *refs_resolve_ref_unsafe(struct ref_store *refs,
const char *refname,
int resolve_flags,
Expand Down Expand Up @@ -310,6 +318,7 @@ typedef int each_ref_fn(const char *refname,
*/
typedef int each_repo_ref_fn(struct repository *r,
const char *refname,
const char *referent,
const struct object_id *oid,
int flags,
void *cb_data);
Expand Down
6 changes: 4 additions & 2 deletions refs/files-backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,9 @@ static void loose_fill_ref_dir_regular_file(struct files_ref_store *refs,
{
struct object_id oid;
int flag;
char *referent;

if (!refs_resolve_ref_unsafe(&refs->base, refname, RESOLVE_REF_READING,
if (!refs_resolve_ref_unsafe_with_referent(&refs->base, refname, &referent, RESOLVE_REF_READING,
&oid, &flag)) {
oidclr(&oid);
flag |= REF_ISBROKEN;
Expand All @@ -258,7 +259,7 @@ static void loose_fill_ref_dir_regular_file(struct files_ref_store *refs,
oidclr(&oid);
flag |= REF_BAD_NAME | REF_ISBROKEN;
}
add_entry_to_dir(dir, create_ref_entry(refname, &oid, flag));
add_entry_to_dir(dir, create_ref_entry(refname, referent, &oid, flag));
}

/*
Expand Down Expand Up @@ -843,6 +844,7 @@ static int files_ref_iterator_advance(struct ref_iterator *ref_iterator)
continue;

iter->base.refname = iter->iter0->refname;
iter->base.referent = iter->iter0->referent;
iter->base.oid = iter->iter0->oid;
iter->base.flags = iter->iter0->flags;
return ITER_OK;
Expand Down
3 changes: 2 additions & 1 deletion refs/iterator.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ static int merge_ref_iterator_advance(struct ref_iterator *ref_iterator)
}

if (selection & ITER_YIELD_CURRENT) {
iter->base.referent = (*iter->current)->referent;
iter->base.refname = (*iter->current)->refname;
iter->base.oid = (*iter->current)->oid;
iter->base.flags = (*iter->current)->flags;
Expand Down Expand Up @@ -448,7 +449,7 @@ int do_for_each_repo_ref_iterator(struct repository *r, struct ref_iterator *ite

current_ref_iter = iter;
while ((ok = ref_iterator_advance(iter)) == ITER_OK) {
retval = fn(r, iter->refname, iter->oid, iter->flags, cb_data);
retval = fn(r, iter->refname, iter->referent, iter->oid, iter->flags, cb_data);
if (retval) {
/*
* If ref_iterator_abort() returns ITER_ERROR,
Expand Down
3 changes: 3 additions & 0 deletions refs/ref-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ struct ref_dir *get_ref_dir(struct ref_entry *entry)
}

struct ref_entry *create_ref_entry(const char *refname,
const char *referent,
const struct object_id *oid, int flag)
{
struct ref_entry *ref;

FLEX_ALLOC_STR(ref, name, refname);
oidcpy(&ref->u.value.oid, oid);
ref->u.value.referent = referent;
ref->flag = flag;
return ref;
}
Expand Down Expand Up @@ -428,6 +430,7 @@ static int cache_ref_iterator_advance(struct ref_iterator *ref_iterator)
level->prefix_state = entry_prefix_state;
level->index = -1;
} else {
iter->base.referent = entry->u.value.referent;
iter->base.refname = entry->name;
iter->base.oid = &entry->u.value.oid;
iter->base.flags = entry->flag;
Expand Down
2 changes: 2 additions & 0 deletions refs/ref-cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ struct ref_value {
* referred to by the last reference in the symlink chain.
*/
struct object_id oid;
const char *referent;
};

/*
Expand Down Expand Up @@ -173,6 +174,7 @@ struct ref_entry *create_dir_entry(struct ref_cache *cache,
const char *dirname, size_t len);

struct ref_entry *create_ref_entry(const char *refname,
const char *referent,
const struct object_id *oid, int flag);

/*
Expand Down
1 change: 1 addition & 0 deletions refs/refs-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ enum do_for_each_ref_flags {
struct ref_iterator {
struct ref_iterator_vtable *vtable;
const char *refname;
const char *referent;
const struct object_id *oid;
unsigned int flags;
};
Expand Down
1 change: 1 addition & 0 deletions replace-object.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

static int register_replace_ref(struct repository *r,
const char *refname,
const char *referent,
const struct object_id *oid,
int flag UNUSED,
void *cb_data UNUSED)
Expand Down

0 comments on commit 72ad036

Please sign in to comment.