Merge branch 'sr/gpg-interface-stop-at-the-end' into maint
[gitweb.git] / server-info.c
index c9fbfd3a510959b5feaf9c39dc8c23e260245cfe..92187c70db650ee0e4d5ea4bf3435e84a51c44b2 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "dir.h"
 #include "repository.h"
 #include "refs.h"
 #include "object.h"
@@ -78,7 +79,7 @@ static int generate_info_refs(FILE *fp)
        return for_each_ref(add_info_ref, fp);
 }
 
-static int update_info_refs(int force)
+static int update_info_refs(void)
 {
        char *path = git_pathdup("info/refs");
        int ret = update_info_file(path, generate_info_refs);
@@ -93,16 +94,13 @@ static struct pack_info {
        int new_num;
 } **info;
 static int num_pack;
-static const char *objdir;
-static int objdirlen;
 
 static struct pack_info *find_pack_by_name(const char *name)
 {
        int i;
        for (i = 0; i < num_pack; i++) {
                struct packed_git *p = info[i]->p;
-               /* skip "/pack/" after ".git/objects" */
-               if (!strcmp(p->pack_name + objdirlen + 6, name))
+               if (!strcmp(pack_basename(p), name))
                        return info[i];
        }
        return NULL;
@@ -194,29 +192,21 @@ static void init_pack_info(const char *infofile, int force)
 {
        struct packed_git *p;
        int stale;
-       int i = 0;
-
-       objdir = get_object_directory();
-       objdirlen = strlen(objdir);
+       int i;
+       size_t alloc = 0;
 
        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.
                 */
-               if (!p->pack_local)
+               if (!p->pack_local || !file_exists(p->pack_name))
                        continue;
-               i++;
-       }
-       num_pack = i;
-       info = xcalloc(num_pack, sizeof(struct pack_info *));
-       for (i = 0, p = get_all_packs(the_repository); p; p = p->next) {
-               if (!p->pack_local)
-                       continue;
-               assert(i < num_pack);
+
+               i = num_pack++;
+               ALLOC_GROW(info, num_pack, alloc);
                info[i] = xcalloc(1, sizeof(struct pack_info));
                info[i]->p = p;
                info[i]->old_num = -1;
-               i++;
        }
 
        if (infofile && !force)
@@ -246,7 +236,7 @@ static int write_pack_info_file(FILE *fp)
 {
        int i;
        for (i = 0; i < num_pack; i++) {
-               if (fprintf(fp, "P %s\n", info[i]->p->pack_name + objdirlen + 6) < 0)
+               if (fprintf(fp, "P %s\n", pack_basename(info[i]->p)) < 0)
                        return -1;
        }
        if (fputc('\n', fp) == EOF)
@@ -275,7 +265,7 @@ int update_server_info(int force)
         */
        int errs = 0;
 
-       errs = errs | update_info_refs(force);
+       errs = errs | update_info_refs();
        errs = errs | update_info_packs(force);
 
        /* remove leftover rev-cache file if there is any */