summaryrefslogtreecommitdiff
path: root/refs.c
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2013-04-22 19:52:35 (GMT)
committerJunio C Hamano <gitster@pobox.com>2013-05-01 22:33:11 (GMT)
commit12e77559ec4bf863d3703a25ab79298d5ff89b3b (patch)
tree1652cf0835074da6b0693451c73123a043321c3a /refs.c
parentd9470330379f5899dd117b7c720e67d278fed9e2 (diff)
downloadgit-12e77559ec4bf863d3703a25ab79298d5ff89b3b.zip
git-12e77559ec4bf863d3703a25ab79298d5ff89b3b.tar.gz
git-12e77559ec4bf863d3703a25ab79298d5ff89b3b.tar.bz2
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>
Diffstat (limited to 'refs.c')
-rw-r--r--refs.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/refs.c b/refs.c
index 9b392bd..3465db6 100644
--- a/refs.c
+++ b/refs.c
@@ -2004,37 +2004,38 @@ static int do_not_prune(int flags)
return (flags & (REF_ISSYMREF|REF_ISPACKED));
}
-static int pack_one_ref(const char *refname, const unsigned char *sha1,
- int flags, void *cb_data)
+static int pack_one_ref(struct ref_entry *entry, void *cb_data)
{
struct pack_refs_cb_data *cb = cb_data;
struct object *o;
int is_tag_ref;
- /* Do not pack the symbolic refs */
- if ((flags & REF_ISSYMREF))
+ /* Do not pack symbolic or broken refs: */
+ if ((entry->flag & REF_ISSYMREF) || !ref_resolves_to_object(entry))
return 0;
- is_tag_ref = !prefixcmp(refname, "refs/tags/");
+ is_tag_ref = !prefixcmp(entry->name, "refs/tags/");
/* ALWAYS pack refs that were already packed or are tags */
- if (!(cb->flags & PACK_REFS_ALL) && !is_tag_ref && !(flags & REF_ISPACKED))
+ if (!(cb->flags & PACK_REFS_ALL) && !is_tag_ref &&
+ !(entry->flag & REF_ISPACKED))
return 0;
- fprintf(cb->refs_file, "%s %s\n", sha1_to_hex(sha1), refname);
+ fprintf(cb->refs_file, "%s %s\n", sha1_to_hex(entry->u.value.sha1),
+ entry->name);
- o = parse_object_or_die(sha1, refname);
+ o = parse_object_or_die(entry->u.value.sha1, entry->name);
if (o->type == OBJ_TAG) {
- o = deref_tag(o, refname, 0);
+ o = deref_tag(o, entry->name, 0);
if (o)
fprintf(cb->refs_file, "^%s\n",
sha1_to_hex(o->sha1));
}
- if ((cb->flags & PACK_REFS_PRUNE) && !do_not_prune(flags)) {
- int namelen = strlen(refname) + 1;
+ if ((cb->flags & PACK_REFS_PRUNE) && !do_not_prune(entry->flag)) {
+ int namelen = strlen(entry->name) + 1;
struct ref_to_prune *n = xcalloc(1, sizeof(*n) + namelen);
- hashcpy(n->sha1, sha1);
- strcpy(n->name, refname);
+ hashcpy(n->sha1, entry->u.value.sha1);
+ strcpy(n->name, entry->name);
n->next = cb->ref_to_prune;
cb->ref_to_prune = n;
}
@@ -2111,7 +2112,7 @@ int pack_refs(unsigned int flags)
/* perhaps other traits later as well */
fprintf(cbdata.refs_file, "# pack-refs with: peeled fully-peeled \n");
- for_each_ref(pack_one_ref, &cbdata);
+ do_for_each_entry(NULL, "", pack_one_ref, &cbdata);
if (ferror(cbdata.refs_file))
die("failed to write ref-pack file");
if (fflush(cbdata.refs_file) || fsync(fd) || fclose(cbdata.refs_file))