Skip to content

Commit 315ea32

Browse files
committed
Merge branch 'jk/peel-ref'
Speeds up "git upload-pack" (what is invoked by "git fetch" on the other side of the connection) by reducing the cost to advertise the branches and tags that are available in the repository. * jk/peel-ref: upload-pack: use peel_ref for ref advertisements peel_ref: check object type before loading peel_ref: do not return a null sha1 peel_ref: use faster deref_tag_noverify
2 parents 6a83a6d + 435c833 commit 315ea32

File tree

5 files changed

+19
-36
lines changed

5 files changed

+19
-36
lines changed

builtin/describe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ static int get_name(const char *path, const unsigned char *sha1, int flag, void
144144
if (!all && !might_be_tag)
145145
return 0;
146146

147-
if (!peel_ref(path, peeled) && !is_null_sha1(peeled)) {
147+
if (!peel_ref(path, peeled)) {
148148
is_tag = !!hashcmp(sha1, peeled);
149149
} else {
150150
hashcpy(peeled, sha1);

builtin/pack-objects.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2033,7 +2033,6 @@ static int add_ref_tag(const char *path, const unsigned char *sha1, int flag, vo
20332033

20342034
if (!prefixcmp(path, "refs/tags/") && /* is a tag? */
20352035
!peel_ref(path, peeled) && /* peelable? */
2036-
!is_null_sha1(peeled) && /* annotated tag? */
20372036
locate_object_entry(peeled)) /* object packed? */
20382037
add_object_entry(sha1, OBJ_TAG, NULL, 0);
20392038
return 0;

builtin/show-ref.c

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ static void show_one(const char *refname, const unsigned char *sha1)
2828

2929
static int show_ref(const char *refname, const unsigned char *sha1, int flag, void *cbdata)
3030
{
31-
struct object *obj;
3231
const char *hex;
3332
unsigned char peeled[20];
3433

@@ -79,25 +78,9 @@ static int show_ref(const char *refname, const unsigned char *sha1, int flag, vo
7978
if (!deref_tags)
8079
return 0;
8180

82-
if ((flag & REF_ISPACKED) && !peel_ref(refname, peeled)) {
83-
if (!is_null_sha1(peeled)) {
84-
hex = find_unique_abbrev(peeled, abbrev);
85-
printf("%s %s^{}\n", hex, refname);
86-
}
87-
}
88-
else {
89-
obj = parse_object(sha1);
90-
if (!obj)
91-
die("git show-ref: bad ref %s (%s)", refname,
92-
sha1_to_hex(sha1));
93-
if (obj->type == OBJ_TAG) {
94-
obj = deref_tag(obj, refname, 0);
95-
if (!obj)
96-
die("git show-ref: bad tag at ref %s (%s)", refname,
97-
sha1_to_hex(sha1));
98-
hex = find_unique_abbrev(obj->sha1, abbrev);
99-
printf("%s %s^{}\n", hex, refname);
100-
}
81+
if (!peel_ref(refname, peeled)) {
82+
hex = find_unique_abbrev(peeled, abbrev);
83+
printf("%s %s^{}\n", hex, refname);
10184
}
10285
return 0;
10386
}

refs.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,6 +1202,8 @@ int peel_ref(const char *refname, unsigned char *sha1)
12021202
if (current_ref && (current_ref->name == refname
12031203
|| !strcmp(current_ref->name, refname))) {
12041204
if (current_ref->flag & REF_KNOWS_PEELED) {
1205+
if (is_null_sha1(current_ref->u.value.peeled))
1206+
return -1;
12051207
hashcpy(sha1, current_ref->u.value.peeled);
12061208
return 0;
12071209
}
@@ -1223,9 +1225,16 @@ int peel_ref(const char *refname, unsigned char *sha1)
12231225
}
12241226

12251227
fallback:
1226-
o = parse_object(base);
1227-
if (o && o->type == OBJ_TAG) {
1228-
o = deref_tag(o, refname, 0);
1228+
o = lookup_unknown_object(base);
1229+
if (o->type == OBJ_NONE) {
1230+
int type = sha1_object_info(base, NULL);
1231+
if (type < 0)
1232+
return -1;
1233+
o->type = type;
1234+
}
1235+
1236+
if (o->type == OBJ_TAG) {
1237+
o = deref_tag_noverify(o);
12291238
if (o) {
12301239
hashcpy(sha1, o->sha1);
12311240
return 0;

upload-pack.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -727,12 +727,7 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, vo
727727
" include-tag multi_ack_detailed";
728728
struct object *o = lookup_unknown_object(sha1);
729729
const char *refname_nons = strip_namespace(refname);
730-
731-
if (o->type == OBJ_NONE) {
732-
o->type = sha1_object_info(sha1, NULL);
733-
if (o->type < 0)
734-
die("git upload-pack: cannot find object %s:", sha1_to_hex(sha1));
735-
}
730+
unsigned char peeled[20];
736731

737732
if (capabilities)
738733
packet_write(1, "%s %s%c%s%s agent=%s\n",
@@ -747,11 +742,8 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, vo
747742
o->flags |= OUR_REF;
748743
nr_our_refs++;
749744
}
750-
if (o->type == OBJ_TAG) {
751-
o = deref_tag_noverify(o);
752-
if (o)
753-
packet_write(1, "%s %s^{}\n", sha1_to_hex(o->sha1), refname_nons);
754-
}
745+
if (!peel_ref(refname, peeled))
746+
packet_write(1, "%s %s^{}\n", sha1_to_hex(peeled), refname_nons);
755747
return 0;
756748
}
757749

0 commit comments

Comments
 (0)