提交 12e77559 编写于 作者: M Michael Haggerty 提交者: Junio C Hamano

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: NMichael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 d9470330
...@@ -2004,37 +2004,38 @@ static int do_not_prune(int flags) ...@@ -2004,37 +2004,38 @@ static int do_not_prune(int flags)
return (flags & (REF_ISSYMREF|REF_ISPACKED)); return (flags & (REF_ISSYMREF|REF_ISPACKED));
} }
static int pack_one_ref(const char *refname, const unsigned char *sha1, static int pack_one_ref(struct ref_entry *entry, void *cb_data)
int flags, void *cb_data)
{ {
struct pack_refs_cb_data *cb = cb_data; struct pack_refs_cb_data *cb = cb_data;
struct object *o; struct object *o;
int is_tag_ref; int is_tag_ref;
/* Do not pack the symbolic refs */ /* Do not pack symbolic or broken refs: */
if ((flags & REF_ISSYMREF)) if ((entry->flag & REF_ISSYMREF) || !ref_resolves_to_object(entry))
return 0; 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 */ /* 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; 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) { if (o->type == OBJ_TAG) {
o = deref_tag(o, refname, 0); o = deref_tag(o, entry->name, 0);
if (o) if (o)
fprintf(cb->refs_file, "^%s\n", fprintf(cb->refs_file, "^%s\n",
sha1_to_hex(o->sha1)); sha1_to_hex(o->sha1));
} }
if ((cb->flags & PACK_REFS_PRUNE) && !do_not_prune(flags)) { if ((cb->flags & PACK_REFS_PRUNE) && !do_not_prune(entry->flag)) {
int namelen = strlen(refname) + 1; int namelen = strlen(entry->name) + 1;
struct ref_to_prune *n = xcalloc(1, sizeof(*n) + namelen); struct ref_to_prune *n = xcalloc(1, sizeof(*n) + namelen);
hashcpy(n->sha1, sha1); hashcpy(n->sha1, entry->u.value.sha1);
strcpy(n->name, refname); strcpy(n->name, entry->name);
n->next = cb->ref_to_prune; n->next = cb->ref_to_prune;
cb->ref_to_prune = n; cb->ref_to_prune = n;
} }
...@@ -2111,7 +2112,7 @@ int pack_refs(unsigned int flags) ...@@ -2111,7 +2112,7 @@ int pack_refs(unsigned int flags)
/* perhaps other traits later as well */ /* perhaps other traits later as well */
fprintf(cbdata.refs_file, "# pack-refs with: peeled fully-peeled \n"); 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)) if (ferror(cbdata.refs_file))
die("failed to write ref-pack file"); die("failed to write ref-pack file");
if (fflush(cbdata.refs_file) || fsync(fd) || fclose(cbdata.refs_file)) if (fflush(cbdata.refs_file) || fsync(fd) || fclose(cbdata.refs_file))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册