/* 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);
+ if (!o)
+ return -1;
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",
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);
safe_create_leading_directories(path0);
info_ref_fp = fopen(path1, "w");
if (!info_ref_fp)
- return error("unable to update %s", path0);
- for_each_ref(add_info_ref);
+ return error("unable to update %s", path1);
+ for_each_ref(add_info_ref, NULL);
fclose(info_ref_fp);
+ adjust_shared_perm(path1);
rename(path1, path0);
free(path0);
free(path1);
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;
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.
*/
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;
+ if (len && line[len-1] == '\n')
+ line[--len] = 0;
+
+ if (!len)
+ continue;
switch (line[0]) {
case 'P': /* P name */
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)
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)
return error("cannot open %s", name);
write_pack_info_file(fp);
fclose(fp);
+ adjust_shared_perm(name);
rename(name, infofile);
return 0;
}