summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Tan <jonathantanmy@google.com>2017-06-21 17:40:22 -0700
committerJunio C Hamano <gitster@pobox.com>2017-06-26 10:28:42 -0700
commitdfdd4afcf97b0199f44231e726e373934da77717 (patch)
tree9f2bd74ea05128dd007e85930ebf863e337dbe5f
parentc84a1f3ed4d5314d2acc2bdca71b0bc5088423f9 (diff)
downloadgit-dfdd4afcf97b0199f44231e726e373934da77717.tar.gz
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>
-rw-r--r--cache.h4
-rw-r--r--sha1_file.c43
2 files changed, 28 insertions, 19 deletions
diff --git a/cache.h b/cache.h
index 48aea923b2..7cf2ca466a 100644
--- a/cache.h
+++ b/cache.h
@@ -1863,6 +1863,10 @@ struct object_info {
#define OBJECT_INFO_LOOKUP_REPLACE 1
/* Allow reading from a loose object file of unknown/bogus type */
#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 packed_object_info(struct packed_git *pack, off_t offset, struct object_info *);
diff --git a/sha1_file.c b/sha1_file.c
index 615a27dac6..b6bc02f093 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -2977,29 +2977,30 @@ 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)
{
- struct cached_object *co;
struct pack_entry e;
int rtype;
const unsigned char *real = (flags & OBJECT_INFO_LOOKUP_REPLACE) ?
lookup_replace_object(sha1) :
sha1;
- co = find_cached_object(real);
- if (co) {
- if (oi->typep)
- *(oi->typep) = co->type;
- if (oi->sizep)
- *(oi->sizep) = co->size;
- if (oi->disk_sizep)
- *(oi->disk_sizep) = 0;
- if (oi->delta_base_sha1)
- hashclr(oi->delta_base_sha1);
- if (oi->typename)
- strbuf_addstr(oi->typename, typename(co->type));
- if (oi->contentp)
- *oi->contentp = xmemdupz(co->buf, co->size);
- oi->whence = OI_CACHED;
- return 0;
+ if (!(flags & OBJECT_INFO_SKIP_CACHED)) {
+ struct cached_object *co = find_cached_object(real);
+ if (co) {
+ if (oi->typep)
+ *(oi->typep) = co->type;
+ if (oi->sizep)
+ *(oi->sizep) = co->size;
+ if (oi->disk_sizep)
+ *(oi->disk_sizep) = 0;
+ if (oi->delta_base_sha1)
+ hashclr(oi->delta_base_sha1);
+ if (oi->typename)
+ strbuf_addstr(oi->typename, typename(co->type));
+ if (oi->contentp)
+ *oi->contentp = xmemdupz(co->buf, co->size);
+ oi->whence = OI_CACHED;
+ return 0;
+ }
}
if (!find_pack_entry(real, &e)) {
@@ -3010,9 +3011,13 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi,
}
/* Not a loose object; someone else may have just packed it. */
- reprepare_packed_git();
- if (!find_pack_entry(real, &e))
+ if (flags & OBJECT_INFO_QUICK) {
return -1;
+ } else {
+ reprepare_packed_git();
+ if (!find_pack_entry(real, &e))
+ return -1;
+ }
}
rtype = packed_object_info(e.p, e.offset, oi);