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
This commit is contained in:
commit
315ea32f1b
@ -144,7 +144,7 @@ static int get_name(const char *path, const unsigned char *sha1, int flag, void
|
|||||||
if (!all && !might_be_tag)
|
if (!all && !might_be_tag)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!peel_ref(path, peeled) && !is_null_sha1(peeled)) {
|
if (!peel_ref(path, peeled)) {
|
||||||
is_tag = !!hashcmp(sha1, peeled);
|
is_tag = !!hashcmp(sha1, peeled);
|
||||||
} else {
|
} else {
|
||||||
hashcpy(peeled, sha1);
|
hashcpy(peeled, sha1);
|
||||||
|
@ -2033,7 +2033,6 @@ static int add_ref_tag(const char *path, const unsigned char *sha1, int flag, vo
|
|||||||
|
|
||||||
if (!prefixcmp(path, "refs/tags/") && /* is a tag? */
|
if (!prefixcmp(path, "refs/tags/") && /* is a tag? */
|
||||||
!peel_ref(path, peeled) && /* peelable? */
|
!peel_ref(path, peeled) && /* peelable? */
|
||||||
!is_null_sha1(peeled) && /* annotated tag? */
|
|
||||||
locate_object_entry(peeled)) /* object packed? */
|
locate_object_entry(peeled)) /* object packed? */
|
||||||
add_object_entry(sha1, OBJ_TAG, NULL, 0);
|
add_object_entry(sha1, OBJ_TAG, NULL, 0);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -28,7 +28,6 @@ static void show_one(const char *refname, const unsigned char *sha1)
|
|||||||
|
|
||||||
static int show_ref(const char *refname, const unsigned char *sha1, int flag, void *cbdata)
|
static int show_ref(const char *refname, const unsigned char *sha1, int flag, void *cbdata)
|
||||||
{
|
{
|
||||||
struct object *obj;
|
|
||||||
const char *hex;
|
const char *hex;
|
||||||
unsigned char peeled[20];
|
unsigned char peeled[20];
|
||||||
|
|
||||||
@ -79,25 +78,9 @@ match:
|
|||||||
if (!deref_tags)
|
if (!deref_tags)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if ((flag & REF_ISPACKED) && !peel_ref(refname, peeled)) {
|
if (!peel_ref(refname, peeled)) {
|
||||||
if (!is_null_sha1(peeled)) {
|
hex = find_unique_abbrev(peeled, abbrev);
|
||||||
hex = find_unique_abbrev(peeled, abbrev);
|
printf("%s %s^{}\n", hex, refname);
|
||||||
printf("%s %s^{}\n", hex, refname);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
obj = parse_object(sha1);
|
|
||||||
if (!obj)
|
|
||||||
die("git show-ref: bad ref %s (%s)", refname,
|
|
||||||
sha1_to_hex(sha1));
|
|
||||||
if (obj->type == OBJ_TAG) {
|
|
||||||
obj = deref_tag(obj, refname, 0);
|
|
||||||
if (!obj)
|
|
||||||
die("git show-ref: bad tag at ref %s (%s)", refname,
|
|
||||||
sha1_to_hex(sha1));
|
|
||||||
hex = find_unique_abbrev(obj->sha1, abbrev);
|
|
||||||
printf("%s %s^{}\n", hex, refname);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
15
refs.c
15
refs.c
@ -1202,6 +1202,8 @@ int peel_ref(const char *refname, unsigned char *sha1)
|
|||||||
if (current_ref && (current_ref->name == refname
|
if (current_ref && (current_ref->name == refname
|
||||||
|| !strcmp(current_ref->name, refname))) {
|
|| !strcmp(current_ref->name, refname))) {
|
||||||
if (current_ref->flag & REF_KNOWS_PEELED) {
|
if (current_ref->flag & REF_KNOWS_PEELED) {
|
||||||
|
if (is_null_sha1(current_ref->u.value.peeled))
|
||||||
|
return -1;
|
||||||
hashcpy(sha1, current_ref->u.value.peeled);
|
hashcpy(sha1, current_ref->u.value.peeled);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1223,9 +1225,16 @@ int peel_ref(const char *refname, unsigned char *sha1)
|
|||||||
}
|
}
|
||||||
|
|
||||||
fallback:
|
fallback:
|
||||||
o = parse_object(base);
|
o = lookup_unknown_object(base);
|
||||||
if (o && o->type == OBJ_TAG) {
|
if (o->type == OBJ_NONE) {
|
||||||
o = deref_tag(o, refname, 0);
|
int type = sha1_object_info(base, NULL);
|
||||||
|
if (type < 0)
|
||||||
|
return -1;
|
||||||
|
o->type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (o->type == OBJ_TAG) {
|
||||||
|
o = deref_tag_noverify(o);
|
||||||
if (o) {
|
if (o) {
|
||||||
hashcpy(sha1, o->sha1);
|
hashcpy(sha1, o->sha1);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -727,12 +727,7 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, vo
|
|||||||
" include-tag multi_ack_detailed";
|
" include-tag multi_ack_detailed";
|
||||||
struct object *o = lookup_unknown_object(sha1);
|
struct object *o = lookup_unknown_object(sha1);
|
||||||
const char *refname_nons = strip_namespace(refname);
|
const char *refname_nons = strip_namespace(refname);
|
||||||
|
unsigned char peeled[20];
|
||||||
if (o->type == OBJ_NONE) {
|
|
||||||
o->type = sha1_object_info(sha1, NULL);
|
|
||||||
if (o->type < 0)
|
|
||||||
die("git upload-pack: cannot find object %s:", sha1_to_hex(sha1));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (capabilities)
|
if (capabilities)
|
||||||
packet_write(1, "%s %s%c%s%s agent=%s\n",
|
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
|
|||||||
o->flags |= OUR_REF;
|
o->flags |= OUR_REF;
|
||||||
nr_our_refs++;
|
nr_our_refs++;
|
||||||
}
|
}
|
||||||
if (o->type == OBJ_TAG) {
|
if (!peel_ref(refname, peeled))
|
||||||
o = deref_tag_noverify(o);
|
packet_write(1, "%s %s^{}\n", sha1_to_hex(peeled), refname_nons);
|
||||||
if (o)
|
|
||||||
packet_write(1, "%s %s^{}\n", sha1_to_hex(o->sha1), refname_nons);
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user