send-pack: stop using `the_repository`

Stop using `the_repository` in the "send-pack" subsystem by passing in a repository when sending a packfile. Adjust callers accordingly by using `the_repository`. While there may be some callers that have a repository available in their context, this trivial conversion allows for easier verification and bubbles up the use of `the_repository` by one level. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Dec 17, 2024 at 07:43 UTC 5ee907bb3f12c630f78554ea9b4c605f4e1a5e92
4 files changed +44 -40
builtin/send-pack.c
+1 -1
@@ -317,7 +317,7 @@ int cmd_send_pack(int argc,
317 set_ref_status_for_push(remote_refs, args.send_mirror,
318 args.force_update);
319
320 - ret = send_pack(&args, fd, conn, remote_refs, &extra_have);
320 + ret = send_pack(the_repository, &args, fd, conn, remote_refs, &extra_have);
321
322 if (helper_status)
323 print_helper_status(remote_refs);
send-pack.c
+40 -37
@@ -1,5 +1,3 @@
1 -#define USE_THE_REPOSITORY_VARIABLE
2 -
1 #include "git-compat-util.h"
2 #include "config.h"
3 #include "commit.h"
@@ -44,10 +42,11 @@ int option_parse_push_signed(const struct option *opt,
42 die("bad %s argument: %s", opt->long_name, arg);
43 }
44
47 -static void feed_object(const struct object_id *oid, FILE *fh, int negative)
45 +static void feed_object(struct repository *r,
46 + const struct object_id *oid, FILE *fh, int negative)
47 {
48 if (negative &&
50 - !repo_has_object_file_with_flags(the_repository, oid,
49 + !repo_has_object_file_with_flags(r, oid,
50 OBJECT_INFO_SKIP_FETCH_OBJECT |
51 OBJECT_INFO_QUICK))
52 return;
@@ -61,7 +60,8 @@ static void feed_object(const struct object_id *oid, FILE *fh, int negative)
60 /*
61 * Make a pack stream and spit it out into file descriptor fd
62 */
64 -static int pack_objects(int fd, struct ref *refs, struct oid_array *advertised,
63 +static int pack_objects(struct repository *r,
64 + int fd, struct ref *refs, struct oid_array *advertised,
65 struct oid_array *negotiated,
66 struct send_pack_args *args)
67 {
@@ -74,7 +74,7 @@ static int pack_objects(int fd, struct ref *refs, struct oid_array *advertised,
74 FILE *po_in;
75 int rc;
76
77 - trace2_region_enter("send_pack", "pack_objects", the_repository);
77 + trace2_region_enter("send_pack", "pack_objects", r);
78 strvec_push(&po.args, "pack-objects");
79 strvec_push(&po.args, "--all-progress-implied");
80 strvec_push(&po.args, "--revs");
@@ -87,7 +87,7 @@ static int pack_objects(int fd, struct ref *refs, struct oid_array *advertised,
87 strvec_push(&po.args, "-q");
88 if (args->progress)
89 strvec_push(&po.args, "--progress");
90 - if (is_repository_shallow(the_repository))
90 + if (is_repository_shallow(r))
91 strvec_push(&po.args, "--shallow");
92 if (args->disable_bitmaps)
93 strvec_push(&po.args, "--no-use-bitmap-index");
@@ -104,15 +104,15 @@ static int pack_objects(int fd, struct ref *refs, struct oid_array *advertised,
104 */
105 po_in = xfdopen(po.in, "w");
106 for (size_t i = 0; i < advertised->nr; i++)
107 - feed_object(&advertised->oid[i], po_in, 1);
107 + feed_object(r, &advertised->oid[i], po_in, 1);
108 for (size_t i = 0; i < negotiated->nr; i++)
109 - feed_object(&negotiated->oid[i], po_in, 1);
109 + feed_object(r, &negotiated->oid[i], po_in, 1);
110
111 while (refs) {
112 if (!is_null_oid(&refs->old_oid))
113 - feed_object(&refs->old_oid, po_in, 1);
113 + feed_object(r, &refs->old_oid, po_in, 1);
114 if (!is_null_oid(&refs->new_oid))
115 - feed_object(&refs->new_oid, po_in, 0);
115 + feed_object(r, &refs->new_oid, po_in, 0);
116 refs = refs->next;
117 }
118
@@ -146,10 +146,10 @@ static int pack_objects(int fd, struct ref *refs, struct oid_array *advertised,
146 */
147 if (rc > 128 && rc != 141)
148 error("pack-objects died of signal %d", rc - 128);
149 - trace2_region_leave("send_pack", "pack_objects", the_repository);
149 + trace2_region_leave("send_pack", "pack_objects", r);
150 return -1;
151 }
152 - trace2_region_leave("send_pack", "pack_objects", the_repository);
152 + trace2_region_leave("send_pack", "pack_objects", r);
153 return 0;
154 }
155
@@ -164,7 +164,8 @@ static int receive_unpack_status(struct packet_reader *reader)
164 return 0;
165 }
166
167 -static int receive_status(struct packet_reader *reader, struct ref *refs)
167 +static int receive_status(struct repository *r,
168 + struct packet_reader *reader, struct ref *refs)
169 {
170 struct ref *hint;
171 int ret;
@@ -172,7 +173,7 @@ static int receive_status(struct packet_reader *reader, struct ref *refs)
173 int new_report = 0;
174 int once = 0;
175
175 - trace2_region_enter("send_pack", "receive_status", the_repository);
176 + trace2_region_enter("send_pack", "receive_status", r);
177 hint = NULL;
178 ret = receive_unpack_status(reader);
179 while (1) {
@@ -221,10 +222,10 @@ static int receive_status(struct packet_reader *reader, struct ref *refs)
222 if (!strcmp(key, "refname"))
223 report->ref_name = xstrdup_or_null(val);
224 else if (!strcmp(key, "old-oid") && val &&
224 - !parse_oid_hex(val, &old_oid, &val))
225 + !parse_oid_hex_algop(val, &old_oid, &val, r->hash_algo))
226 report->old_oid = oiddup(&old_oid);
227 else if (!strcmp(key, "new-oid") && val &&
227 - !parse_oid_hex(val, &new_oid, &val))
228 + !parse_oid_hex_algop(val, &new_oid, &val, r->hash_algo))
229 report->new_oid = oiddup(&new_oid);
230 else if (!strcmp(key, "forced-update"))
231 report->forced_update = 1;
@@ -271,7 +272,7 @@ static int receive_status(struct packet_reader *reader, struct ref *refs)
272 new_report = 1;
273 }
274 }
274 - trace2_region_leave("send_pack", "receive_status", the_repository);
275 + trace2_region_leave("send_pack", "receive_status", r);
276 return ret;
277 }
278
@@ -293,9 +294,9 @@ static int advertise_shallow_grafts_cb(const struct commit_graft *graft, void *c
294 return 0;
295 }
296
296 -static void advertise_shallow_grafts_buf(struct strbuf *sb)
297 +static void advertise_shallow_grafts_buf(struct repository *r, struct strbuf *sb)
298 {
298 - if (!is_repository_shallow(the_repository))
299 + if (!is_repository_shallow(r))
300 return;
301 for_each_commit_graft(advertise_shallow_grafts_cb, sb);
302 }
@@ -426,13 +427,14 @@ static void reject_invalid_nonce(const char *nonce, int len)
427 }
428 }
429
429 -static void get_commons_through_negotiation(const char *url,
430 +static void get_commons_through_negotiation(struct repository *r,
431 + const char *url,
432 const struct ref *remote_refs,
433 struct oid_array *commons)
434 {
435 struct child_process child = CHILD_PROCESS_INIT;
436 const struct ref *ref;
435 - int len = the_hash_algo->hexsz + 1; /* hash + NL */
437 + int len = r->hash_algo->hexsz + 1; /* hash + NL */
438 int nr_negotiation_tip = 0;
439
440 child.git_cmd = 1;
@@ -466,7 +468,7 @@ static void get_commons_through_negotiation(const char *url,
468 break;
469 if (read_len != len)
470 die("invalid length read %d", read_len);
469 - if (parse_oid_hex(hex_hash, &oid, &end) || *end != '\n')
471 + if (parse_oid_hex_algop(hex_hash, &oid, &end, r->hash_algo) || *end != '\n')
472 die("invalid hash");
473 oid_array_append(commons, &oid);
474 } while (1);
@@ -480,7 +482,8 @@ static void get_commons_through_negotiation(const char *url,
482 }
483 }
484
483 -int send_pack(struct send_pack_args *args,
485 +int send_pack(struct repository *r,
486 + struct send_pack_args *args,
487 int fd[], struct child_process *conn,
488 struct ref *remote_refs,
489 struct oid_array *extra_have)
@@ -518,17 +521,17 @@ int send_pack(struct send_pack_args *args,
521 goto out;
522 }
523
521 - git_config_get_bool("push.negotiate", &push_negotiate);
524 + repo_config_get_bool(r, "push.negotiate", &push_negotiate);
525 if (push_negotiate) {
523 - trace2_region_enter("send_pack", "push_negotiate", the_repository);
524 - get_commons_through_negotiation(args->url, remote_refs, &commons);
525 - trace2_region_leave("send_pack", "push_negotiate", the_repository);
526 + trace2_region_enter("send_pack", "push_negotiate", r);
527 + get_commons_through_negotiation(r, args->url, remote_refs, &commons);
528 + trace2_region_leave("send_pack", "push_negotiate", r);
529 }
530
528 - if (!git_config_get_bool("push.usebitmaps", &use_bitmaps))
531 + if (!repo_config_get_bool(r, "push.usebitmaps", &use_bitmaps))
532 args->disable_bitmaps = !use_bitmaps;
533
531 - git_config_get_bool("transfer.advertisesid", &advertise_sid);
534 + repo_config_get_bool(r, "transfer.advertisesid", &advertise_sid);
535
536 /* Does the other end support the reporting? */
537 if (server_supports("report-status-v2"))
@@ -554,7 +557,7 @@ int send_pack(struct send_pack_args *args,
557 if (server_supports("push-options"))
558 push_options_supported = 1;
559
557 - if (!server_supports_hash(the_hash_algo->name, &object_format_supported))
560 + if (!server_supports_hash(r->hash_algo->name, &object_format_supported))
561 die(_("the receiving end does not support this repository's hash algorithm"));
562
563 if (args->push_cert != SEND_PACK_PUSH_CERT_NEVER) {
@@ -596,7 +599,7 @@ int send_pack(struct send_pack_args *args,
599 if (use_push_options)
600 strbuf_addstr(&cap_buf, " push-options");
601 if (object_format_supported)
599 - strbuf_addf(&cap_buf, " object-format=%s", the_hash_algo->name);
602 + strbuf_addf(&cap_buf, " object-format=%s", r->hash_algo->name);
603 if (agent_supported)
604 strbuf_addf(&cap_buf, " agent=%s", git_user_agent_sanitized());
605 if (advertise_sid)
@@ -646,7 +649,7 @@ int send_pack(struct send_pack_args *args,
649 }
650
651 if (!args->dry_run)
649 - advertise_shallow_grafts_buf(&req_buf);
652 + advertise_shallow_grafts_buf(r, &req_buf);
653
654 /*
655 * Finally, tell the other end!
@@ -686,7 +689,7 @@ int send_pack(struct send_pack_args *args,
689 }
690
691 if (args->stateless_rpc) {
689 - if (!args->dry_run && (cmds_sent || is_repository_shallow(the_repository))) {
692 + if (!args->dry_run && (cmds_sent || is_repository_shallow(r))) {
693 packet_buf_flush(&req_buf);
694 send_sideband(out, -1, req_buf.buf, req_buf.len, LARGE_PACKET_MAX);
695 }
@@ -711,7 +714,7 @@ int send_pack(struct send_pack_args *args,
714 PACKET_READ_DIE_ON_ERR_PACKET);
715
716 if (need_pack_data && cmds_sent) {
714 - if (pack_objects(out, remote_refs, extra_have, &commons, args) < 0) {
717 + if (pack_objects(r, out, remote_refs, extra_have, &commons, args) < 0) {
718 if (args->stateless_rpc)
719 close(out);
720 if (git_connection_is_socket(conn))
@@ -724,7 +727,7 @@ int send_pack(struct send_pack_args *args,
727 * we get one).
728 */
729 if (status_report)
727 - receive_status(&reader, remote_refs);
730 + receive_status(r, &reader, remote_refs);
731
732 if (use_sideband) {
733 close(demux.out);
@@ -743,7 +746,7 @@ int send_pack(struct send_pack_args *args,
746 packet_flush(out);
747
748 if (status_report && cmds_sent)
746 - ret = receive_status(&reader, remote_refs);
749 + ret = receive_status(r, &reader, remote_refs);
750 else
751 ret = 0;
752 if (args->stateless_rpc)
send-pack.h
+2 -1
@@ -6,6 +6,7 @@
6 struct child_process;
7 struct oid_array;
8 struct ref;
9 +struct repository;
10
11 /* Possible values for push_cert field in send_pack_args. */
12 #define SEND_PACK_PUSH_CERT_NEVER 0
@@ -35,7 +36,7 @@ struct option;
36 int option_parse_push_signed(const struct option *opt,
37 const char *arg, int unset);
38
38 -int send_pack(struct send_pack_args *args,
39 +int send_pack(struct repository *r, struct send_pack_args *args,
40 int fd[], struct child_process *conn,
41 struct ref *remote_refs, struct oid_array *extra_have);
42
transport.c
+1 -1
@@ -932,7 +932,7 @@ static int git_transport_push(struct transport *transport, struct ref *remote_re
932 break;
933 case protocol_v1:
934 case protocol_v0:
935 - ret = send_pack(&args, data->fd, data->conn, remote_refs,
935 + ret = send_pack(the_repository, &args, data->fd, data->conn, remote_refs,
936 &data->extra_have);
937 break;
938 case protocol_unknown_version: