!has_sha1_pack_kept_or_nonlocal(&oid) &&
!loosened_object_can_be_discarded(&oid, p->mtime)) {
if (force_object_loose(the_repository->objects->sources,
- &oid, p->mtime))
+ &oid, &p->mtime))
die(_("unable to force loose object"));
loosened_objects_nr++;
}
}
/* Returns 1 if we have successfully freshened the file, 0 otherwise. */
-static int freshen_file(const char *fn)
+static int freshen_file(const char *fn, const time_t *mtime)
{
- return !utime(fn, NULL);
+ struct utimbuf times, *timesp = NULL;
+
+ if (mtime) {
+ times.actime = *mtime;
+ times.modtime = *mtime;
+ timesp = ×
+ }
+
+ return !utime(fn, timesp);
}
/*
* either does not exist on disk, or has a stale mtime and may be subject to
* pruning).
*/
-int check_and_freshen_file(const char *fn, int freshen)
+int check_and_freshen_file(const char *fn, int freshen,
+ const time_t *mtime)
{
if (access(fn, F_OK))
return 0;
- if (freshen && !freshen_file(fn))
+ if (freshen && !freshen_file(fn, mtime))
return 0;
return 1;
}
int write_loose_object(struct odb_source_loose *loose,
const struct object_id *oid, char *hdr,
int hdrlen, const void *buf, unsigned long len,
- time_t mtime, unsigned flags)
+ const time_t *mtime, unsigned flags)
{
int fd, ret;
unsigned char compressed[4096];
close_loose_object(loose, fd, tmp_file.buf);
if (mtime) {
- struct utimbuf utb;
- utb.actime = mtime;
- utb.modtime = mtime;
+ struct utimbuf utb = {
+ .actime = *mtime,
+ .modtime = *mtime,
+ };
+
if (utime(tmp_file.buf, &utb) < 0 &&
!(flags & ODB_WRITE_OBJECT_SILENT))
warning_errno(_("failed utime() on %s"), tmp_file.buf);
}
int force_object_loose(struct odb_source *source,
- const struct object_id *oid, time_t mtime)
+ const struct object_id *oid, const time_t *mtime)
{
struct odb_source_files *files = odb_source_files_downcast(source);
const struct git_hash_algo *compat = source->odb->repo->compat_hash_algo;
size_t objsize);
int force_object_loose(struct odb_source *source,
- const struct object_id *oid, time_t mtime);
+ const struct object_id *oid,
+ const time_t *mtime);
/**
* With in-core object data in "buf", rehash it to make sure the
int write_loose_object(struct odb_source_loose *loose,
const struct object_id *oid, char *hdr,
int hdrlen, const void *buf, unsigned long len,
- time_t mtime, unsigned flags);
+ const time_t *mtime, unsigned flags);
/* Helper to check and "touch" a file */
-int check_and_freshen_file(const char *fn, int freshen);
+int check_and_freshen_file(const char *fn, int freshen,
+ const time_t *mtime);
/*
* Open the loose object at path, check its hash, and return the contents,
return 0;
return odb_source_write_object(odb->inmemory_objects,
- buf, len, type, oid, NULL, 0);
+ buf, len, type, oid, NULL, NULL, 0);
}
void *odb_read_object(struct object_database *odb,
struct odb_source *source;
odb_prepare_alternates(odb);
for (source = odb->sources; source; source = source->next)
- if (odb_source_freshen_object(source, oid))
+ if (odb_source_freshen_object(source, oid, NULL))
return 1;
return 0;
}
}
return odb_source_write_object(odb->sources, buf, len, type,
- oid, compat_oid_p, flags);
+ oid, compat_oid_p, NULL, flags);
}
int odb_write_object_stream(struct object_database *odb,
}
static int odb_source_files_freshen_object(struct odb_source *source,
- const struct object_id *oid)
+ const struct object_id *oid,
+ const time_t *mtime)
{
struct odb_source_files *files = odb_source_files_downcast(source);
- if (odb_source_freshen_object(&files->packed->base, oid) ||
- odb_source_freshen_object(&files->loose->base, oid))
+ if (odb_source_freshen_object(&files->packed->base, oid, mtime) ||
+ odb_source_freshen_object(&files->loose->base, oid, mtime))
return 1;
return 0;
}
enum object_type type,
const struct object_id *oid,
const struct object_id *compat_oid,
+ const time_t *mtime,
enum odb_write_object_flags flags)
{
struct odb_source_files *files = odb_source_files_downcast(source);
return odb_source_write_object(&files->loose->base, buf, len, type,
- oid, compat_oid, flags);
+ oid, compat_oid, mtime, flags);
}
static int odb_source_files_write_object_stream(struct odb_source *source,
enum object_type type,
const struct object_id *oid,
const struct object_id *compat_oid UNUSED,
+ const time_t *mtime UNUSED,
enum odb_write_object_flags flags UNUSED)
{
struct odb_source_inmemory *inmemory = odb_source_inmemory_downcast(source);
hash_object_file(source->odb->repo->hash_algo, data, total_read, OBJ_BLOB, oid);
ret = odb_source_inmemory_write_object(source, data, len, OBJ_BLOB, oid,
- NULL, 0);
+ NULL, NULL, 0);
if (ret < 0)
goto out;
}
static int odb_source_inmemory_freshen_object(struct odb_source *source,
- const struct object_id *oid)
+ const struct object_id *oid,
+ const time_t *mtime UNUSED)
{
struct odb_source_inmemory *inmemory = odb_source_inmemory_downcast(source);
if (find_cached_object(inmemory, oid))
}
static int odb_source_loose_freshen_object(struct odb_source *source,
- const struct object_id *oid)
+ const struct object_id *oid,
+ const time_t *mtime)
{
struct odb_source_loose *loose = odb_source_loose_downcast(source);
static struct strbuf path = STRBUF_INIT;
odb_loose_path(loose, &path, oid);
- return !!check_and_freshen_file(path.buf, 1);
+ return !!check_and_freshen_file(path.buf, 1, mtime);
}
static int odb_source_loose_write_object(struct odb_source *source,
enum object_type type,
const struct object_id *oid,
const struct object_id *compat_oid,
+ const time_t *mtime,
enum odb_write_object_flags flags)
{
struct odb_source_loose *loose = odb_source_loose_downcast(source);
hdrlen = format_object_header(hdr, sizeof(hdr), type, len);
- if (write_loose_object(loose, oid, hdr, hdrlen, buf, len, 0, flags))
+ if (write_loose_object(loose, oid, hdr, hdrlen, buf, len, mtime, flags))
return -1;
if (compat_oid)
}
static int odb_source_packed_freshen_object(struct odb_source *source,
- const struct object_id *oid)
+ const struct object_id *oid,
+ const time_t *mtime)
{
struct odb_source_packed *packed = odb_source_packed_downcast(source);
+ struct utimbuf times, *timesp = NULL;
struct pack_entry e;
+ if (mtime) {
+ times.actime = *mtime;
+ times.modtime = *mtime;
+ timesp = ×
+ }
+
if (!find_pack_entry(packed, oid, &e))
return 0;
if (e.p->is_cruft)
return 0;
if (e.p->freshened)
return 1;
- if (utime(e.p->pack_name, NULL))
+ if (utime(e.p->pack_name, timesp))
return 0;
e.p->freshened = 1;
enum object_type type UNUSED,
const struct object_id *oid UNUSED,
const struct object_id *compat_oid UNUSED,
+ const time_t *mtime UNUSED,
unsigned flags UNUSED)
{
return error("packed backend cannot write objects");
* has been freshened.
*/
int (*freshen_object)(struct odb_source *source,
- const struct object_id *oid);
+ const struct object_id *oid,
+ const time_t *mtime);
/*
* This callback is expected to persist the given object into the
enum object_type type,
const struct object_id *oid,
const struct object_id *compat_oid,
+ const time_t *mtime,
enum odb_write_object_flags flags);
/*
* not exist.
*/
static inline int odb_source_freshen_object(struct odb_source *source,
- const struct object_id *oid)
+ const struct object_id *oid,
+ const time_t *mtime)
{
- return source->freshen_object(source, oid);
+ return source->freshen_object(source, oid, mtime);
}
/*
enum object_type type,
const struct object_id *oid,
const struct object_id *compat_oid,
+ const time_t *mtime,
enum odb_write_object_flags flags)
{
return source->write_object(source, buf, len, type, oid,
- compat_oid, flags);
+ compat_oid, mtime, flags);
}
/*
*/
static void freshen_shared_index(const char *shared_index, int warn)
{
- if (!check_and_freshen_file(shared_index, 1) && warn)
+ if (!check_and_freshen_file(shared_index, 1, NULL) && warn)
warning(_("could not freshen shared index '%s'"), shared_index);
}
size_t content_len = strlen(content);
hash_object_file(repo.hash_algo, content, content_len, type, oid);
cl_must_pass(odb_source_write_object(&source->base, content, content_len,
- type, oid, NULL, 0));
+ type, oid, NULL, NULL, 0));
}
void test_odb_inmemory__initialize(void)
const char *end;
cl_must_pass(parse_oid_hex_algop(RANDOM_OID, &oid, &end, repo.hash_algo));
- cl_assert_equal_i(odb_source_freshen_object(&source->base, &oid), 0);
+ cl_assert_equal_i(odb_source_freshen_object(&source->base, &oid, NULL), 0);
cl_assert_write_object(source, "foobar", OBJ_BLOB, &written_oid);
cl_assert_equal_i(odb_source_freshen_object(&source->base,
- &written_oid), 1);
+ &written_oid, NULL), 1);
odb_source_free(&source->base);
}