add_packed_ref(): new function in the refs API.

Add a new function add_packed_ref() that adds a reference directly to the in-memory packed reference cache. This will be useful for creating local references while cloning. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael Haggerty committed Jan 17, 2012 at 06:50 UTC 30249ee68fa5fa63bfb9bb417987b0547253b8e7
2 files changed +12
refs.c
+6
@@ -319,6 +319,12 @@ static struct ref_array *get_packed_refs(struct ref_cache *refs)
319 return &refs->packed;
320 }
321
322 +void add_packed_ref(const char *refname, const unsigned char *sha1)
323 +{
324 + add_ref(get_packed_refs(get_ref_cache(NULL)),
325 + create_ref_entry(refname, sha1, REF_ISPACKED, 1));
326 +}
327 +
328 static void get_ref_dir(struct ref_cache *refs, const char *base,
329 struct ref_array *array)
330 {
refs.h
+6
@@ -50,6 +50,12 @@ extern int for_each_rawref(each_ref_fn, void *);
50
51 extern void warn_dangling_symref(FILE *fp, const char *msg_fmt, const char *refname);
52
53 +/*
54 + * Add a reference to the in-memory packed reference cache. To actually
55 + * write the reference to the packed-refs file, call pack_refs().
56 + */
57 +extern void add_packed_ref(const char *refname, const unsigned char *sha1);
58 +
59 /*
60 * Extra refs will be listed by for_each_ref() before any actual refs
61 * for the duration of this process or until clear_extra_refs() is