summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--builtin/cat-file.c7
-rw-r--r--cache.h1
-rw-r--r--sha1_file.c20
-rw-r--r--streaming.c2
4 files changed, 19 insertions, 11 deletions
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index fe5c77f54c..163ce6c77c 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -150,7 +150,9 @@ static void expand_atom(struct strbuf *sb, const char *atom, int len,
if (!data->mark_query)
strbuf_addstr(sb, sha1_to_hex(data->sha1));
} else if (is_atom("objecttype", atom, len)) {
- if (!data->mark_query)
+ if (data->mark_query)
+ data->info.typep = &data->type;
+ else
strbuf_addstr(sb, typename(data->type));
} else if (is_atom("objectsize", atom, len)) {
if (data->mark_query)
@@ -229,8 +231,7 @@ static int batch_one_object(const char *obj_name, struct batch_options *opt,
return 0;
}
- data->type = sha1_object_info_extended(data->sha1, &data->info);
- if (data->type <= 0) {
+ if (sha1_object_info_extended(data->sha1, &data->info) < 0) {
printf("%s missing\n", obj_name);
fflush(stdout);
return 0;
diff --git a/cache.h b/cache.h
index dc99366a2e..6882bbe6c3 100644
--- a/cache.h
+++ b/cache.h
@@ -1099,6 +1099,7 @@ extern int unpack_object_header(struct packed_git *, struct pack_window **, off_
struct object_info {
/* Request */
+ enum object_type *typep;
unsigned long *sizep;
unsigned long *disk_sizep;
diff --git a/sha1_file.c b/sha1_file.c
index fa2809884b..d391271310 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -2433,24 +2433,26 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi)
{
struct cached_object *co;
struct pack_entry e;
- int type, rtype;
+ int rtype;
co = find_cached_object(sha1);
if (co) {
+ if (oi->typep)
+ *(oi->typep) = co->type;
if (oi->sizep)
*(oi->sizep) = co->size;
if (oi->disk_sizep)
*(oi->disk_sizep) = 0;
oi->whence = OI_CACHED;
- return co->type;
+ return 0;
}
if (!find_pack_entry(sha1, &e)) {
/* Most likely it's a loose object. */
- if (!sha1_loose_object_info(sha1, &type,
+ if (!sha1_loose_object_info(sha1, oi->typep,
oi->sizep, oi->disk_sizep)) {
oi->whence = OI_LOOSE;
- return type;
+ return 0;
}
/* Not a loose object; someone else may have just packed it. */
@@ -2459,7 +2461,7 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi)
return -1;
}
- rtype = packed_object_info(e.p, e.offset, &type, oi->sizep,
+ rtype = packed_object_info(e.p, e.offset, oi->typep, oi->sizep,
oi->disk_sizep);
if (rtype < 0) {
mark_bad_packed_object(e.p, sha1);
@@ -2474,15 +2476,19 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi)
rtype == OBJ_OFS_DELTA);
}
- return type;
+ return 0;
}
int sha1_object_info(const unsigned char *sha1, unsigned long *sizep)
{
+ enum object_type type;
struct object_info oi = {0};
+ oi.typep = &type;
oi.sizep = sizep;
- return sha1_object_info_extended(sha1, &oi);
+ if (sha1_object_info_extended(sha1, &oi) < 0)
+ return -1;
+ return type;
}
static void *read_packed_sha1(const unsigned char *sha1,
diff --git a/streaming.c b/streaming.c
index cac282f06b..870657ab56 100644
--- a/streaming.c
+++ b/streaming.c
@@ -111,11 +111,11 @@ static enum input_source istream_source(const unsigned char *sha1,
unsigned long size;
int status;
+ oi->typep = type;
oi->sizep = &size;
status = sha1_object_info_extended(sha1, oi);
if (status < 0)
return stream_error;
- *type = status;
switch (oi->whence) {
case OI_LOOSE: