1 #define USE_THE_REPOSITORY_VARIABLE
3 #include "git-compat-util.h"
6 #include "environment.h"
11 #include "fetch-pack.h"
14 #include "send-pack.h"
21 #include "submodule.h"
22 #include "string-list.h"
23 #include "oid-array.h"
26 #include "transport-internal.h"
28 #include "object-name.h"
30 #include "bundle-uri.h"
32 static int transport_use_color
= -1;
33 static char transport_colors
[][COLOR_MAXLEN
] = {
35 GIT_COLOR_RED
/* REJECTED */
38 enum color_transport
{
39 TRANSPORT_COLOR_RESET
= 0,
40 TRANSPORT_COLOR_REJECTED
= 1
43 static int transport_color_config(void)
45 const char *keys
[] = {
46 "color.transport.reset",
47 "color.transport.rejected"
48 }, *key
= "color.transport";
51 static int initialized
;
57 if (!git_config_get_string(key
, &value
))
58 transport_use_color
= git_config_colorbool(key
, value
);
60 if (!want_color_stderr(transport_use_color
))
63 for (i
= 0; i
< ARRAY_SIZE(keys
); i
++)
64 if (!git_config_get_string(keys
[i
], &value
)) {
66 return config_error_nonbool(keys
[i
]);
67 if (color_parse(value
, transport_colors
[i
]) < 0)
74 static const char *transport_get_color(enum color_transport ix
)
76 if (want_color_stderr(transport_use_color
))
77 return transport_colors
[ix
];
81 static void set_upstreams(struct transport
*transport
, struct ref
*refs
,
85 for (ref
= refs
; ref
; ref
= ref
->next
) {
86 const char *localname
;
88 const char *remotename
;
91 * Check suitability for tracking. Must be successful /
92 * already up-to-date ref create/modify (not delete).
94 if (ref
->status
!= REF_STATUS_OK
&&
95 ref
->status
!= REF_STATUS_UPTODATE
)
99 if (is_null_oid(&ref
->new_oid
))
102 /* Follow symbolic refs (mainly for HEAD). */
103 localname
= ref
->peer_ref
->name
;
104 remotename
= ref
->name
;
105 tmp
= refs_resolve_ref_unsafe(get_main_ref_store(the_repository
),
106 localname
, RESOLVE_REF_READING
,
108 if (tmp
&& flag
& REF_ISSYMREF
&&
109 starts_with(tmp
, "refs/heads/"))
112 /* Both source and destination must be local branches. */
113 if (!localname
|| !starts_with(localname
, "refs/heads/"))
115 if (!remotename
|| !starts_with(remotename
, "refs/heads/"))
119 int flag
= transport
->verbose
< 0 ? 0 : BRANCH_CONFIG_VERBOSE
;
120 install_branch_config(flag
, localname
+ 11,
121 transport
->remote
->name
, remotename
);
122 } else if (transport
->verbose
>= 0)
123 printf(_("Would set upstream of '%s' to '%s' of '%s'\n"),
124 localname
+ 11, remotename
+ 11,
125 transport
->remote
->name
);
129 struct bundle_transport_data
{
131 struct bundle_header header
;
132 unsigned get_refs_from_bundle_called
: 1;
135 static void get_refs_from_bundle_inner(struct transport
*transport
)
137 struct bundle_transport_data
*data
= transport
->data
;
139 data
->get_refs_from_bundle_called
= 1;
143 data
->fd
= read_bundle_header(transport
->url
, &data
->header
);
145 die(_("could not read bundle '%s'"), transport
->url
);
147 transport
->hash_algo
= data
->header
.hash_algo
;
150 static struct ref
*get_refs_from_bundle(struct transport
*transport
,
152 struct transport_ls_refs_options
*transport_options UNUSED
)
154 struct bundle_transport_data
*data
= transport
->data
;
155 struct ref
*result
= NULL
;
161 get_refs_from_bundle_inner(transport
);
163 for (i
= 0; i
< data
->header
.references
.nr
; i
++) {
164 struct string_list_item
*e
= data
->header
.references
.items
+ i
;
165 const char *name
= e
->string
;
166 struct ref
*ref
= alloc_ref(name
);
167 struct object_id
*oid
= e
->util
;
168 oidcpy(&ref
->old_oid
, oid
);
175 static int fetch_refs_from_bundle(struct transport
*transport
,
177 struct ref
**to_fetch UNUSED
)
179 struct bundle_transport_data
*data
= transport
->data
;
180 struct strvec extra_index_pack_args
= STRVEC_INIT
;
183 if (transport
->progress
)
184 strvec_push(&extra_index_pack_args
, "-v");
186 if (!data
->get_refs_from_bundle_called
)
187 get_refs_from_bundle_inner(transport
);
188 ret
= unbundle(the_repository
, &data
->header
, data
->fd
,
189 &extra_index_pack_args
,
190 fetch_pack_fsck_objects() ? VERIFY_BUNDLE_FSCK
: 0);
191 transport
->hash_algo
= data
->header
.hash_algo
;
193 strvec_clear(&extra_index_pack_args
);
197 static int close_bundle(struct transport
*transport
)
199 struct bundle_transport_data
*data
= transport
->data
;
202 bundle_header_release(&data
->header
);
207 struct git_transport_data
{
208 struct git_transport_options options
;
209 struct child_process
*conn
;
211 unsigned finished_handshake
: 1;
212 enum protocol_version version
;
213 struct oid_array extra_have
;
214 struct oid_array shallow
;
217 static int set_git_option(struct git_transport_options
*opts
,
218 const char *name
, const char *value
)
220 if (!strcmp(name
, TRANS_OPT_UPLOADPACK
)) {
221 opts
->uploadpack
= value
;
223 } else if (!strcmp(name
, TRANS_OPT_RECEIVEPACK
)) {
224 opts
->receivepack
= value
;
226 } else if (!strcmp(name
, TRANS_OPT_THIN
)) {
227 opts
->thin
= !!value
;
229 } else if (!strcmp(name
, TRANS_OPT_FOLLOWTAGS
)) {
230 opts
->followtags
= !!value
;
232 } else if (!strcmp(name
, TRANS_OPT_KEEP
)) {
233 opts
->keep
= !!value
;
235 } else if (!strcmp(name
, TRANS_OPT_UPDATE_SHALLOW
)) {
236 opts
->update_shallow
= !!value
;
238 } else if (!strcmp(name
, TRANS_OPT_DEPTH
)) {
243 opts
->depth
= strtol(value
, &end
, 0);
245 die(_("transport: invalid depth option '%s'"), value
);
248 } else if (!strcmp(name
, TRANS_OPT_DEEPEN_SINCE
)) {
249 opts
->deepen_since
= value
;
251 } else if (!strcmp(name
, TRANS_OPT_DEEPEN_NOT
)) {
252 opts
->deepen_not
= (const struct string_list
*)value
;
254 } else if (!strcmp(name
, TRANS_OPT_DEEPEN_RELATIVE
)) {
255 opts
->deepen_relative
= !!value
;
257 } else if (!strcmp(name
, TRANS_OPT_FROM_PROMISOR
)) {
258 opts
->from_promisor
= !!value
;
260 } else if (!strcmp(name
, TRANS_OPT_LIST_OBJECTS_FILTER
)) {
261 list_objects_filter_die_if_populated(&opts
->filter_options
);
262 parse_list_objects_filter(&opts
->filter_options
, value
);
264 } else if (!strcmp(name
, TRANS_OPT_REFETCH
)) {
265 opts
->refetch
= !!value
;
267 } else if (!strcmp(name
, TRANS_OPT_REJECT_SHALLOW
)) {
268 opts
->reject_shallow
= !!value
;
274 static int connect_setup(struct transport
*transport
, int for_push
)
276 struct git_transport_data
*data
= transport
->data
;
277 int flags
= transport
->verbose
> 0 ? CONNECT_VERBOSE
: 0;
282 switch (transport
->family
) {
283 case TRANSPORT_FAMILY_ALL
: break;
284 case TRANSPORT_FAMILY_IPV4
: flags
|= CONNECT_IPV4
; break;
285 case TRANSPORT_FAMILY_IPV6
: flags
|= CONNECT_IPV6
; break;
288 data
->conn
= git_connect(data
->fd
, transport
->url
,
293 data
->options
.receivepack
:
294 data
->options
.uploadpack
,
300 static void die_if_server_options(struct transport
*transport
)
302 if (!transport
->server_options
|| !transport
->server_options
->nr
)
304 advise(_("see protocol.version in 'git help config' for more details"));
305 die(_("server options require protocol version 2 or later"));
309 * Obtains the protocol version from the transport and writes it to
310 * transport->data->version, first connecting if not already connected.
312 * If the protocol version is one that allows skipping the listing of remote
313 * refs, and must_list_refs is 0, the listing of remote refs is skipped and
314 * this function returns NULL. Otherwise, this function returns the list of
317 static struct ref
*handshake(struct transport
*transport
, int for_push
,
318 struct transport_ls_refs_options
*options
,
321 struct git_transport_data
*data
= transport
->data
;
322 struct ref
*refs
= NULL
;
323 struct packet_reader reader
;
325 const char *server_sid
;
327 connect_setup(transport
, for_push
);
329 packet_reader_init(&reader
, data
->fd
[0], NULL
, 0,
330 PACKET_READ_CHOMP_NEWLINE
|
331 PACKET_READ_GENTLE_ON_EOF
|
332 PACKET_READ_DIE_ON_ERR_PACKET
);
334 data
->version
= discover_version(&reader
);
335 switch (data
->version
) {
337 if (server_feature_v2("session-id", &server_sid
))
338 trace2_data_string("transfer", NULL
, "server-sid", server_sid
);
340 get_remote_refs(data
->fd
[1], &reader
, &refs
, for_push
,
342 transport
->server_options
,
343 transport
->stateless_rpc
);
347 die_if_server_options(transport
);
348 get_remote_heads(&reader
, &refs
,
349 for_push
? REF_NORMAL
: 0,
352 server_sid
= server_feature_value("session-id", &sid_len
);
354 char *sid
= xstrndup(server_sid
, sid_len
);
355 trace2_data_string("transfer", NULL
, "server-sid", sid
);
359 case protocol_unknown_version
:
360 BUG("unknown protocol version");
362 data
->finished_handshake
= 1;
363 transport
->hash_algo
= reader
.hash_algo
;
365 if (reader
.line_peeked
)
366 BUG("buffer must be empty at the end of handshake()");
371 static struct ref
*get_refs_via_connect(struct transport
*transport
, int for_push
,
372 struct transport_ls_refs_options
*options
)
374 return handshake(transport
, for_push
, options
, 1);
377 static int get_bundle_uri(struct transport
*transport
)
379 struct git_transport_data
*data
= transport
->data
;
380 struct packet_reader reader
;
381 int stateless_rpc
= transport
->stateless_rpc
;
383 if (!transport
->bundles
) {
384 CALLOC_ARRAY(transport
->bundles
, 1);
385 init_bundle_list(transport
->bundles
);
388 if (!data
->finished_handshake
) {
389 struct ref
*refs
= handshake(transport
, 0, NULL
, 0);
396 * "Support" protocol v0 and v2 without bundle-uri support by
397 * silently degrading to a NOOP.
399 if (!server_supports_v2("bundle-uri"))
402 packet_reader_init(&reader
, data
->fd
[0], NULL
, 0,
403 PACKET_READ_CHOMP_NEWLINE
|
404 PACKET_READ_GENTLE_ON_EOF
);
406 return get_remote_bundle_uri(data
->fd
[1], &reader
,
407 transport
->bundles
, stateless_rpc
);
410 static int fetch_refs_via_pack(struct transport
*transport
,
411 int nr_heads
, struct ref
**to_fetch
)
414 struct git_transport_data
*data
= transport
->data
;
415 struct ref
*refs
= NULL
;
416 struct fetch_pack_args args
;
417 struct ref
*refs_tmp
= NULL
;
419 memset(&args
, 0, sizeof(args
));
420 args
.uploadpack
= data
->options
.uploadpack
;
421 args
.keep_pack
= data
->options
.keep
;
423 args
.use_thin_pack
= data
->options
.thin
;
424 args
.include_tag
= data
->options
.followtags
;
425 args
.verbose
= (transport
->verbose
> 1);
426 args
.quiet
= (transport
->verbose
< 0);
427 args
.no_progress
= !transport
->progress
;
428 args
.depth
= data
->options
.depth
;
429 args
.deepen_since
= data
->options
.deepen_since
;
430 args
.deepen_not
= data
->options
.deepen_not
;
431 args
.deepen_relative
= data
->options
.deepen_relative
;
432 args
.check_self_contained_and_connected
=
433 data
->options
.check_self_contained_and_connected
;
434 args
.cloning
= transport
->cloning
;
435 args
.update_shallow
= data
->options
.update_shallow
;
436 args
.from_promisor
= data
->options
.from_promisor
;
437 list_objects_filter_copy(&args
.filter_options
,
438 &data
->options
.filter_options
);
439 args
.refetch
= data
->options
.refetch
;
440 args
.stateless_rpc
= transport
->stateless_rpc
;
441 args
.server_options
= transport
->server_options
;
442 args
.negotiation_tips
= data
->options
.negotiation_tips
;
443 args
.reject_shallow_remote
= transport
->smart_options
->reject_shallow
;
445 if (!data
->finished_handshake
) {
447 int must_list_refs
= 0;
448 for (i
= 0; i
< nr_heads
; i
++) {
449 if (!to_fetch
[i
]->exact_oid
) {
454 refs_tmp
= handshake(transport
, 0, NULL
, must_list_refs
);
457 if (data
->version
== protocol_unknown_version
)
458 BUG("unknown protocol version");
459 else if (data
->version
<= protocol_v1
)
460 die_if_server_options(transport
);
462 if (data
->options
.acked_commits
) {
463 if (data
->version
< protocol_v2
) {
464 warning(_("--negotiate-only requires protocol v2"));
466 } else if (!server_supports_feature("fetch", "wait-for-done", 0)) {
467 warning(_("server does not support wait-for-done"));
470 negotiate_using_fetch(data
->options
.negotiation_tips
,
471 transport
->server_options
,
472 transport
->stateless_rpc
,
474 data
->options
.acked_commits
);
480 refs
= fetch_pack(&args
, data
->fd
,
481 refs_tmp
? refs_tmp
: transport
->remote_refs
,
482 to_fetch
, nr_heads
, &data
->shallow
,
483 &transport
->pack_lockfiles
, data
->version
);
485 data
->finished_handshake
= 0;
486 data
->options
.self_contained_and_connected
=
487 args
.self_contained_and_connected
;
488 data
->options
.connectivity_checked
= args
.connectivity_checked
;
492 if (report_unmatched_refs(to_fetch
, nr_heads
))
497 if (data
->fd
[1] >= 0)
499 if (finish_connect(data
->conn
))
505 list_objects_filter_release(&args
.filter_options
);
509 static int push_had_errors(struct ref
*ref
)
511 for (; ref
; ref
= ref
->next
) {
512 switch (ref
->status
) {
513 case REF_STATUS_NONE
:
514 case REF_STATUS_UPTODATE
:
524 int transport_refs_pushed(struct ref
*ref
)
526 for (; ref
; ref
= ref
->next
) {
527 switch(ref
->status
) {
528 case REF_STATUS_NONE
:
529 case REF_STATUS_UPTODATE
:
538 static void update_one_tracking_ref(struct remote
*remote
, char *refname
,
539 struct object_id
*new_oid
, int deletion
,
542 struct refspec_item rs
;
544 memset(&rs
, 0, sizeof(rs
));
548 if (!remote_find_tracking(remote
, &rs
)) {
550 fprintf(stderr
, "updating local tracking ref '%s'\n", rs
.dst
);
552 refs_delete_ref(get_main_ref_store(the_repository
),
553 NULL
, rs
.dst
, NULL
, 0);
555 refs_update_ref(get_main_ref_store(the_repository
),
556 "update by push", rs
.dst
, new_oid
,
562 void transport_update_tracking_ref(struct remote
*remote
, struct ref
*ref
, int verbose
)
565 struct object_id
*new_oid
;
566 struct ref_push_report
*report
;
568 if (ref
->status
!= REF_STATUS_OK
&& ref
->status
!= REF_STATUS_UPTODATE
)
571 report
= ref
->report
;
573 update_one_tracking_ref(remote
, ref
->name
, &ref
->new_oid
,
574 ref
->deletion
, verbose
);
576 for (; report
; report
= report
->next
) {
577 refname
= report
->ref_name
? (char *)report
->ref_name
: ref
->name
;
578 new_oid
= report
->new_oid
? report
->new_oid
: &ref
->new_oid
;
579 update_one_tracking_ref(remote
, refname
, new_oid
,
580 is_null_oid(new_oid
), verbose
);
584 static void print_ref_status(char flag
, const char *summary
,
585 struct ref
*to
, struct ref
*from
, const char *msg
,
586 struct ref_push_report
*report
,
587 int porcelain
, int summary_width
)
591 if (report
&& report
->ref_name
)
592 to_name
= report
->ref_name
;
598 fprintf(stdout
, "%c\t%s:%s\t", flag
, from
->name
, to_name
);
600 fprintf(stdout
, "%c\t:%s\t", flag
, to_name
);
602 fprintf(stdout
, "%s (%s)\n", summary
, msg
);
604 fprintf(stdout
, "%s\n", summary
);
606 const char *red
= "", *reset
= "";
607 if (push_had_errors(to
)) {
608 red
= transport_get_color(TRANSPORT_COLOR_REJECTED
);
609 reset
= transport_get_color(TRANSPORT_COLOR_RESET
);
611 fprintf(stderr
, " %s%c %-*s%s ", red
, flag
, summary_width
,
614 fprintf(stderr
, "%s -> %s",
615 prettify_refname(from
->name
),
616 prettify_refname(to_name
));
618 fputs(prettify_refname(to_name
), stderr
);
628 static void print_ok_ref_status(struct ref
*ref
,
629 struct ref_push_report
*report
,
630 int porcelain
, int summary_width
)
632 struct object_id
*old_oid
;
633 struct object_id
*new_oid
;
634 const char *ref_name
;
637 if (report
&& report
->old_oid
)
638 old_oid
= report
->old_oid
;
640 old_oid
= &ref
->old_oid
;
641 if (report
&& report
->new_oid
)
642 new_oid
= report
->new_oid
;
644 new_oid
= &ref
->new_oid
;
645 if (report
&& report
->forced_update
)
646 forced_update
= report
->forced_update
;
648 forced_update
= ref
->forced_update
;
649 if (report
&& report
->ref_name
)
650 ref_name
= report
->ref_name
;
652 ref_name
= ref
->name
;
655 print_ref_status('-', "[deleted]", ref
, NULL
, NULL
,
656 report
, porcelain
, summary_width
);
657 else if (is_null_oid(old_oid
))
658 print_ref_status('*',
659 (starts_with(ref_name
, "refs/tags/")
661 : (starts_with(ref_name
, "refs/heads/")
663 : "[new reference]")),
664 ref
, ref
->peer_ref
, NULL
,
665 report
, porcelain
, summary_width
);
667 struct strbuf quickref
= STRBUF_INIT
;
671 strbuf_add_unique_abbrev(&quickref
, old_oid
,
674 strbuf_addstr(&quickref
, "...");
676 msg
= "forced update";
678 strbuf_addstr(&quickref
, "..");
682 strbuf_add_unique_abbrev(&quickref
, new_oid
,
685 print_ref_status(type
, quickref
.buf
, ref
, ref
->peer_ref
, msg
,
686 report
, porcelain
, summary_width
);
687 strbuf_release(&quickref
);
691 static int print_one_push_report(struct ref
*ref
, const char *dest
, int count
,
692 struct ref_push_report
*report
,
693 int porcelain
, int summary_width
)
696 char *url
= transport_anonymize_url(dest
);
697 fprintf(porcelain
? stdout
: stderr
, "To %s\n", url
);
701 switch(ref
->status
) {
702 case REF_STATUS_NONE
:
703 print_ref_status('X', "[no match]", ref
, NULL
, NULL
,
704 report
, porcelain
, summary_width
);
706 case REF_STATUS_REJECT_NODELETE
:
707 print_ref_status('!', "[rejected]", ref
, NULL
,
708 "remote does not support deleting refs",
709 report
, porcelain
, summary_width
);
711 case REF_STATUS_UPTODATE
:
712 print_ref_status('=', "[up to date]", ref
,
714 report
, porcelain
, summary_width
);
716 case REF_STATUS_REJECT_NONFASTFORWARD
:
717 print_ref_status('!', "[rejected]", ref
, ref
->peer_ref
,
719 report
, porcelain
, summary_width
);
721 case REF_STATUS_REJECT_ALREADY_EXISTS
:
722 print_ref_status('!', "[rejected]", ref
, ref
->peer_ref
,
724 report
, porcelain
, summary_width
);
726 case REF_STATUS_REJECT_FETCH_FIRST
:
727 print_ref_status('!', "[rejected]", ref
, ref
->peer_ref
,
729 report
, porcelain
, summary_width
);
731 case REF_STATUS_REJECT_NEEDS_FORCE
:
732 print_ref_status('!', "[rejected]", ref
, ref
->peer_ref
,
734 report
, porcelain
, summary_width
);
736 case REF_STATUS_REJECT_STALE
:
737 print_ref_status('!', "[rejected]", ref
, ref
->peer_ref
,
739 report
, porcelain
, summary_width
);
741 case REF_STATUS_REJECT_REMOTE_UPDATED
:
742 print_ref_status('!', "[rejected]", ref
, ref
->peer_ref
,
743 "remote ref updated since checkout",
744 report
, porcelain
, summary_width
);
746 case REF_STATUS_REJECT_SHALLOW
:
747 print_ref_status('!', "[rejected]", ref
, ref
->peer_ref
,
748 "new shallow roots not allowed",
749 report
, porcelain
, summary_width
);
751 case REF_STATUS_REMOTE_REJECT
:
752 print_ref_status('!', "[remote rejected]", ref
,
753 ref
->deletion
? NULL
: ref
->peer_ref
,
755 report
, porcelain
, summary_width
);
757 case REF_STATUS_EXPECTING_REPORT
:
758 print_ref_status('!', "[remote failure]", ref
,
759 ref
->deletion
? NULL
: ref
->peer_ref
,
760 "remote failed to report status",
761 report
, porcelain
, summary_width
);
763 case REF_STATUS_ATOMIC_PUSH_FAILED
:
764 print_ref_status('!', "[rejected]", ref
, ref
->peer_ref
,
765 "atomic push failed",
766 report
, porcelain
, summary_width
);
769 print_ok_ref_status(ref
, report
, porcelain
, summary_width
);
776 static int print_one_push_status(struct ref
*ref
, const char *dest
, int count
,
777 int porcelain
, int summary_width
)
779 struct ref_push_report
*report
;
783 return print_one_push_report(ref
, dest
, count
,
784 NULL
, porcelain
, summary_width
);
786 for (report
= ref
->report
; report
; report
= report
->next
)
787 print_one_push_report(ref
, dest
, count
+ n
++,
788 report
, porcelain
, summary_width
);
792 static int measure_abbrev(const struct object_id
*oid
, int sofar
)
794 char hex
[GIT_MAX_HEXSZ
+ 1];
795 int w
= repo_find_unique_abbrev_r(the_repository
, hex
, oid
,
798 return (w
< sofar
) ? sofar
: w
;
801 int transport_summary_width(const struct ref
*refs
)
805 for (; refs
; refs
= refs
->next
) {
806 maxw
= measure_abbrev(&refs
->old_oid
, maxw
);
807 maxw
= measure_abbrev(&refs
->new_oid
, maxw
);
810 maxw
= FALLBACK_DEFAULT_ABBREV
;
811 return (2 * maxw
+ 3);
814 void transport_print_push_status(const char *dest
, struct ref
*refs
,
815 int verbose
, int porcelain
, unsigned int *reject_reasons
)
820 int summary_width
= transport_summary_width(refs
);
822 if (transport_color_config() < 0)
823 warning(_("could not parse transport.color.* config"));
825 head
= refs_resolve_refdup(get_main_ref_store(the_repository
), "HEAD",
826 RESOLVE_REF_READING
, NULL
, NULL
);
829 for (ref
= refs
; ref
; ref
= ref
->next
)
830 if (ref
->status
== REF_STATUS_UPTODATE
)
831 n
+= print_one_push_status(ref
, dest
, n
,
832 porcelain
, summary_width
);
835 for (ref
= refs
; ref
; ref
= ref
->next
)
836 if (ref
->status
== REF_STATUS_OK
)
837 n
+= print_one_push_status(ref
, dest
, n
,
838 porcelain
, summary_width
);
841 for (ref
= refs
; ref
; ref
= ref
->next
) {
842 if (ref
->status
!= REF_STATUS_NONE
&&
843 ref
->status
!= REF_STATUS_UPTODATE
&&
844 ref
->status
!= REF_STATUS_OK
)
845 n
+= print_one_push_status(ref
, dest
, n
,
846 porcelain
, summary_width
);
847 if (ref
->status
== REF_STATUS_REJECT_NONFASTFORWARD
) {
848 if (head
!= NULL
&& !strcmp(head
, ref
->name
))
849 *reject_reasons
|= REJECT_NON_FF_HEAD
;
851 *reject_reasons
|= REJECT_NON_FF_OTHER
;
852 } else if (ref
->status
== REF_STATUS_REJECT_ALREADY_EXISTS
) {
853 *reject_reasons
|= REJECT_ALREADY_EXISTS
;
854 } else if (ref
->status
== REF_STATUS_REJECT_FETCH_FIRST
) {
855 *reject_reasons
|= REJECT_FETCH_FIRST
;
856 } else if (ref
->status
== REF_STATUS_REJECT_NEEDS_FORCE
) {
857 *reject_reasons
|= REJECT_NEEDS_FORCE
;
858 } else if (ref
->status
== REF_STATUS_REJECT_REMOTE_UPDATED
) {
859 *reject_reasons
|= REJECT_REF_NEEDS_UPDATE
;
865 static int git_transport_push(struct transport
*transport
, struct ref
*remote_refs
, int flags
)
867 struct git_transport_data
*data
= transport
->data
;
868 struct send_pack_args args
;
871 if (transport_color_config() < 0)
874 if (!data
->finished_handshake
)
875 get_refs_via_connect(transport
, 1, NULL
);
877 memset(&args
, 0, sizeof(args
));
878 args
.send_mirror
= !!(flags
& TRANSPORT_PUSH_MIRROR
);
879 args
.force_update
= !!(flags
& TRANSPORT_PUSH_FORCE
);
880 args
.use_thin_pack
= data
->options
.thin
;
881 args
.verbose
= (transport
->verbose
> 0);
882 args
.quiet
= (transport
->verbose
< 0);
883 args
.progress
= transport
->progress
;
884 args
.dry_run
= !!(flags
& TRANSPORT_PUSH_DRY_RUN
);
885 args
.porcelain
= !!(flags
& TRANSPORT_PUSH_PORCELAIN
);
886 args
.atomic
= !!(flags
& TRANSPORT_PUSH_ATOMIC
);
887 args
.push_options
= transport
->push_options
;
888 args
.url
= transport
->url
;
890 if (flags
& TRANSPORT_PUSH_CERT_ALWAYS
)
891 args
.push_cert
= SEND_PACK_PUSH_CERT_ALWAYS
;
892 else if (flags
& TRANSPORT_PUSH_CERT_IF_ASKED
)
893 args
.push_cert
= SEND_PACK_PUSH_CERT_IF_ASKED
;
895 args
.push_cert
= SEND_PACK_PUSH_CERT_NEVER
;
897 switch (data
->version
) {
899 die(_("support for protocol v2 not implemented yet"));
903 ret
= send_pack(&args
, data
->fd
, data
->conn
, remote_refs
,
906 case protocol_unknown_version
:
907 BUG("unknown protocol version");
913 * Atomic push may abort the connection early and close the pipe,
914 * which may cause an error for `finish_connect()`. Ignore this error
915 * for atomic git-push.
917 if (ret
|| args
.atomic
)
918 finish_connect(data
->conn
);
920 ret
= finish_connect(data
->conn
);
922 data
->finished_handshake
= 0;
927 static int connect_git(struct transport
*transport
, const char *name
,
928 const char *executable
, int fd
[2])
930 struct git_transport_data
*data
= transport
->data
;
931 data
->conn
= git_connect(data
->fd
, transport
->url
,
932 name
, executable
, 0);
938 static int disconnect_git(struct transport
*transport
)
940 struct git_transport_data
*data
= transport
->data
;
942 if (data
->finished_handshake
&& !transport
->stateless_rpc
)
943 packet_flush(data
->fd
[1]);
945 if (data
->fd
[1] >= 0)
947 finish_connect(data
->conn
);
950 if (data
->options
.negotiation_tips
) {
951 oid_array_clear(data
->options
.negotiation_tips
);
952 free(data
->options
.negotiation_tips
);
954 list_objects_filter_release(&data
->options
.filter_options
);
955 oid_array_clear(&data
->extra_have
);
956 oid_array_clear(&data
->shallow
);
961 static struct transport_vtable taken_over_vtable
= {
962 .get_refs_list
= get_refs_via_connect
,
963 .get_bundle_uri
= get_bundle_uri
,
964 .fetch_refs
= fetch_refs_via_pack
,
965 .push_refs
= git_transport_push
,
966 .disconnect
= disconnect_git
969 void transport_take_over(struct transport
*transport
,
970 struct child_process
*child
)
972 struct git_transport_data
*data
;
974 if (!transport
->smart_options
)
975 BUG("taking over transport requires non-NULL "
976 "smart_options field.");
978 CALLOC_ARRAY(data
, 1);
979 data
->options
= *transport
->smart_options
;
981 data
->fd
[0] = data
->conn
->out
;
982 data
->fd
[1] = data
->conn
->in
;
983 data
->finished_handshake
= 0;
984 transport
->data
= data
;
986 transport
->vtable
= &taken_over_vtable
;
987 transport
->smart_options
= &(data
->options
);
989 transport
->cannot_reuse
= 1;
992 static int is_file(const char *url
)
997 return S_ISREG(buf
.st_mode
);
1000 static int external_specification_len(const char *url
)
1002 return strchr(url
, ':') - url
;
1005 static const struct string_list
*protocol_allow_list(void)
1007 static int enabled
= -1;
1008 static struct string_list allowed
= STRING_LIST_INIT_DUP
;
1011 const char *v
= getenv("GIT_ALLOW_PROTOCOL");
1013 string_list_split(&allowed
, v
, ':', -1);
1014 string_list_sort(&allowed
);
1021 return enabled
? &allowed
: NULL
;
1024 enum protocol_allow_config
{
1025 PROTOCOL_ALLOW_NEVER
= 0,
1026 PROTOCOL_ALLOW_USER_ONLY
,
1027 PROTOCOL_ALLOW_ALWAYS
1030 static enum protocol_allow_config
parse_protocol_config(const char *key
,
1033 if (!strcasecmp(value
, "always"))
1034 return PROTOCOL_ALLOW_ALWAYS
;
1035 else if (!strcasecmp(value
, "never"))
1036 return PROTOCOL_ALLOW_NEVER
;
1037 else if (!strcasecmp(value
, "user"))
1038 return PROTOCOL_ALLOW_USER_ONLY
;
1040 die(_("unknown value for config '%s': %s"), key
, value
);
1043 static enum protocol_allow_config
get_protocol_config(const char *type
)
1045 char *key
= xstrfmt("protocol.%s.allow", type
);
1048 /* first check the per-protocol config */
1049 if (!git_config_get_string(key
, &value
)) {
1050 enum protocol_allow_config ret
=
1051 parse_protocol_config(key
, value
);
1058 /* if defined, fallback to user-defined default for unknown protocols */
1059 if (!git_config_get_string("protocol.allow", &value
)) {
1060 enum protocol_allow_config ret
=
1061 parse_protocol_config("protocol.allow", value
);
1066 /* fallback to built-in defaults */
1068 if (!strcmp(type
, "http") ||
1069 !strcmp(type
, "https") ||
1070 !strcmp(type
, "git") ||
1071 !strcmp(type
, "ssh"))
1072 return PROTOCOL_ALLOW_ALWAYS
;
1074 /* known scary; err on the side of caution */
1075 if (!strcmp(type
, "ext"))
1076 return PROTOCOL_ALLOW_NEVER
;
1078 /* unknown; by default let them be used only directly by the user */
1079 return PROTOCOL_ALLOW_USER_ONLY
;
1082 int is_transport_allowed(const char *type
, int from_user
)
1084 const struct string_list
*allow_list
= protocol_allow_list();
1086 return string_list_has_string(allow_list
, type
);
1088 switch (get_protocol_config(type
)) {
1089 case PROTOCOL_ALLOW_ALWAYS
:
1091 case PROTOCOL_ALLOW_NEVER
:
1093 case PROTOCOL_ALLOW_USER_ONLY
:
1095 from_user
= git_env_bool("GIT_PROTOCOL_FROM_USER", 1);
1099 BUG("invalid protocol_allow_config type");
1102 void transport_check_allowed(const char *type
)
1104 if (!is_transport_allowed(type
, -1))
1105 die(_("transport '%s' not allowed"), type
);
1108 static struct transport_vtable bundle_vtable
= {
1109 .get_refs_list
= get_refs_from_bundle
,
1110 .fetch_refs
= fetch_refs_from_bundle
,
1111 .disconnect
= close_bundle
1114 static struct transport_vtable builtin_smart_vtable
= {
1115 .get_refs_list
= get_refs_via_connect
,
1116 .get_bundle_uri
= get_bundle_uri
,
1117 .fetch_refs
= fetch_refs_via_pack
,
1118 .push_refs
= git_transport_push
,
1119 .connect
= connect_git
,
1120 .disconnect
= disconnect_git
1123 struct transport
*transport_get(struct remote
*remote
, const char *url
)
1126 char *helper_to_free
= NULL
;
1128 struct transport
*ret
= xcalloc(1, sizeof(*ret
));
1130 ret
->progress
= isatty(2);
1131 string_list_init_dup(&ret
->pack_lockfiles
);
1133 CALLOC_ARRAY(ret
->bundles
, 1);
1134 init_bundle_list(ret
->bundles
);
1137 BUG("No remote provided to transport_get()");
1139 ret
->got_remote_refs
= 0;
1140 ret
->remote
= remote
;
1141 helper
= remote
->foreign_vcs
;
1144 url
= remote
->url
.v
[0];
1148 while (is_urlschemechar(p
== url
, *p
))
1150 if (starts_with(p
, "::"))
1151 helper
= helper_to_free
= xstrndup(url
, p
- url
);
1154 transport_helper_init(ret
, helper
);
1155 free(helper_to_free
);
1156 } else if (starts_with(url
, "rsync:")) {
1157 die(_("git-over-rsync is no longer supported"));
1158 } else if (url_is_local_not_ssh(url
) && is_file(url
) && is_bundle(url
, 1)) {
1159 struct bundle_transport_data
*data
= xcalloc(1, sizeof(*data
));
1160 bundle_header_init(&data
->header
);
1161 transport_check_allowed("file");
1163 ret
->vtable
= &bundle_vtable
;
1164 ret
->smart_options
= NULL
;
1165 } else if (!is_url(url
)
1166 || starts_with(url
, "file://")
1167 || starts_with(url
, "git://")
1168 || starts_with(url
, "ssh://")
1169 || starts_with(url
, "git+ssh://") /* deprecated - do not use */
1170 || starts_with(url
, "ssh+git://") /* deprecated - do not use */
1173 * These are builtin smart transports; "allowed" transports
1174 * will be checked individually in git_connect.
1176 struct git_transport_data
*data
= xcalloc(1, sizeof(*data
));
1177 list_objects_filter_init(&data
->options
.filter_options
);
1179 ret
->vtable
= &builtin_smart_vtable
;
1180 ret
->smart_options
= &(data
->options
);
1183 data
->finished_handshake
= 0;
1185 /* Unknown protocol in URL. Pass to external handler. */
1186 int len
= external_specification_len(url
);
1187 char *handler
= xmemdupz(url
, len
);
1188 transport_helper_init(ret
, handler
);
1192 if (ret
->smart_options
) {
1193 ret
->smart_options
->thin
= 1;
1194 ret
->smart_options
->uploadpack
= "git-upload-pack";
1195 if (remote
->uploadpack
)
1196 ret
->smart_options
->uploadpack
= remote
->uploadpack
;
1197 ret
->smart_options
->receivepack
= "git-receive-pack";
1198 if (remote
->receivepack
)
1199 ret
->smart_options
->receivepack
= remote
->receivepack
;
1202 ret
->hash_algo
= &hash_algos
[GIT_HASH_SHA1
];
1207 const struct git_hash_algo
*transport_get_hash_algo(struct transport
*transport
)
1209 return transport
->hash_algo
;
1212 int transport_set_option(struct transport
*transport
,
1213 const char *name
, const char *value
)
1215 int git_reports
= 1, protocol_reports
= 1;
1217 if (transport
->smart_options
)
1218 git_reports
= set_git_option(transport
->smart_options
,
1221 if (transport
->vtable
->set_option
)
1222 protocol_reports
= transport
->vtable
->set_option(transport
,
1225 /* If either report is 0, report 0 (success). */
1226 if (!git_reports
|| !protocol_reports
)
1228 /* If either reports -1 (invalid value), report -1. */
1229 if ((git_reports
== -1) || (protocol_reports
== -1))
1231 /* Otherwise if both report unknown, report unknown. */
1235 void transport_set_verbosity(struct transport
*transport
, int verbosity
,
1239 transport
->verbose
= verbosity
<= 3 ? verbosity
: 3;
1241 transport
->verbose
= -1;
1244 * Rules used to determine whether to report progress (processing aborts
1245 * when a rule is satisfied):
1247 * . Report progress, if force_progress is 1 (ie. --progress).
1248 * . Don't report progress, if force_progress is 0 (ie. --no-progress).
1249 * . Don't report progress, if verbosity < 0 (ie. -q/--quiet ).
1250 * . Report progress if isatty(2) is 1.
1252 if (force_progress
>= 0)
1253 transport
->progress
= !!force_progress
;
1255 transport
->progress
= verbosity
>= 0 && isatty(2);
1258 static void die_with_unpushed_submodules(struct string_list
*needs_pushing
)
1262 fprintf(stderr
, _("The following submodule paths contain changes that can\n"
1263 "not be found on any remote:\n"));
1264 for (i
= 0; i
< needs_pushing
->nr
; i
++)
1265 fprintf(stderr
, " %s\n", needs_pushing
->items
[i
].string
);
1266 fprintf(stderr
, _("\nPlease try\n\n"
1267 " git push --recurse-submodules=on-demand\n\n"
1268 "or cd to the path and use\n\n"
1270 "to push them to a remote.\n\n"));
1272 string_list_clear(needs_pushing
, 0);
1274 die(_("Aborting."));
1277 static int run_pre_push_hook(struct transport
*transport
,
1278 struct ref
*remote_refs
)
1282 struct child_process proc
= CHILD_PROCESS_INIT
;
1284 const char *hook_path
= find_hook(the_repository
, "pre-push");
1289 strvec_push(&proc
.args
, hook_path
);
1290 strvec_push(&proc
.args
, transport
->remote
->name
);
1291 strvec_push(&proc
.args
, transport
->url
);
1294 proc
.trace2_hook_name
= "pre-push";
1296 if (start_command(&proc
)) {
1297 finish_command(&proc
);
1301 sigchain_push(SIGPIPE
, SIG_IGN
);
1303 strbuf_init(&buf
, 256);
1305 for (r
= remote_refs
; r
; r
= r
->next
) {
1306 if (!r
->peer_ref
) continue;
1307 if (r
->status
== REF_STATUS_REJECT_NONFASTFORWARD
) continue;
1308 if (r
->status
== REF_STATUS_REJECT_STALE
) continue;
1309 if (r
->status
== REF_STATUS_REJECT_REMOTE_UPDATED
) continue;
1310 if (r
->status
== REF_STATUS_UPTODATE
) continue;
1313 strbuf_addf( &buf
, "%s %s %s %s\n",
1314 r
->peer_ref
->name
, oid_to_hex(&r
->new_oid
),
1315 r
->name
, oid_to_hex(&r
->old_oid
));
1317 if (write_in_full(proc
.in
, buf
.buf
, buf
.len
) < 0) {
1318 /* We do not mind if a hook does not read all refs. */
1325 strbuf_release(&buf
);
1331 sigchain_pop(SIGPIPE
);
1333 x
= finish_command(&proc
);
1340 int transport_push(struct repository
*r
,
1341 struct transport
*transport
,
1342 struct refspec
*rs
, int flags
,
1343 unsigned int *reject_reasons
)
1345 struct ref
*remote_refs
= NULL
;
1346 struct ref
*local_refs
= NULL
;
1347 int match_flags
= MATCH_REFS_NONE
;
1348 int verbose
= (transport
->verbose
> 0);
1349 int quiet
= (transport
->verbose
< 0);
1350 int porcelain
= flags
& TRANSPORT_PUSH_PORCELAIN
;
1351 int pretend
= flags
& TRANSPORT_PUSH_DRY_RUN
;
1354 struct transport_ls_refs_options transport_options
=
1355 TRANSPORT_LS_REFS_OPTIONS_INIT
;
1357 *reject_reasons
= 0;
1359 if (transport_color_config() < 0)
1362 if (!transport
->vtable
->push_refs
)
1365 local_refs
= get_local_heads();
1367 if (check_push_refs(local_refs
, rs
) < 0)
1370 refspec_ref_prefixes(rs
, &transport_options
.ref_prefixes
);
1372 trace2_region_enter("transport_push", "get_refs_list", r
);
1373 remote_refs
= transport
->vtable
->get_refs_list(transport
, 1,
1374 &transport_options
);
1375 trace2_region_leave("transport_push", "get_refs_list", r
);
1377 transport_ls_refs_options_release(&transport_options
);
1379 if (flags
& TRANSPORT_PUSH_ALL
)
1380 match_flags
|= MATCH_REFS_ALL
;
1381 if (flags
& TRANSPORT_PUSH_MIRROR
)
1382 match_flags
|= MATCH_REFS_MIRROR
;
1383 if (flags
& TRANSPORT_PUSH_PRUNE
)
1384 match_flags
|= MATCH_REFS_PRUNE
;
1385 if (flags
& TRANSPORT_PUSH_FOLLOW_TAGS
)
1386 match_flags
|= MATCH_REFS_FOLLOW_TAGS
;
1388 if (match_push_refs(local_refs
, &remote_refs
, rs
, match_flags
))
1391 if (transport
->smart_options
&&
1392 transport
->smart_options
->cas
&&
1393 !is_empty_cas(transport
->smart_options
->cas
))
1394 apply_push_cas(transport
->smart_options
->cas
,
1395 transport
->remote
, remote_refs
);
1397 set_ref_status_for_push(remote_refs
,
1398 flags
& TRANSPORT_PUSH_MIRROR
,
1399 flags
& TRANSPORT_PUSH_FORCE
);
1401 if (!(flags
& TRANSPORT_PUSH_NO_HOOK
))
1402 if (run_pre_push_hook(transport
, remote_refs
))
1405 if ((flags
& (TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND
|
1406 TRANSPORT_RECURSE_SUBMODULES_ONLY
)) &&
1407 !is_bare_repository()) {
1408 struct ref
*ref
= remote_refs
;
1409 struct oid_array commits
= OID_ARRAY_INIT
;
1411 trace2_region_enter("transport_push", "push_submodules", r
);
1412 for (; ref
; ref
= ref
->next
)
1413 if (!is_null_oid(&ref
->new_oid
))
1414 oid_array_append(&commits
,
1417 if (!push_unpushed_submodules(r
,
1421 transport
->push_options
,
1423 oid_array_clear(&commits
);
1424 trace2_region_leave("transport_push", "push_submodules", r
);
1425 die(_("failed to push all needed submodules"));
1427 oid_array_clear(&commits
);
1428 trace2_region_leave("transport_push", "push_submodules", r
);
1431 if (((flags
& TRANSPORT_RECURSE_SUBMODULES_CHECK
) ||
1432 ((flags
& (TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND
|
1433 TRANSPORT_RECURSE_SUBMODULES_ONLY
)) &&
1434 !pretend
)) && !is_bare_repository()) {
1435 struct ref
*ref
= remote_refs
;
1436 struct string_list needs_pushing
= STRING_LIST_INIT_DUP
;
1437 struct oid_array commits
= OID_ARRAY_INIT
;
1439 trace2_region_enter("transport_push", "check_submodules", r
);
1440 for (; ref
; ref
= ref
->next
)
1441 if (!is_null_oid(&ref
->new_oid
))
1442 oid_array_append(&commits
,
1445 if (find_unpushed_submodules(r
,
1447 transport
->remote
->name
,
1449 oid_array_clear(&commits
);
1450 trace2_region_leave("transport_push", "check_submodules", r
);
1451 die_with_unpushed_submodules(&needs_pushing
);
1453 string_list_clear(&needs_pushing
, 0);
1454 oid_array_clear(&commits
);
1455 trace2_region_leave("transport_push", "check_submodules", r
);
1458 if (!(flags
& TRANSPORT_RECURSE_SUBMODULES_ONLY
)) {
1459 trace2_region_enter("transport_push", "push_refs", r
);
1460 push_ret
= transport
->vtable
->push_refs(transport
, remote_refs
, flags
);
1461 trace2_region_leave("transport_push", "push_refs", r
);
1464 err
= push_had_errors(remote_refs
);
1465 ret
= push_ret
| err
;
1468 transport_print_push_status(transport
->url
, remote_refs
,
1469 verbose
| porcelain
, porcelain
,
1472 if (flags
& TRANSPORT_PUSH_SET_UPSTREAM
)
1473 set_upstreams(transport
, remote_refs
, pretend
);
1475 if (!(flags
& (TRANSPORT_PUSH_DRY_RUN
|
1476 TRANSPORT_RECURSE_SUBMODULES_ONLY
))) {
1478 for (ref
= remote_refs
; ref
; ref
= ref
->next
)
1479 transport_update_tracking_ref(transport
->remote
, ref
, verbose
);
1482 if (porcelain
&& !push_ret
)
1484 else if (!quiet
&& !ret
&& !transport_refs_pushed(remote_refs
))
1485 /* stable plumbing output; do not modify or localize */
1486 fprintf(stderr
, "Everything up-to-date\n");
1489 free_refs(local_refs
);
1490 free_refs(remote_refs
);
1494 const struct ref
*transport_get_remote_refs(struct transport
*transport
,
1495 struct transport_ls_refs_options
*transport_options
)
1497 if (!transport
->got_remote_refs
) {
1498 transport
->remote_refs
=
1499 transport
->vtable
->get_refs_list(transport
, 0,
1501 transport
->got_remote_refs
= 1;
1504 return transport
->remote_refs
;
1507 void transport_ls_refs_options_release(struct transport_ls_refs_options
*opts
)
1509 strvec_clear(&opts
->ref_prefixes
);
1510 free((char *)opts
->unborn_head_target
);
1513 int transport_fetch_refs(struct transport
*transport
, struct ref
*refs
)
1516 int nr_heads
= 0, nr_alloc
= 0, nr_refs
= 0;
1517 struct ref
**heads
= NULL
;
1520 for (rm
= refs
; rm
; rm
= rm
->next
) {
1523 !is_null_oid(&rm
->old_oid
) &&
1524 oideq(&rm
->peer_ref
->old_oid
, &rm
->old_oid
))
1526 ALLOC_GROW(heads
, nr_heads
+ 1, nr_alloc
);
1527 heads
[nr_heads
++] = rm
;
1532 * When deepening of a shallow repository is requested,
1533 * then local and remote refs are likely to still be equal.
1534 * Just feed them all to the fetch method in that case.
1535 * This condition shouldn't be met in a non-deepening fetch
1536 * (see builtin/fetch.c:quickfetch()).
1538 ALLOC_ARRAY(heads
, nr_refs
);
1539 for (rm
= refs
; rm
; rm
= rm
->next
)
1540 heads
[nr_heads
++] = rm
;
1543 rc
= transport
->vtable
->fetch_refs(transport
, nr_heads
, heads
);
1549 int transport_get_remote_bundle_uri(struct transport
*transport
)
1552 const struct transport_vtable
*vtable
= transport
->vtable
;
1554 /* Check config only once. */
1555 if (transport
->got_remote_bundle_uri
)
1557 transport
->got_remote_bundle_uri
= 1;
1560 * Don't request bundle-uri from the server unless configured to
1561 * do so by the transfer.bundleURI=true config option.
1563 if (git_config_get_bool("transfer.bundleuri", &value
) || !value
)
1566 if (!transport
->bundles
->baseURI
)
1567 transport
->bundles
->baseURI
= xstrdup(transport
->url
);
1569 if (!vtable
->get_bundle_uri
)
1570 return error(_("bundle-uri operation not supported by protocol"));
1572 if (vtable
->get_bundle_uri(transport
) < 0)
1573 return error(_("could not retrieve server-advertised bundle-uri list"));
1577 void transport_unlock_pack(struct transport
*transport
, unsigned int flags
)
1579 int in_signal_handler
= !!(flags
& TRANSPORT_UNLOCK_PACK_IN_SIGNAL_HANDLER
);
1582 for (i
= 0; i
< transport
->pack_lockfiles
.nr
; i
++)
1583 if (in_signal_handler
)
1584 unlink(transport
->pack_lockfiles
.items
[i
].string
);
1586 unlink_or_warn(transport
->pack_lockfiles
.items
[i
].string
);
1587 if (!in_signal_handler
)
1588 string_list_clear(&transport
->pack_lockfiles
, 0);
1591 int transport_connect(struct transport
*transport
, const char *name
,
1592 const char *exec
, int fd
[2])
1594 if (transport
->vtable
->connect
)
1595 return transport
->vtable
->connect(transport
, name
, exec
, fd
);
1597 die(_("operation not supported by protocol"));
1600 int transport_disconnect(struct transport
*transport
)
1603 if (transport
->vtable
->disconnect
)
1604 ret
= transport
->vtable
->disconnect(transport
);
1605 if (transport
->got_remote_refs
)
1606 free_refs((void *)transport
->remote_refs
);
1607 clear_bundle_list(transport
->bundles
);
1608 free(transport
->bundles
);
1614 * Strip username (and password) from a URL and return
1615 * it in a newly allocated string.
1617 char *transport_anonymize_url(const char *url
)
1619 char *scheme_prefix
, *anon_part
;
1620 size_t anon_len
, prefix_len
= 0;
1622 anon_part
= strchr(url
, '@');
1623 if (url_is_local_not_ssh(url
) || !anon_part
)
1626 anon_len
= strlen(++anon_part
);
1627 scheme_prefix
= strstr(url
, "://");
1628 if (!scheme_prefix
) {
1629 if (!strchr(anon_part
, ':'))
1630 /* cannot be "me@there:/path/name" */
1634 /* make sure scheme is reasonable */
1635 for (cp
= url
; cp
< scheme_prefix
; cp
++) {
1638 case '+': case '.': case '-':
1647 /* @ past the first slash does not count */
1648 cp
= strchr(scheme_prefix
+ 3, '/');
1649 if (cp
&& cp
< anon_part
)
1651 prefix_len
= scheme_prefix
- url
+ 3;
1653 return xstrfmt("%.*s%.*s", (int)prefix_len
, url
,
1654 (int)anon_len
, anon_part
);
1656 return xstrdup(url
);