Code

Remove hash in git-describe in favor of util slot.
[git.git] / server-info.c
index 7d7bcb2188e8f4a65f83a4693220864d0a255951..6cd38be3291e95e75a7d2348e825d49c8f7ad2af 100644 (file)
@@ -7,12 +7,12 @@
 /* refs */
 static FILE *info_ref_fp;
 
-static int add_info_ref(const char *path, const unsigned char *sha1)
+static int add_info_ref(const char *path, const unsigned char *sha1, int flag, void *cb_data)
 {
        struct object *o = parse_object(sha1);
 
        fprintf(info_ref_fp, "%s        %s\n", sha1_to_hex(sha1), path);
-       if (o->type == tag_type) {
+       if (o->type == OBJ_TAG) {
                o = deref_tag(o, path, 0);
                if (o)
                        fprintf(info_ref_fp, "%s        %s^{}\n",
@@ -23,7 +23,7 @@ static int add_info_ref(const char *path, const unsigned char *sha1)
 
 static int update_info_refs(int force)
 {
-       char *path0 = strdup(git_path("info/refs"));
+       char *path0 = xstrdup(git_path("info/refs"));
        int len = strlen(path0);
        char *path1 = xmalloc(len + 2);
 
@@ -34,7 +34,7 @@ static int update_info_refs(int force)
        info_ref_fp = fopen(path1, "w");
        if (!info_ref_fp)
                return error("unable to update %s", path0);
-       for_each_ref(add_info_ref);
+       for_each_ref(add_info_ref, NULL);
        fclose(info_ref_fp);
        rename(path1, path0);
        free(path0);
@@ -94,12 +94,15 @@ static int read_pack_info_file(const char *infofile)
 
        fp = fopen(infofile, "r");
        if (!fp)
-               return 1; /* nonexisting is not an error. */
+               return 1; /* nonexistent is not an error. */
 
        while (fgets(line, sizeof(line), fp)) {
                int len = strlen(line);
                if (line[len-1] == '\n')
-                       line[len-1] = 0;
+                       line[--len] = 0;
+
+               if (!len)
+                       continue;
 
                switch (line[0]) {
                case 'P': /* P name */
@@ -140,7 +143,12 @@ static int compare_info(const void *a_, const void *b_)
                return 1;
 
        /* then it does not matter but at least keep the comparison stable */
-       return (*a)->p - (*b)->p;
+       if ((*a)->p == (*b)->p)
+               return 0;
+       else if ((*a)->p < (*b)->p)
+               return -1;
+       else
+               return 1;
 }
 
 static void init_pack_info(const char *infofile, int force)
@@ -195,6 +203,7 @@ static void write_pack_info_file(FILE *fp)
        int i;
        for (i = 0; i < num_pack; i++)
                fprintf(fp, "P %s\n", info[i]->p->pack_name + objdirlen + 6);
+       fputc('\n', fp);
 }
 
 static int update_info_packs(int force)