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>
Daniel Barkalow committed
Apr 27, 2008 at 13:39 UTC
e142a3c61d22c3a3c081cb2c693e4d3725c21522
2 files changed
+27
refs.c
+18
@@ -159,6 +159,8 @@ static struct cached_refs {
159
} cached_refs;
160
static struct ref_list *current_ref;
161
162
+static struct ref_list *extra_refs;
163
+
164
static void free_ref_list(struct ref_list *list)
165
{
166
struct ref_list *next;
@@ -215,6 +217,17 @@ static void read_packed_refs(FILE *f, struct cached_refs *cached_refs)
217
cached_refs->packed = sort_ref_list(list);
218
}
219
220
+void add_extra_ref(const char *name, const unsigned char *sha1, int flag)
221
+{
222
+ extra_refs = add_ref(name, sha1, flag, extra_refs, NULL);
223
+}
224
+
225
+void clear_extra_refs(void)
226
+{
227
+ free_ref_list(extra_refs);
228
+ extra_refs = NULL;
229
+}
230
+
231
static struct ref_list *get_packed_refs(void)
232
{
233
if (!cached_refs.did_packed) {
@@ -536,6 +549,11 @@ static int do_for_each_ref(const char *base, each_ref_fn fn, int trim,
549
struct ref_list *packed = get_packed_refs();
550
struct ref_list *loose = get_loose_refs();
551
552
+ struct ref_list *extra;
553
+
554
+ for (extra = extra_refs; extra; extra = extra->next)
555
+ retval = do_one_ref(base, fn, trim, cb_data, extra);
556
+
557
while (packed && loose) {
558
struct ref_list *entry;
559
int cmp = strcmp(packed->name, loose->name);
refs.h
+9
@@ -24,6 +24,15 @@ extern int for_each_tag_ref(each_ref_fn, void *);
24
extern int for_each_branch_ref(each_ref_fn, void *);
25
extern int for_each_remote_ref(each_ref_fn, void *);
26
27
+/*
28
+ * Extra refs will be listed by for_each_ref() before any actual refs
29
+ * for the duration of this process or until clear_extra_refs() is
30
+ * called. Only extra refs added before for_each_ref() is called will
31
+ * be listed on a given call of for_each_ref().
32
+ */
33
+extern void add_extra_ref(const char *refname, const unsigned char *sha1, int flags);
34
+extern void clear_extra_refs(void);
35
+
36
extern int peel_ref(const char *, unsigned char *);
37
38
/** Locks a "refs/" ref returning the lock on success and NULL on failure. **/