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>
Jonathan Tan committed
Jun 21, 2017 at 17:40 UTC
dfdd4afcf97b0199f44231e726e373934da77717
2 files changed
+28
-19
cache.h
+4
@@ -1863,6 +1863,10 @@ struct object_info {
1863
#define OBJECT_INFO_LOOKUP_REPLACE 1
1864
/* Allow reading from a loose object file of unknown/bogus type */
1865
#define OBJECT_INFO_ALLOW_UNKNOWN_TYPE 2
1866
+/* Do not check cached storage */
1867
+#define OBJECT_INFO_SKIP_CACHED 4
1868
+/* Do not retry packed storage after checking packed and loose storage */
1869
+#define OBJECT_INFO_QUICK 8
1870
extern int sha1_object_info_extended(const unsigned char *, struct object_info *, unsigned flags);
1871
extern int packed_object_info(struct packed_git *pack, off_t offset, struct object_info *);
1872
sha1_file.c
+24
-19
@@ -2977,29 +2977,30 @@ static int sha1_loose_object_info(const unsigned char *sha1,
2977
2978
int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi, unsigned flags)
2979
{
2980
- struct cached_object *co;
2980
struct pack_entry e;
2981
int rtype;
2982
const unsigned char *real = (flags & OBJECT_INFO_LOOKUP_REPLACE) ?
2983
lookup_replace_object(sha1) :
2984
sha1;
2985
2987
- co = find_cached_object(real);
2988
- if (co) {
2989
- if (oi->typep)
2990
- *(oi->typep) = co->type;
2991
- if (oi->sizep)
2992
- *(oi->sizep) = co->size;
2993
- if (oi->disk_sizep)
2994
- *(oi->disk_sizep) = 0;
2995
- if (oi->delta_base_sha1)
2996
- hashclr(oi->delta_base_sha1);
2997
- if (oi->typename)
2998
- strbuf_addstr(oi->typename, typename(co->type));
2999
- if (oi->contentp)
3000
- *oi->contentp = xmemdupz(co->buf, co->size);
3001
- oi->whence = OI_CACHED;
3002
- return 0;
2986
+ if (!(flags & OBJECT_INFO_SKIP_CACHED)) {
2987
+ struct cached_object *co = find_cached_object(real);
2988
+ if (co) {
2989
+ if (oi->typep)
2990
+ *(oi->typep) = co->type;
2991
+ if (oi->sizep)
2992
+ *(oi->sizep) = co->size;
2993
+ if (oi->disk_sizep)
2994
+ *(oi->disk_sizep) = 0;
2995
+ if (oi->delta_base_sha1)
2996
+ hashclr(oi->delta_base_sha1);
2997
+ if (oi->typename)
2998
+ strbuf_addstr(oi->typename, typename(co->type));
2999
+ if (oi->contentp)
3000
+ *oi->contentp = xmemdupz(co->buf, co->size);
3001
+ oi->whence = OI_CACHED;
3002
+ return 0;
3003
+ }
3004
}
3005
3006
if (!find_pack_entry(real, &e)) {
@@ -3010,9 +3011,13 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi,
3011
}
3012
3013
/* Not a loose object; someone else may have just packed it. */
3013
- reprepare_packed_git();
3014
- if (!find_pack_entry(real, &e))
3014
+ if (flags & OBJECT_INFO_QUICK) {
3015
return -1;
3016
+ } else {
3017
+ reprepare_packed_git();
3018
+ if (!find_pack_entry(real, &e))
3019
+ return -1;
3020
+ }
3021
}
3022
3023
rtype = packed_object_info(e.p, e.offset, oi);