sha1-file: convert freshen functions to object_id
Convert the various functions for freshening objects and has_loose_object_nonlocal to use struct object_id. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
14c3c80c81
commit
6862ebbfcb
@ -1012,7 +1012,7 @@ static int want_object_in_pack(const struct object_id *oid,
|
|||||||
int want;
|
int want;
|
||||||
struct list_head *pos;
|
struct list_head *pos;
|
||||||
|
|
||||||
if (!exclude && local && has_loose_object_nonlocal(oid->hash))
|
if (!exclude && local && has_loose_object_nonlocal(oid))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
2
cache.h
2
cache.h
@ -1275,7 +1275,7 @@ extern int has_object_file_with_flags(const struct object_id *oid, int flags);
|
|||||||
* with the specified name. This function does not respect replace
|
* with the specified name. This function does not respect replace
|
||||||
* references.
|
* references.
|
||||||
*/
|
*/
|
||||||
extern int has_loose_object_nonlocal(const unsigned char *sha1);
|
extern int has_loose_object_nonlocal(const struct object_id *oid);
|
||||||
|
|
||||||
extern void assert_oid_type(const struct object_id *oid, enum object_type expect);
|
extern void assert_oid_type(const struct object_id *oid, enum object_type expect);
|
||||||
|
|
||||||
|
36
sha1_file.c
36
sha1_file.c
@ -709,42 +709,42 @@ int check_and_freshen_file(const char *fn, int freshen)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int check_and_freshen_local(const unsigned char *sha1, int freshen)
|
static int check_and_freshen_local(const struct object_id *oid, int freshen)
|
||||||
{
|
{
|
||||||
static struct strbuf buf = STRBUF_INIT;
|
static struct strbuf buf = STRBUF_INIT;
|
||||||
|
|
||||||
strbuf_reset(&buf);
|
strbuf_reset(&buf);
|
||||||
sha1_file_name(the_repository, &buf, sha1);
|
sha1_file_name(the_repository, &buf, oid->hash);
|
||||||
|
|
||||||
return check_and_freshen_file(buf.buf, freshen);
|
return check_and_freshen_file(buf.buf, freshen);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int check_and_freshen_nonlocal(const unsigned char *sha1, int freshen)
|
static int check_and_freshen_nonlocal(const struct object_id *oid, int freshen)
|
||||||
{
|
{
|
||||||
struct alternate_object_database *alt;
|
struct alternate_object_database *alt;
|
||||||
prepare_alt_odb(the_repository);
|
prepare_alt_odb(the_repository);
|
||||||
for (alt = the_repository->objects->alt_odb_list; alt; alt = alt->next) {
|
for (alt = the_repository->objects->alt_odb_list; alt; alt = alt->next) {
|
||||||
const char *path = alt_sha1_path(alt, sha1);
|
const char *path = alt_sha1_path(alt, oid->hash);
|
||||||
if (check_and_freshen_file(path, freshen))
|
if (check_and_freshen_file(path, freshen))
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int check_and_freshen(const unsigned char *sha1, int freshen)
|
static int check_and_freshen(const struct object_id *oid, int freshen)
|
||||||
{
|
{
|
||||||
return check_and_freshen_local(sha1, freshen) ||
|
return check_and_freshen_local(oid, freshen) ||
|
||||||
check_and_freshen_nonlocal(sha1, freshen);
|
check_and_freshen_nonlocal(oid, freshen);
|
||||||
}
|
}
|
||||||
|
|
||||||
int has_loose_object_nonlocal(const unsigned char *sha1)
|
int has_loose_object_nonlocal(const struct object_id *oid)
|
||||||
{
|
{
|
||||||
return check_and_freshen_nonlocal(sha1, 0);
|
return check_and_freshen_nonlocal(oid, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int has_loose_object(const unsigned char *sha1)
|
static int has_loose_object(const struct object_id *oid)
|
||||||
{
|
{
|
||||||
return check_and_freshen(sha1, 0);
|
return check_and_freshen(oid, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mmap_limit_check(size_t length)
|
static void mmap_limit_check(size_t length)
|
||||||
@ -1661,15 +1661,15 @@ static int write_loose_object(const struct object_id *oid, char *hdr,
|
|||||||
return finalize_object_file(tmp_file.buf, filename.buf);
|
return finalize_object_file(tmp_file.buf, filename.buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int freshen_loose_object(const unsigned char *sha1)
|
static int freshen_loose_object(const struct object_id *oid)
|
||||||
{
|
{
|
||||||
return check_and_freshen(sha1, 1);
|
return check_and_freshen(oid, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int freshen_packed_object(const unsigned char *sha1)
|
static int freshen_packed_object(const struct object_id *oid)
|
||||||
{
|
{
|
||||||
struct pack_entry e;
|
struct pack_entry e;
|
||||||
if (!find_pack_entry(the_repository, sha1, &e))
|
if (!find_pack_entry(the_repository, oid->hash, &e))
|
||||||
return 0;
|
return 0;
|
||||||
if (e.p->freshened)
|
if (e.p->freshened)
|
||||||
return 1;
|
return 1;
|
||||||
@ -1689,7 +1689,7 @@ int write_object_file(const void *buf, unsigned long len, const char *type,
|
|||||||
* it out into .git/objects/??/?{38} file.
|
* it out into .git/objects/??/?{38} file.
|
||||||
*/
|
*/
|
||||||
write_object_file_prepare(buf, len, type, oid, hdr, &hdrlen);
|
write_object_file_prepare(buf, len, type, oid, hdr, &hdrlen);
|
||||||
if (freshen_packed_object(oid->hash) || freshen_loose_object(oid->hash))
|
if (freshen_packed_object(oid) || freshen_loose_object(oid))
|
||||||
return 0;
|
return 0;
|
||||||
return write_loose_object(oid, hdr, hdrlen, buf, len, 0);
|
return write_loose_object(oid, hdr, hdrlen, buf, len, 0);
|
||||||
}
|
}
|
||||||
@ -1708,7 +1708,7 @@ int hash_object_file_literally(const void *buf, unsigned long len,
|
|||||||
|
|
||||||
if (!(flags & HASH_WRITE_OBJECT))
|
if (!(flags & HASH_WRITE_OBJECT))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
if (freshen_packed_object(oid->hash) || freshen_loose_object(oid->hash))
|
if (freshen_packed_object(oid) || freshen_loose_object(oid))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
status = write_loose_object(oid, header, hdrlen, buf, len, 0);
|
status = write_loose_object(oid, header, hdrlen, buf, len, 0);
|
||||||
|
|
||||||
@ -1726,7 +1726,7 @@ int force_object_loose(const struct object_id *oid, time_t mtime)
|
|||||||
int hdrlen;
|
int hdrlen;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (has_loose_object(oid->hash))
|
if (has_loose_object(oid))
|
||||||
return 0;
|
return 0;
|
||||||
buf = read_object(oid->hash, &type, &len);
|
buf = read_object(oid->hash, &type, &len);
|
||||||
if (!buf)
|
if (!buf)
|
||||||
|
Loading…
Reference in New Issue
Block a user