Merge fixes up to GIT 1.0.4
[gitweb.git] / server-info.c
index 7b214c8138afa7ff8f3a274235c6be5dac32ef07..05bce7da3b4935675465f993c24bb1188439d6d9 100644 (file)
@@ -55,30 +55,6 @@ static int num_pack;
 static const char *objdir;
 static int objdirlen;
 
-static struct object *parse_object_cheap(const unsigned char *sha1)
-{
-       struct object *o;
-
-       if ((o = parse_object(sha1)) == NULL)
-               return NULL;
-       if (o->type == commit_type) {
-               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;
-}
-
 static struct pack_info *find_pack_by_name(const char *name)
 {
        int i;
@@ -91,15 +67,6 @@ static struct pack_info *find_pack_by_name(const char *name)
        return NULL;
 }
 
-static struct pack_info *find_pack_by_old_num(int old_num)
-{
-       int i;
-       for (i = 0; i < num_pack; i++)
-               if (info[i]->old_num == old_num)
-                       return info[i];
-       return NULL;
-}
-
 /* Returns non-zero when we detect that the info in the
  * old file is useless.
  */
@@ -132,7 +99,10 @@ static int read_pack_info_file(const char *infofile)
        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 */
@@ -173,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)
@@ -228,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)