Skip to content

Commit d1afa8b

Browse files
committed
Merge branch 'jk/parse-object-cached'
* jk/parse-object-cached: upload-pack: avoid parsing tag destinations upload-pack: avoid parsing objects during ref advertisement parse_object: try internal cache before reading object db
2 parents 2bbf77d + 90108a2 commit d1afa8b

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

object.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,15 @@ struct object *parse_object(const unsigned char *sha1)
191191
enum object_type type;
192192
int eaten;
193193
const unsigned char *repl = lookup_replace_object(sha1);
194-
void *buffer = read_sha1_file(sha1, &type, &size);
194+
void *buffer;
195+
struct object *obj;
196+
197+
obj = lookup_object(sha1);
198+
if (obj && obj->parsed)
199+
return obj;
195200

201+
buffer = read_sha1_file(sha1, &type, &size);
196202
if (buffer) {
197-
struct object *obj;
198203
if (check_sha1_signature(repl, buffer, size, typename(type)) < 0) {
199204
free(buffer);
200205
error("sha1 mismatch %s\n", sha1_to_hex(repl));

tag.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ struct object *deref_tag(struct object *o, const char *warn, int warnlen)
2424
return o;
2525
}
2626

27+
struct object *deref_tag_noverify(struct object *o)
28+
{
29+
while (o && o->type == OBJ_TAG) {
30+
o = parse_object(o->sha1);
31+
if (o && o->type == OBJ_TAG && ((struct tag *)o)->tagged)
32+
o = ((struct tag *)o)->tagged;
33+
else
34+
o = NULL;
35+
}
36+
return o;
37+
}
38+
2739
struct tag *lookup_tag(const unsigned char *sha1)
2840
{
2941
struct object *obj = lookup_object(sha1);

tag.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ extern struct tag *lookup_tag(const unsigned char *sha1);
1616
extern int parse_tag_buffer(struct tag *item, const void *data, unsigned long size);
1717
extern int parse_tag(struct tag *item);
1818
extern struct object *deref_tag(struct object *, const char *, int);
19+
extern struct object *deref_tag_noverify(struct object *);
1920
extern size_t parse_signature(const char *buf, unsigned long size);
2021

2122
#endif /* TAG_H */

upload-pack.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -724,11 +724,14 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, vo
724724
static const char *capabilities = "multi_ack thin-pack side-band"
725725
" side-band-64k ofs-delta shallow no-progress"
726726
" include-tag multi_ack_detailed";
727-
struct object *o = parse_object(sha1);
727+
struct object *o = lookup_unknown_object(sha1);
728728
const char *refname_nons = strip_namespace(refname);
729729

730-
if (!o)
731-
die("git upload-pack: cannot find object %s:", sha1_to_hex(sha1));
730+
if (o->type == OBJ_NONE) {
731+
o->type = sha1_object_info(sha1, NULL);
732+
if (o->type < 0)
733+
die("git upload-pack: cannot find object %s:", sha1_to_hex(sha1));
734+
}
732735

733736
if (capabilities)
734737
packet_write(1, "%s %s%c%s%s\n", sha1_to_hex(sha1), refname_nons,
@@ -742,7 +745,7 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, vo
742745
nr_our_refs++;
743746
}
744747
if (o->type == OBJ_TAG) {
745-
o = deref_tag(o, refname, 0);
748+
o = deref_tag_noverify(o);
746749
if (o)
747750
packet_write(1, "%s %s^{}\n", sha1_to_hex(o->sha1), refname_nons);
748751
}

0 commit comments

Comments
 (0)