Imported Upstream version 2.20.1
[platform/upstream/git.git] / server-info.c
index 75dd677..e2b2d6a 100644 (file)
@@ -1,8 +1,11 @@
 #include "cache.h"
+#include "repository.h"
 #include "refs.h"
 #include "object.h"
 #include "commit.h"
 #include "tag.h"
+#include "packfile.h"
+#include "object-store.h"
 
 /*
  * Create the file "path" by writing to a temporary file and renaming
@@ -14,19 +17,21 @@ static int update_info_file(char *path, int (*generate)(FILE *))
        char *tmp = mkpathdup("%s_XXXXXX", path);
        int ret = -1;
        int fd = -1;
-       FILE *fp = NULL;
+       FILE *fp = NULL, *to_close;
 
        safe_create_leading_directories(path);
        fd = git_mkstemp_mode(tmp, 0666);
        if (fd < 0)
                goto out;
-       fp = fdopen(fd, "w");
+       to_close = fp = fdopen(fd, "w");
        if (!fp)
                goto out;
+       fd = -1;
        ret = generate(fp);
        if (ret)
                goto out;
-       if (fclose(fp))
+       fp = NULL;
+       if (fclose(to_close))
                goto out;
        if (adjust_shared_perm(tmp) < 0)
                goto out;
@@ -51,7 +56,7 @@ static int add_info_ref(const char *path, const struct object_id *oid,
                        int flag, void *cb_data)
 {
        FILE *fp = cb_data;
-       struct object *o = parse_object(oid->hash);
+       struct object *o = parse_object(the_repository, oid);
        if (!o)
                return -1;
 
@@ -59,7 +64,7 @@ static int add_info_ref(const char *path, const struct object_id *oid,
                return -1;
 
        if (o->type == OBJ_TAG) {
-               o = deref_tag(o, path, 0);
+               o = deref_tag(the_repository, o, path, 0);
                if (o)
                        if (fprintf(fp, "%s     %s^{}\n",
                                oid_to_hex(&o->oid), path) < 0)
@@ -87,8 +92,6 @@ static struct pack_info {
        int old_num;
        int new_num;
        int nr_alloc;
-       int nr_heads;
-       unsigned char (*head)[20];
 } **info;
 static int num_pack;
 static const char *objdir;
@@ -131,7 +134,7 @@ static int read_pack_info_file(const char *infofile)
        char line[1000];
        int old_cnt = 0;
 
-       fp = fopen(infofile, "r");
+       fp = fopen_or_warn(infofile, "r");
        if (!fp)
                return 1; /* nonexistent is not an error. */
 
@@ -196,8 +199,7 @@ static void init_pack_info(const char *infofile, int force)
        objdir = get_object_directory();
        objdirlen = strlen(objdir);
 
-       prepare_packed_git();
-       for (p = packed_git; p; p = p->next) {
+       for (p = get_all_packs(the_repository); p; p = p->next) {
                /* we ignore things on alternate path since they are
                 * not available to the pullers in general.
                 */
@@ -207,7 +209,7 @@ static void init_pack_info(const char *infofile, int force)
        }
        num_pack = i;
        info = xcalloc(num_pack, sizeof(struct pack_info *));
-       for (i = 0, p = packed_git; p; p = p->next) {
+       for (i = 0, p = get_all_packs(the_repository); p; p = p->next) {
                if (!p->pack_local)
                        continue;
                info[i] = xcalloc(1, sizeof(struct pack_info));
@@ -221,15 +223,12 @@ static void init_pack_info(const char *infofile, int force)
        else
                stale = 1;
 
-       for (i = 0; i < num_pack; i++) {
-               if (stale) {
+       for (i = 0; i < num_pack; i++)
+               if (stale)
                        info[i]->old_num = -1;
-                       info[i]->nr_heads = 0;
-               }
-       }
 
        /* renumber them */
-       qsort(info, num_pack, sizeof(info[0]), compare_info);
+       QSORT(info, num_pack, compare_info);
        for (i = 0; i < num_pack; i++)
                info[i]->new_num = i;
 }