X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=server-info.c;h=e4006f0b5bc14f39d28ac98120b2fcccec34de8d;hb=1b1e59c5084ac8b0af0aa443bb1713179d400211;hp=2b3aecab4aa0df4125f401219f06ea04577cacca;hpb=51017101c7a308745ba3c04944457f1dc6a55780;p=git.git diff --git a/server-info.c b/server-info.c index 2b3aecab..e4006f0b 100644 --- a/server-info.c +++ b/server-info.c @@ -3,30 +3,26 @@ #include "object.h" #include "commit.h" #include "tag.h" -#include "rev-cache.h" /* refs */ static FILE *info_ref_fp; -static unsigned long info_ref_time; -static int info_ref_is_stale = 0; - -static int stat_ref(const char *path, const unsigned char *sha1) -{ - struct stat st; - if (!stat(path, &st) && info_ref_time < st.st_mtime) - info_ref_is_stale = 1; - return 0; -} static int add_info_ref(const char *path, const unsigned char *sha1) { + struct object *o = parse_object(sha1); + fprintf(info_ref_fp, "%s %s\n", sha1_to_hex(sha1), path); + if (o->type == tag_type) { + o = deref_tag(o, path, 0); + if (o) + fprintf(info_ref_fp, "%s %s^{}\n", + sha1_to_hex(o->sha1), path); + } return 0; } static int update_info_refs(int force) { - struct stat st; char *path0 = strdup(git_path("info/refs")); int len = strlen(path0); char *path1 = xmalloc(len + 2); @@ -34,21 +30,6 @@ static int update_info_refs(int force) strcpy(path1, path0); strcpy(path1 + len, "+"); - if (!force) { - if (stat(path0, &st)) { - if (errno == ENOENT) - info_ref_is_stale = 1; - else - return error("cannot stat %s", path0); - } - else { - info_ref_time = st.st_mtime; - for_each_ref(stat_ref); - } - if (!info_ref_is_stale) - return 0; - } - safe_create_leading_directories(path0); info_ref_fp = fopen(path1, "w"); if (!info_ref_fp) @@ -86,6 +67,16 @@ static struct object *parse_object_cheap(const unsigned char *sha1) struct commit *commit = (struct commit *)o; free(commit->buffer); commit->buffer = NULL; + } else if (o->type == tree_type) { + struct tree *tree = (struct tree *)o; + struct tree_entry_list *e, *n; + for (e = tree->entries; e; e = n) { + free(e->name); + e->name = NULL; + n = e->next; + free(e); + } + tree->entries = NULL; } return o; } @@ -433,7 +424,6 @@ static void find_pack_info_one(int pack_ix) { unsigned char sha1[20]; struct object *o; - struct object_list *ref; int i; struct packed_git *p = info[pack_ix]->p; int num = num_packed_objects(p); @@ -446,8 +436,12 @@ static void find_pack_info_one(int pack_ix) die("corrupt pack file %s?", p->pack_name); if ((o = lookup_object(sha1)) == NULL) die("cannot parse %s", sha1_to_hex(sha1)); - for (ref = o->refs; ref; ref = ref->next) - ref->item->flags = 0; + if (o->refs) { + struct object_refs *refs = o->refs; + int j; + for (j = 0; j < refs->count; j++) + refs->ref[j]->flags = 0; + } o->flags = 0; } @@ -457,8 +451,12 @@ static void find_pack_info_one(int pack_ix) die("corrupt pack file %s?", p->pack_name); if ((o = lookup_object(sha1)) == NULL) die("cannot find %s", sha1_to_hex(sha1)); - for (ref = o->refs; ref; ref = ref->next) - ref->item->flags |= REFERENCED; + if (o->refs) { + struct object_refs *refs = o->refs; + int j; + for (j = 0; j < refs->count; j++) + refs->ref[j]->flags |= REFERENCED; + } o->flags |= INTERNAL; } @@ -469,8 +467,12 @@ static void find_pack_info_one(int pack_ix) die("cannot find %s", sha1_to_hex(sha1)); show(o, pack_ix); - for (ref = o->refs; ref; ref = ref->next) - show(ref->item, pack_ix); + if (o->refs) { + struct object_refs *refs = o->refs; + int j; + for (j = 0; j < refs->count; j++) + show(refs->ref[j], pack_ix); + } } } @@ -516,45 +518,6 @@ static int update_info_packs(int force) return 0; } -/* rev-cache */ -static int record_rev_cache_ref(const char *path, const unsigned char *sha1) -{ - struct object *obj = parse_object(sha1); - - if (!obj) - return error("ref %s has bad sha %s", path, sha1_to_hex(sha1)); - while (obj && obj->type == tag_type) - obj = parse_object(((struct tag *)obj)->tagged->sha1); - if (!obj || obj->type != commit_type) - /* tag pointing at a non-commit */ - return 0; - return record_rev_cache(obj->sha1, NULL); -} - -static int update_info_revs(int force) -{ - char *path0 = strdup(git_path("info/rev-cache")); - int len = strlen(path0); - char *path1 = xmalloc(len + 2); - - strcpy(path1, path0); - strcpy(path1 + len, "+"); - - /* read existing rev-cache */ - if (!force) - read_rev_cache(path0, NULL, 0); - safe_create_leading_directories(path0); - - for_each_ref(record_rev_cache_ref); - - /* update the rev-cache database */ - write_rev_cache(path1, force ? "/dev/null" : path0); - rename(path1, path0); - free(path1); - free(path0); - return 0; -} - /* public */ int update_server_info(int force) { @@ -566,7 +529,6 @@ int update_server_info(int force) errs = errs | update_info_refs(force); errs = errs | update_info_packs(force); - errs = errs | update_info_revs(force); return errs; }