442
read_info_alternates(get_object_directory(), 0);
443
}
444
445
-static int has_loose_object_local(const unsigned char *sha1)
445
+static int freshen_file(const char *fn)
446
{
447
- return !access(sha1_file_name(sha1), F_OK);
447
+ struct utimbuf t;
448
+ t.actime = t.modtime = time(NULL);
449
+ return !utime(fn, &t);
450
}
451
450
-int has_loose_object_nonlocal(const unsigned char *sha1)
452
+static int check_and_freshen_file(const char *fn, int freshen)
453
+{
454
+ if (access(fn, F_OK))
455
+ return 0;
456
+ if (freshen && freshen_file(fn))
457
+ return 0;
458
+ return 1;
459
+}
460
+
461
+static int check_and_freshen_local(const unsigned char *sha1, int freshen)
462
+{
463
+ return check_and_freshen_file(sha1_file_name(sha1), freshen);
464
+}
465
+
466
+static int check_and_freshen_nonlocal(const unsigned char *sha1, int freshen)
467
{
468
struct alternate_object_database *alt;
469
prepare_alt_odb();
470
for (alt = alt_odb_list; alt; alt = alt->next) {
471
fill_sha1_path(alt->name, sha1);
456
- if (!access(alt->base, F_OK))
472
+ if (check_and_freshen_file(alt->base, freshen))
473
return 1;
474
}
475
return 0;
476
}
477
478
+static int check_and_freshen(const unsigned char *sha1, int freshen)
479
+{
480
+ return check_and_freshen_local(sha1, freshen) ||
481
+ check_and_freshen_nonlocal(sha1, freshen);
482
+}
483
+
484
+int has_loose_object_nonlocal(const unsigned char *sha1)
485
+{
486
+ return check_and_freshen_nonlocal(sha1, 0);
487
+}
488
+
489
static int has_loose_object(const unsigned char *sha1)
490
{
464
- return has_loose_object_local(sha1) ||
465
- has_loose_object_nonlocal(sha1);
491
+ return check_and_freshen(sha1, 0);
492
}
493
494
static unsigned int pack_used_ctr;
2991
return move_temp_to_file(tmp_file, filename);
2992
}
2993
2994
+static int freshen_loose_object(const unsigned char *sha1)
2995
+{
2996
+ return check_and_freshen(sha1, 1);
2997
+}
2998
+
2999
+static int freshen_packed_object(const unsigned char *sha1)
3000
+{
3001
+ struct pack_entry e;
3002
+ return find_pack_entry(sha1, &e) && freshen_file(e.p->pack_name);
3003
+}
3004
+
3005
int write_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *returnsha1)
3006
{
3007
unsigned char sha1[20];
3014
write_sha1_file_prepare(buf, len, type, sha1, hdr, &hdrlen);
3015
if (returnsha1)
3016
hashcpy(returnsha1, sha1);
2980
- if (has_sha1_file(sha1))
3017
+ if (freshen_loose_object(sha1) || freshen_packed_object(sha1))
3018
return 0;
3019
return write_loose_object(sha1, hdr, hdrlen, buf, len, 0);
3020
}