Allow for having for_each_ref() list extra refs
These refs can be anything, but they are most likely useful as pointing to objects that you know are in the object database but don't have any regular refs for. For example, when cloning with --reference, the refs in this repository should be listed as objects that we have, even though we don't have refs in our newly-created repository for them yet. Signed-off-by: Daniel Barkalow <barkalow@iabervon.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
e0aaa29ff3
commit
e142a3c61d
18
refs.c
18
refs.c
@ -159,6 +159,8 @@ static struct cached_refs {
|
||||
} cached_refs;
|
||||
static struct ref_list *current_ref;
|
||||
|
||||
static struct ref_list *extra_refs;
|
||||
|
||||
static void free_ref_list(struct ref_list *list)
|
||||
{
|
||||
struct ref_list *next;
|
||||
@ -215,6 +217,17 @@ static void read_packed_refs(FILE *f, struct cached_refs *cached_refs)
|
||||
cached_refs->packed = sort_ref_list(list);
|
||||
}
|
||||
|
||||
void add_extra_ref(const char *name, const unsigned char *sha1, int flag)
|
||||
{
|
||||
extra_refs = add_ref(name, sha1, flag, extra_refs, NULL);
|
||||
}
|
||||
|
||||
void clear_extra_refs(void)
|
||||
{
|
||||
free_ref_list(extra_refs);
|
||||
extra_refs = NULL;
|
||||
}
|
||||
|
||||
static struct ref_list *get_packed_refs(void)
|
||||
{
|
||||
if (!cached_refs.did_packed) {
|
||||
@ -536,6 +549,11 @@ static int do_for_each_ref(const char *base, each_ref_fn fn, int trim,
|
||||
struct ref_list *packed = get_packed_refs();
|
||||
struct ref_list *loose = get_loose_refs();
|
||||
|
||||
struct ref_list *extra;
|
||||
|
||||
for (extra = extra_refs; extra; extra = extra->next)
|
||||
retval = do_one_ref(base, fn, trim, cb_data, extra);
|
||||
|
||||
while (packed && loose) {
|
||||
struct ref_list *entry;
|
||||
int cmp = strcmp(packed->name, loose->name);
|
||||
|
Reference in New Issue
Block a user