Skip to content

Commit cbbe50d

Browse files
committed
upload-pack: share more code
We mark the objects pointed at our refs with "OUR_REF" flag in two functions (mark_our_ref() and send_ref()), but we can just use the former as a helper for the latter. Update the way mark_our_ref() prepares in-core object to use lookup_unknown_object() to delay reading the actual object data, just like we did in 435c833 (upload-pack: use peel_ref for ref advertisements, 2012-10-04). Signed-off-by: Junio C Hamano <[email protected]>
1 parent 02f55e6 commit cbbe50d

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

upload-pack.c

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -722,15 +722,28 @@ static void receive_needs(void)
722722
free(shallows.objects);
723723
}
724724

725+
static int mark_our_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
726+
{
727+
struct object *o = lookup_unknown_object(sha1);
728+
if (!o)
729+
die("git upload-pack: cannot find object %s:", sha1_to_hex(sha1));
730+
if (!(o->flags & OUR_REF)) {
731+
o->flags |= OUR_REF;
732+
nr_our_refs++;
733+
}
734+
return 0;
735+
}
736+
725737
static int send_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
726738
{
727739
static const char *capabilities = "multi_ack thin-pack side-band"
728740
" side-band-64k ofs-delta shallow no-progress"
729741
" include-tag multi_ack_detailed";
730-
struct object *o = lookup_unknown_object(sha1);
731742
const char *refname_nons = strip_namespace(refname);
732743
unsigned char peeled[20];
733744

745+
mark_our_ref(refname, sha1, flag, cb_data);
746+
734747
if (capabilities)
735748
packet_write(1, "%s %s%c%s%s agent=%s\n",
736749
sha1_to_hex(sha1), refname_nons,
@@ -740,27 +753,11 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, vo
740753
else
741754
packet_write(1, "%s %s\n", sha1_to_hex(sha1), refname_nons);
742755
capabilities = NULL;
743-
if (!(o->flags & OUR_REF)) {
744-
o->flags |= OUR_REF;
745-
nr_our_refs++;
746-
}
747756
if (!peel_ref(refname, peeled))
748757
packet_write(1, "%s %s^{}\n", sha1_to_hex(peeled), refname_nons);
749758
return 0;
750759
}
751760

752-
static int mark_our_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
753-
{
754-
struct object *o = parse_object(sha1);
755-
if (!o)
756-
die("git upload-pack: cannot find object %s:", sha1_to_hex(sha1));
757-
if (!(o->flags & OUR_REF)) {
758-
o->flags |= OUR_REF;
759-
nr_our_refs++;
760-
}
761-
return 0;
762-
}
763-
764761
static void upload_pack(void)
765762
{
766763
if (advertise_refs || !stateless_rpc) {

0 commit comments

Comments
 (0)