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>
This commit is contained in:
Michael Haggerty 2013-04-22 21:52:35 +02:00 committed by Junio C Hamano
parent d947033037
commit 12e77559ec

29
refs.c
View File

@ -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))