pack_refs(): change to use do_for_each_entry()
pack_refs() was not using any of the extra features of for_each_ref(), so change it to use do_for_each_entry(). This also gives it access to the ref_entry and in particular its peeled field, which will be taken advantage of in the next commit. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Apr 22, 2013 at 21:52 UTC
12e77559ec4bf863d3703a25ab79298d5ff89b3b
1 file changed
+15
-14
refs.c
+15
-14
@@ -2004,37 +2004,38 @@ static int do_not_prune(int flags)
2004
return (flags & (REF_ISSYMREF|REF_ISPACKED));
2005
}
2006
2007
-static int pack_one_ref(const char *refname, const unsigned char *sha1,
2008
- int flags, void *cb_data)
2007
+static int pack_one_ref(struct ref_entry *entry, void *cb_data)
2008
{
2009
struct pack_refs_cb_data *cb = cb_data;
2010
struct object *o;
2011
int is_tag_ref;
2012
2014
- /* Do not pack the symbolic refs */
2015
- if ((flags & REF_ISSYMREF))
2013
+ /* Do not pack symbolic or broken refs: */
2014
+ if ((entry->flag & REF_ISSYMREF) || !ref_resolves_to_object(entry))
2015
return 0;
2017
- is_tag_ref = !prefixcmp(refname, "refs/tags/");
2016
+ is_tag_ref = !prefixcmp(entry->name, "refs/tags/");
2017
2018
/* ALWAYS pack refs that were already packed or are tags */
2020
- if (!(cb->flags & PACK_REFS_ALL) && !is_tag_ref && !(flags & REF_ISPACKED))
2019
+ if (!(cb->flags & PACK_REFS_ALL) && !is_tag_ref &&
2020
+ !(entry->flag & REF_ISPACKED))
2021
return 0;
2022
2023
- fprintf(cb->refs_file, "%s %s\n", sha1_to_hex(sha1), refname);
2023
+ fprintf(cb->refs_file, "%s %s\n", sha1_to_hex(entry->u.value.sha1),
2024
+ entry->name);
2025
2025
- o = parse_object_or_die(sha1, refname);
2026
+ o = parse_object_or_die(entry->u.value.sha1, entry->name);
2027
if (o->type == OBJ_TAG) {
2027
- o = deref_tag(o, refname, 0);
2028
+ o = deref_tag(o, entry->name, 0);
2029
if (o)
2030
fprintf(cb->refs_file, "^%s\n",
2031
sha1_to_hex(o->sha1));
2032
}
2033
2033
- if ((cb->flags & PACK_REFS_PRUNE) && !do_not_prune(flags)) {
2034
- int namelen = strlen(refname) + 1;
2034
+ if ((cb->flags & PACK_REFS_PRUNE) && !do_not_prune(entry->flag)) {
2035
+ int namelen = strlen(entry->name) + 1;
2036
struct ref_to_prune *n = xcalloc(1, sizeof(*n) + namelen);
2036
- hashcpy(n->sha1, sha1);
2037
- strcpy(n->name, refname);
2037
+ hashcpy(n->sha1, entry->u.value.sha1);
2038
+ strcpy(n->name, entry->name);
2039
n->next = cb->ref_to_prune;
2040
cb->ref_to_prune = n;
2041
}
@@ -2111,7 +2112,7 @@ int pack_refs(unsigned int flags)
2112
/* perhaps other traits later as well */
2113
fprintf(cbdata.refs_file, "# pack-refs with: peeled fully-peeled \n");
2114
2114
- for_each_ref(pack_one_ref, &cbdata);
2115
+ do_for_each_entry(NULL, "", pack_one_ref, &cbdata);
2116
if (ferror(cbdata.refs_file))
2117
die("failed to write ref-pack file");
2118
if (fflush(cbdata.refs_file) || fsync(fd) || fclose(cbdata.refs_file))