X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=builtin-pack-refs.c;h=8dc5b9efffc3ad2cd56130155a94aa489d0d0b1b;hb=9d0524d42f340fc49f9e175d966afb7dce3854bb;hp=1087657674840820662cba686f525a69a68e689c;hpb=e0d68cd5d95fc15342db38c211f71efe5bcfbe94;p=git.git diff --git a/builtin-pack-refs.c b/builtin-pack-refs.c index 108765767..8dc5b9eff 100644 --- a/builtin-pack-refs.c +++ b/builtin-pack-refs.c @@ -1,5 +1,7 @@ #include "cache.h" #include "refs.h" +#include "object.h" +#include "tag.h" static const char builtin_pack_refs_usage[] = "git-pack-refs [--all] [--prune]"; @@ -12,6 +14,7 @@ struct ref_to_prune { struct pack_refs_cb_data { int prune; + int all; struct ref_to_prune *ref_to_prune; FILE *refs_file; }; @@ -28,10 +31,26 @@ static int handle_one_ref(const char *path, const unsigned char *sha1, int flags, void *cb_data) { struct pack_refs_cb_data *cb = cb_data; + int is_tag_ref; /* Do not pack the symbolic refs */ - if (!(flags & REF_ISSYMREF)) - fprintf(cb->refs_file, "%s %s\n", sha1_to_hex(sha1), path); + if ((flags & REF_ISSYMREF)) + return 0; + is_tag_ref = !strncmp(path, "refs/tags/", 10); + if (!cb->all && !is_tag_ref) + return 0; + + fprintf(cb->refs_file, "%s %s\n", sha1_to_hex(sha1), path); + if (is_tag_ref) { + struct object *o = parse_object(sha1); + if (o->type == OBJ_TAG) { + o = deref_tag(o, path, 0); + if (o) + fprintf(cb->refs_file, "^%s\n", + sha1_to_hex(o->sha1)); + } + } + if (cb->prune && !do_not_prune(flags)) { int namelen = strlen(path) + 1; struct ref_to_prune *n = xcalloc(1, sizeof(*n) + namelen); @@ -68,7 +87,6 @@ int cmd_pack_refs(int argc, const char **argv, const char *prefix) { int fd, i; struct pack_refs_cb_data cbdata; - int (*iterate_ref)(each_ref_fn, void *) = for_each_tag_ref; memset(&cbdata, 0, sizeof(cbdata)); @@ -79,7 +97,7 @@ int cmd_pack_refs(int argc, const char **argv, const char *prefix) continue; } if (!strcmp(arg, "--all")) { - iterate_ref = for_each_ref; + cbdata.all = 1; continue; } /* perhaps other parameters later... */ @@ -93,7 +111,11 @@ int cmd_pack_refs(int argc, const char **argv, const char *prefix) if (!cbdata.refs_file) die("unable to create ref-pack file structure (%s)", strerror(errno)); - iterate_ref(handle_one_ref, &cbdata); + + /* perhaps other traits later as well */ + fprintf(cbdata.refs_file, "# pack-refs with: peeled \n"); + + for_each_ref(handle_one_ref, &cbdata); fflush(cbdata.refs_file); fsync(fd); fclose(cbdata.refs_file);