builtin/show-ref: rewrite to use object_id
[gitweb.git] / server-info.c
index d54a3d624c488aaf65bc5b46f509c2481fe73103..317dda87bf77bcd5766175b2e30ad24b41208abf 100644 (file)
@@ -17,7 +17,7 @@ static int update_info_file(char *path, int (*generate)(FILE *))
        FILE *fp = NULL;
 
        safe_create_leading_directories(path);
-       fd = mkstemp(tmp);
+       fd = git_mkstemp_mode(tmp, 0666);
        if (fd < 0)
                goto out;
        fp = fdopen(fd, "w");
@@ -69,7 +69,10 @@ static int add_info_ref(const char *path, const unsigned char *sha1, int flag, v
 
 static int generate_info_refs(FILE *fp)
 {
-       return for_each_ref(add_info_ref, fp);
+       struct each_ref_fn_sha1_adapter wrapped_add_info_ref =
+               {add_info_ref, fp};
+
+       return for_each_ref(each_ref_fn_adapter, &wrapped_add_info_ref);
 }
 
 static int update_info_refs(int force)
@@ -233,6 +236,14 @@ static void init_pack_info(const char *infofile, int force)
                info[i]->new_num = i;
 }
 
+static void free_pack_info(void)
+{
+       int i;
+       for (i = 0; i < num_pack; i++)
+               free(info[i]);
+       free(info);
+}
+
 static int write_pack_info_file(FILE *fp)
 {
        int i;
@@ -252,6 +263,7 @@ static int update_info_packs(int force)
 
        init_pack_info(infofile, force);
        ret = update_info_file(infofile, write_pack_info_file);
+       free_pack_info();
        free(infofile);
        return ret;
 }