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 <gitster@pobox.com>
Junio C Hamano committed
Jan 18, 2013 at 15:48 UTC
cbbe50db7691cd9d7d261ebc5c5ffec55f93127d
1 file changed
+14
-17
upload-pack.c
+14
-17
@@ -722,15 +722,28 @@ static void receive_needs(void)
722
free(shallows.objects);
723
}
724
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
+
737
static int send_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
738
{
739
static const char *capabilities = "multi_ack thin-pack side-band"
740
" side-band-64k ofs-delta shallow no-progress"
741
" include-tag multi_ack_detailed";
730
- struct object *o = lookup_unknown_object(sha1);
742
const char *refname_nons = strip_namespace(refname);
743
unsigned char peeled[20];
744
745
+ mark_our_ref(refname, sha1, flag, cb_data);
746
+
747
if (capabilities)
748
packet_write(1, "%s %s%c%s%s agent=%s\n",
749
sha1_to_hex(sha1), refname_nons,
@@ -740,27 +753,11 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, vo
753
else
754
packet_write(1, "%s %s\n", sha1_to_hex(sha1), refname_nons);
755
capabilities = NULL;
743
- if (!(o->flags & OUR_REF)) {
744
- o->flags |= OUR_REF;
745
- nr_our_refs++;
746
- }
756
if (!peel_ref(refname, peeled))
757
packet_write(1, "%s %s^{}\n", sha1_to_hex(peeled), refname_nons);
758
return 0;
759
}
760
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
-
761
static void upload_pack(void)
762
{
763
if (advertise_refs || !stateless_rpc) {