Skip to content

Commit

Permalink
Merge branch 'jk/peel-ref'
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Jeff King committed Oct 25, 2012
2 parents 6a83a6d + 435c833 commit 315ea32
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 36 deletions.
2 changes: 1 addition & 1 deletion builtin/describe.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ static int get_name(const char *path, const unsigned char *sha1, int flag, void
if (!all && !might_be_tag)
return 0;

if (!peel_ref(path, peeled) && !is_null_sha1(peeled)) {
if (!peel_ref(path, peeled)) {
is_tag = !!hashcmp(sha1, peeled);
} else {
hashcpy(peeled, sha1);
Expand Down
1 change: 0 additions & 1 deletion builtin/pack-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -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? */
!peel_ref(path, peeled) && /* peelable? */
!is_null_sha1(peeled) && /* annotated tag? */
locate_object_entry(peeled)) /* object packed? */
add_object_entry(sha1, OBJ_TAG, NULL, 0);
return 0;
Expand Down
23 changes: 3 additions & 20 deletions builtin/show-ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
struct object *obj;
const char *hex;
unsigned char peeled[20];

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

if ((flag & REF_ISPACKED) && !peel_ref(refname, peeled)) {
if (!is_null_sha1(peeled)) {
hex = find_unique_abbrev(peeled, abbrev);
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);
}
if (!peel_ref(refname, peeled)) {
hex = find_unique_abbrev(peeled, abbrev);
printf("%s %s^{}\n", hex, refname);
}
return 0;
}
Expand Down
15 changes: 12 additions & 3 deletions refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,8 @@ int peel_ref(const char *refname, unsigned char *sha1)
if (current_ref && (current_ref->name == refname
|| !strcmp(current_ref->name, refname))) {
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);
return 0;
}
Expand All @@ -1223,9 +1225,16 @@ int peel_ref(const char *refname, unsigned char *sha1)
}

fallback:
o = parse_object(base);
if (o && o->type == OBJ_TAG) {
o = deref_tag(o, refname, 0);
o = lookup_unknown_object(base);
if (o->type == OBJ_NONE) {
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) {
hashcpy(sha1, o->sha1);
return 0;
Expand Down
14 changes: 3 additions & 11 deletions upload-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -727,12 +727,7 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, vo
" include-tag multi_ack_detailed";
struct object *o = lookup_unknown_object(sha1);
const char *refname_nons = strip_namespace(refname);

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));
}
unsigned char peeled[20];

if (capabilities)
packet_write(1, "%s %s%c%s%s agent=%s\n",
Expand All @@ -747,11 +742,8 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, vo
o->flags |= OUR_REF;
nr_our_refs++;
}
if (o->type == OBJ_TAG) {
o = deref_tag_noverify(o);
if (o)
packet_write(1, "%s %s^{}\n", sha1_to_hex(o->sha1), refname_nons);
}
if (!peel_ref(refname, peeled))
packet_write(1, "%s %s^{}\n", sha1_to_hex(peeled), refname_nons);
return 0;
}

Expand Down

0 comments on commit 315ea32

Please sign in to comment.