sha1_file: teach sha1_object_info_extended more flags
Improve sha1_object_info_extended() by supporting additional flags. This allows has_sha1_file_with_flags() to be modified to use sha1_object_info_extended() in a subsequent patch. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
c84a1f3ed4
commit
dfdd4afcf9
4
cache.h
4
cache.h
|
@ -1863,6 +1863,10 @@ struct object_info {
|
||||||
#define OBJECT_INFO_LOOKUP_REPLACE 1
|
#define OBJECT_INFO_LOOKUP_REPLACE 1
|
||||||
/* Allow reading from a loose object file of unknown/bogus type */
|
/* Allow reading from a loose object file of unknown/bogus type */
|
||||||
#define OBJECT_INFO_ALLOW_UNKNOWN_TYPE 2
|
#define OBJECT_INFO_ALLOW_UNKNOWN_TYPE 2
|
||||||
|
/* Do not check cached storage */
|
||||||
|
#define OBJECT_INFO_SKIP_CACHED 4
|
||||||
|
/* Do not retry packed storage after checking packed and loose storage */
|
||||||
|
#define OBJECT_INFO_QUICK 8
|
||||||
extern int sha1_object_info_extended(const unsigned char *, struct object_info *, unsigned flags);
|
extern int sha1_object_info_extended(const unsigned char *, struct object_info *, unsigned flags);
|
||||||
extern int packed_object_info(struct packed_git *pack, off_t offset, struct object_info *);
|
extern int packed_object_info(struct packed_git *pack, off_t offset, struct object_info *);
|
||||||
|
|
||||||
|
|
|
@ -2977,14 +2977,14 @@ static int sha1_loose_object_info(const unsigned char *sha1,
|
||||||
|
|
||||||
int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi, unsigned flags)
|
int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi, unsigned flags)
|
||||||
{
|
{
|
||||||
struct cached_object *co;
|
|
||||||
struct pack_entry e;
|
struct pack_entry e;
|
||||||
int rtype;
|
int rtype;
|
||||||
const unsigned char *real = (flags & OBJECT_INFO_LOOKUP_REPLACE) ?
|
const unsigned char *real = (flags & OBJECT_INFO_LOOKUP_REPLACE) ?
|
||||||
lookup_replace_object(sha1) :
|
lookup_replace_object(sha1) :
|
||||||
sha1;
|
sha1;
|
||||||
|
|
||||||
co = find_cached_object(real);
|
if (!(flags & OBJECT_INFO_SKIP_CACHED)) {
|
||||||
|
struct cached_object *co = find_cached_object(real);
|
||||||
if (co) {
|
if (co) {
|
||||||
if (oi->typep)
|
if (oi->typep)
|
||||||
*(oi->typep) = co->type;
|
*(oi->typep) = co->type;
|
||||||
|
@ -3001,6 +3001,7 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi,
|
||||||
oi->whence = OI_CACHED;
|
oi->whence = OI_CACHED;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!find_pack_entry(real, &e)) {
|
if (!find_pack_entry(real, &e)) {
|
||||||
/* Most likely it's a loose object. */
|
/* Most likely it's a loose object. */
|
||||||
|
@ -3010,10 +3011,14 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Not a loose object; someone else may have just packed it. */
|
/* Not a loose object; someone else may have just packed it. */
|
||||||
|
if (flags & OBJECT_INFO_QUICK) {
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
reprepare_packed_git();
|
reprepare_packed_git();
|
||||||
if (!find_pack_entry(real, &e))
|
if (!find_pack_entry(real, &e))
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
rtype = packed_object_info(e.p, e.offset, oi);
|
rtype = packed_object_info(e.p, e.offset, oi);
|
||||||
if (rtype < 0) {
|
if (rtype < 0) {
|
||||||
|
|
Loading…
Reference in New Issue