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
;
195 static int close_bundle(struct transport
*transport
)
197 struct bundle_transport_data
*data
= transport
->data
;
200 bundle_header_release(&data
->header
);
205 struct git_transport_data
{
206 struct git_transport_options options
;
207 struct child_process
*conn
;
209 unsigned finished_handshake
: 1;
210 enum protocol_version version
;
211 struct oid_array extra_have
;
212 struct oid_array shallow
;
215 static int set_git_option(struct git_transport_options
*opts
,
216 const char *name
, const char *value
)
218 if (!strcmp(name
, TRANS_OPT_UPLOADPACK
)) {
219 opts
->uploadpack
= value
;
221 } else if (!strcmp(name
, TRANS_OPT_RECEIVEPACK
)) {
222 opts
->receivepack
= value
;
224 } else if (!strcmp(name
, TRANS_OPT_THIN
)) {
225 opts
->thin
= !!value
;
227 } else if (!strcmp(name
, TRANS_OPT_FOLLOWTAGS
)) {
228 opts
->followtags
= !!value
;
230 } else if (!strcmp(name
, TRANS_OPT_KEEP
)) {
231 opts
->keep
= !!value
;
233 } else if (!strcmp(name
, TRANS_OPT_UPDATE_SHALLOW
)) {
234 opts
->update_shallow
= !!value
;
236 } else if (!strcmp(name
, TRANS_OPT_DEPTH
)) {
241 opts
->depth
= strtol(value
, &end
, 0);
243 die(_("transport: invalid depth option '%s'"), value
);
246 } else if (!strcmp(name
, TRANS_OPT_DEEPEN_SINCE
)) {
247 opts
->deepen_since
= value
;
249 } else if (!strcmp(name
, TRANS_OPT_DEEPEN_NOT
)) {
250 opts
->deepen_not
= (const struct string_list
*)value
;
252 } else if (!strcmp(name
, TRANS_OPT_DEEPEN_RELATIVE
)) {
253 opts
->deepen_relative
= !!value
;
255 } else if (!strcmp(name
, TRANS_OPT_FROM_PROMISOR
)) {
256 opts
->from_promisor
= !!value
;
258 } else if (!strcmp(name
, TRANS_OPT_LIST_OBJECTS_FILTER
)) {
259 list_objects_filter_die_if_populated(&opts
->filter_options
);
260 parse_list_objects_filter(&opts
->filter_options
, value
);
262 } else if (!strcmp(name
, TRANS_OPT_REFETCH
)) {
263 opts
->refetch
= !!value
;
265 } else if (!strcmp(name
, TRANS_OPT_REJECT_SHALLOW
)) {
266 opts
->reject_shallow
= !!value
;
272 static int connect_setup(struct transport
*transport
, int for_push
)
274 struct git_transport_data
*data
= transport
->data
;
275 int flags
= transport
->verbose
> 0 ? CONNECT_VERBOSE
: 0;
280 switch (transport
->family
) {
281 case TRANSPORT_FAMILY_ALL
: break;
282 case TRANSPORT_FAMILY_IPV4
: flags
|= CONNECT_IPV4
; break;
283 case TRANSPORT_FAMILY_IPV6
: flags
|= CONNECT_IPV6
; break;
286 data
->conn
= git_connect(data
->fd
, transport
->url
,
291 data
->options
.receivepack
:
292 data
->options
.uploadpack
,
298 static void die_if_server_options(struct transport
*transport
)
300 if (!transport
->server_options
|| !transport
->server_options
->nr
)
302 advise(_("see protocol.version in 'git help config' for more details"));
303 die(_("server options require protocol version 2 or later"));
307 * Obtains the protocol version from the transport and writes it to
308 * transport->data->version, first connecting if not already connected.
310 * If the protocol version is one that allows skipping the listing of remote
311 * refs, and must_list_refs is 0, the listing of remote refs is skipped and
312 * this function returns NULL. Otherwise, this function returns the list of
315 static struct ref
*handshake(struct transport
*transport
, int for_push
,
316 struct transport_ls_refs_options
*options
,
319 struct git_transport_data
*data
= transport
->data
;
320 struct ref
*refs
= NULL
;
321 struct packet_reader reader
;
323 const char *server_sid
;
325 connect_setup(transport
, for_push
);
327 packet_reader_init(&reader
, data
->fd
[0], NULL
, 0,
328 PACKET_READ_CHOMP_NEWLINE
|
329 PACKET_READ_GENTLE_ON_EOF
|
330 PACKET_READ_DIE_ON_ERR_PACKET
);
332 data
->version
= discover_version(&reader
);
333 switch (data
->version
) {
335 if (server_feature_v2("session-id", &server_sid
))
336 trace2_data_string("transfer", NULL
, "server-sid", server_sid
);
338 get_remote_refs(data
->fd
[1], &reader
, &refs
, for_push
,
340 transport
->server_options
,
341 transport
->stateless_rpc
);
345 die_if_server_options(transport
);
346 get_remote_heads(&reader
, &refs
,
347 for_push
? REF_NORMAL
: 0,
350 server_sid
= server_feature_value("session-id", &sid_len
);
352 char *sid
= xstrndup(server_sid
, sid_len
);
353 trace2_data_string("transfer", NULL
, "server-sid", sid
);
357 case protocol_unknown_version
:
358 BUG("unknown protocol version");
360 data
->finished_handshake
= 1;
361 transport
->hash_algo
= reader
.hash_algo
;
363 if (reader
.line_peeked
)
364 BUG("buffer must be empty at the end of handshake()");
369 static struct ref
*get_refs_via_connect(struct transport
*transport
, int for_push
,
370 struct transport_ls_refs_options
*options
)
372 return handshake(transport
, for_push
, options
, 1);
375 static int get_bundle_uri(struct transport
*transport
)
377 struct git_transport_data
*data
= transport
->data
;
378 struct packet_reader reader
;
379 int stateless_rpc
= transport
->stateless_rpc
;
381 if (!transport
->bundles
) {
382 CALLOC_ARRAY(transport
->bundles
, 1);
383 init_bundle_list(transport
->bundles
);
386 if (!data
->finished_handshake
) {
387 struct ref
*refs
= handshake(transport
, 0, NULL
, 0);
394 * "Support" protocol v0 and v2 without bundle-uri support by
395 * silently degrading to a NOOP.
397 if (!server_supports_v2("bundle-uri"))
400 packet_reader_init(&reader
, data
->fd
[0], NULL
, 0,
401 PACKET_READ_CHOMP_NEWLINE
|
402 PACKET_READ_GENTLE_ON_EOF
);
404 return get_remote_bundle_uri(data
->fd
[1], &reader
,
405 transport
->bundles
, stateless_rpc
);
408 static int fetch_refs_via_pack(struct transport
*transport
,
409 int nr_heads
, struct ref
**to_fetch
)
412 struct git_transport_data
*data
= transport
->data
;
413 struct ref
*refs
= NULL
;
414 struct fetch_pack_args args
;
415 struct ref
*refs_tmp
= NULL
;
417 memset(&args
, 0, sizeof(args
));
418 args
.uploadpack
= data
->options
.uploadpack
;
419 args
.keep_pack
= data
->options
.keep
;
421 args
.use_thin_pack
= data
->options
.thin
;
422 args
.include_tag
= data
->options
.followtags
;
423 args
.verbose
= (transport
->verbose
> 1);
424 args
.quiet
= (transport
->verbose
< 0);
425 args
.no_progress
= !transport
->progress
;
426 args
.depth
= data
->options
.depth
;
427 args
.deepen_since
= data
->options
.deepen_since
;
428 args
.deepen_not
= data
->options
.deepen_not
;
429 args
.deepen_relative
= data
->options
.deepen_relative
;
430 args
.check_self_contained_and_connected
=
431 data
->options
.check_self_contained_and_connected
;
432 args
.cloning
= transport
->cloning
;
433 args
.update_shallow
= data
->options
.update_shallow
;
434 args
.from_promisor
= data
->options
.from_promisor
;
435 list_objects_filter_copy(&args
.filter_options
,
436 &data
->options
.filter_options
);
437 args
.refetch
= data
->options
.refetch
;
438 args
.stateless_rpc
= transport
->stateless_rpc
;
439 args
.server_options
= transport
->server_options
;
440 args
.negotiation_tips
= data
->options
.negotiation_tips
;
441 args
.reject_shallow_remote
= transport
->smart_options
->reject_shallow
;
443 if (!data
->finished_handshake
) {
445 int must_list_refs
= 0;
446 for (i
= 0; i
< nr_heads
; i
++) {
447 if (!to_fetch
[i
]->exact_oid
) {
452 refs_tmp
= handshake(transport
, 0, NULL
, must_list_refs
);
455 if (data
->version
== protocol_unknown_version
)
456 BUG("unknown protocol version");
457 else if (data
->version
<= protocol_v1
)
458 die_if_server_options(transport
);
460 if (data
->options
.acked_commits
) {
461 if (data
->version
< protocol_v2
) {
462 warning(_("--negotiate-only requires protocol v2"));
464 } else if (!server_supports_feature("fetch", "wait-for-done", 0)) {
465 warning(_("server does not support wait-for-done"));
468 negotiate_using_fetch(data
->options
.negotiation_tips
,
469 transport
->server_options
,
470 transport
->stateless_rpc
,
472 data
->options
.acked_commits
);
478 refs
= fetch_pack(&args
, data
->fd
,
479 refs_tmp
? refs_tmp
: transport
->remote_refs
,
480 to_fetch
, nr_heads
, &data
->shallow
,
481 &transport
->pack_lockfiles
, data
->version
);
483 data
->finished_handshake
= 0;
484 data
->options
.self_contained_and_connected
=
485 args
.self_contained_and_connected
;
486 data
->options
.connectivity_checked
= args
.connectivity_checked
;
490 if (report_unmatched_refs(to_fetch
, nr_heads
))
495 if (data
->fd
[1] >= 0)
497 if (finish_connect(data
->conn
))
503 list_objects_filter_release(&args
.filter_options
);
507 static int push_had_errors(struct ref
*ref
)
509 for (; ref
; ref
= ref
->next
) {
510 switch (ref
->status
) {
511 case REF_STATUS_NONE
:
512 case REF_STATUS_UPTODATE
:
522 int transport_refs_pushed(struct ref
*ref
)
524 for (; ref
; ref
= ref
->next
) {
525 switch(ref
->status
) {
526 case REF_STATUS_NONE
:
527 case REF_STATUS_UPTODATE
:
536 static void update_one_tracking_ref(struct remote
*remote
, char *refname
,
537 struct object_id
*new_oid
, int deletion
,
540 struct refspec_item rs
;
542 memset(&rs
, 0, sizeof(rs
));
546 if (!remote_find_tracking(remote
, &rs
)) {
548 fprintf(stderr
, "updating local tracking ref '%s'\n", rs
.dst
);
550 refs_delete_ref(get_main_ref_store(the_repository
),
551 NULL
, rs
.dst
, NULL
, 0);
553 refs_update_ref(get_main_ref_store(the_repository
),
554 "update by push", rs
.dst
, new_oid
,
560 void transport_update_tracking_ref(struct remote
*remote
, struct ref
*ref
, int verbose
)
563 struct object_id
*new_oid
;
564 struct ref_push_report
*report
;
566 if (ref
->status
!= REF_STATUS_OK
&& ref
->status
!= REF_STATUS_UPTODATE
)
569 report
= ref
->report
;
571 update_one_tracking_ref(remote
, ref
->name
, &ref
->new_oid
,
572 ref
->deletion
, verbose
);
574 for (; report
; report
= report
->next
) {
575 refname
= report
->ref_name
? (char *)report
->ref_name
: ref
->name
;
576 new_oid
= report
->new_oid
? report
->new_oid
: &ref
->new_oid
;
577 update_one_tracking_ref(remote
, refname
, new_oid
,
578 is_null_oid(new_oid
), verbose
);
582 static void print_ref_status(char flag
, const char *summary
,
583 struct ref
*to
, struct ref
*from
, const char *msg
,
584 struct ref_push_report
*report
,
585 int porcelain
, int summary_width
)
589 if (report
&& report
->ref_name
)
590 to_name
= report
->ref_name
;
596 fprintf(stdout
, "%c\t%s:%s\t", flag
, from
->name
, to_name
);
598 fprintf(stdout
, "%c\t:%s\t", flag
, to_name
);
600 fprintf(stdout
, "%s (%s)\n", summary
, msg
);
602 fprintf(stdout
, "%s\n", summary
);
604 const char *red
= "", *reset
= "";
605 if (push_had_errors(to
)) {
606 red
= transport_get_color(TRANSPORT_COLOR_REJECTED
);
607 reset
= transport_get_color(TRANSPORT_COLOR_RESET
);
609 fprintf(stderr
, " %s%c %-*s%s ", red
, flag
, summary_width
,
612 fprintf(stderr
, "%s -> %s",
613 prettify_refname(from
->name
),
614 prettify_refname(to_name
));
616 fputs(prettify_refname(to_name
), stderr
);
626 static void print_ok_ref_status(struct ref
*ref
,
627 struct ref_push_report
*report
,
628 int porcelain
, int summary_width
)
630 struct object_id
*old_oid
;
631 struct object_id
*new_oid
;
632 const char *ref_name
;
635 if (report
&& report
->old_oid
)
636 old_oid
= report
->old_oid
;
638 old_oid
= &ref
->old_oid
;
639 if (report
&& report
->new_oid
)
640 new_oid
= report
->new_oid
;
642 new_oid
= &ref
->new_oid
;
643 if (report
&& report
->forced_update
)
644 forced_update
= report
->forced_update
;
646 forced_update
= ref
->forced_update
;
647 if (report
&& report
->ref_name
)
648 ref_name
= report
->ref_name
;
650 ref_name
= ref
->name
;
653 print_ref_status('-', "[deleted]", ref
, NULL
, NULL
,
654 report
, porcelain
, summary_width
);
655 else if (is_null_oid(old_oid
))
656 print_ref_status('*',
657 (starts_with(ref_name
, "refs/tags/")
659 : (starts_with(ref_name
, "refs/heads/")
661 : "[new reference]")),
662 ref
, ref
->peer_ref
, NULL
,
663 report
, porcelain
, summary_width
);
665 struct strbuf quickref
= STRBUF_INIT
;
669 strbuf_add_unique_abbrev(&quickref
, old_oid
,
672 strbuf_addstr(&quickref
, "...");
674 msg
= "forced update";
676 strbuf_addstr(&quickref
, "..");
680 strbuf_add_unique_abbrev(&quickref
, new_oid
,
683 print_ref_status(type
, quickref
.buf
, ref
, ref
->peer_ref
, msg
,
684 report
, porcelain
, summary_width
);
685 strbuf_release(&quickref
);
689 static int print_one_push_report(struct ref
*ref
, const char *dest
, int count
,
690 struct ref_push_report
*report
,
691 int porcelain
, int summary_width
)
694 char *url
= transport_anonymize_url(dest
);
695 fprintf(porcelain
? stdout
: stderr
, "To %s\n", url
);
699 switch(ref
->status
) {
700 case REF_STATUS_NONE
:
701 print_ref_status('X', "[no match]", ref
, NULL
, NULL
,
702 report
, porcelain
, summary_width
);
704 case REF_STATUS_REJECT_NODELETE
:
705 print_ref_status('!', "[rejected]", ref
, NULL
,
706 "remote does not support deleting refs",
707 report
, porcelain
, summary_width
);
709 case REF_STATUS_UPTODATE
:
710 print_ref_status('=', "[up to date]", ref
,
712 report
, porcelain
, summary_width
);
714 case REF_STATUS_REJECT_NONFASTFORWARD
:
715 print_ref_status('!', "[rejected]", ref
, ref
->peer_ref
,
717 report
, porcelain
, summary_width
);
719 case REF_STATUS_REJECT_ALREADY_EXISTS
:
720 print_ref_status('!', "[rejected]", ref
, ref
->peer_ref
,
722 report
, porcelain
, summary_width
);
724 case REF_STATUS_REJECT_FETCH_FIRST
:
725 print_ref_status('!', "[rejected]", ref
, ref
->peer_ref
,
727 report
, porcelain
, summary_width
);
729 case REF_STATUS_REJECT_NEEDS_FORCE
:
730 print_ref_status('!', "[rejected]", ref
, ref
->peer_ref
,
732 report
, porcelain
, summary_width
);
734 case REF_STATUS_REJECT_STALE
:
735 print_ref_status('!', "[rejected]", ref
, ref
->peer_ref
,
737 report
, porcelain
, summary_width
);
739 case REF_STATUS_REJECT_REMOTE_UPDATED
:
740 print_ref_status('!', "[rejected]", ref
, ref
->peer_ref
,
741 "remote ref updated since checkout",
742 report
, porcelain
, summary_width
);
744 case REF_STATUS_REJECT_SHALLOW
:
745 print_ref_status('!', "[rejected]", ref
, ref
->peer_ref
,
746 "new shallow roots not allowed",
747 report
, porcelain
, summary_width
);
749 case REF_STATUS_REMOTE_REJECT
:
750 print_ref_status('!', "[remote rejected]", ref
,
751 ref
->deletion
? NULL
: ref
->peer_ref
,
753 report
, porcelain
, summary_width
);
755 case REF_STATUS_EXPECTING_REPORT
:
756 print_ref_status('!', "[remote failure]", ref
,
757 ref
->deletion
? NULL
: ref
->peer_ref
,
758 "remote failed to report status",
759 report
, porcelain
, summary_width
);
761 case REF_STATUS_ATOMIC_PUSH_FAILED
:
762 print_ref_status('!', "[rejected]", ref
, ref
->peer_ref
,
763 "atomic push failed",
764 report
, porcelain
, summary_width
);
767 print_ok_ref_status(ref
, report
, porcelain
, summary_width
);
774 static int print_one_push_status(struct ref
*ref
, const char *dest
, int count
,
775 int porcelain
, int summary_width
)
777 struct ref_push_report
*report
;
781 return print_one_push_report(ref
, dest
, count
,
782 NULL
, porcelain
, summary_width
);
784 for (report
= ref
->report
; report
; report
= report
->next
)
785 print_one_push_report(ref
, dest
, count
+ n
++,
786 report
, porcelain
, summary_width
);
790 static int measure_abbrev(const struct object_id
*oid
, int sofar
)
792 char hex
[GIT_MAX_HEXSZ
+ 1];
793 int w
= repo_find_unique_abbrev_r(the_repository
, hex
, oid
,
796 return (w
< sofar
) ? sofar
: w
;
799 int transport_summary_width(const struct ref
*refs
)
803 for (; refs
; refs
= refs
->next
) {
804 maxw
= measure_abbrev(&refs
->old_oid
, maxw
);
805 maxw
= measure_abbrev(&refs
->new_oid
, maxw
);
808 maxw
= FALLBACK_DEFAULT_ABBREV
;
809 return (2 * maxw
+ 3);
812 void transport_print_push_status(const char *dest
, struct ref
*refs
,
813 int verbose
, int porcelain
, unsigned int *reject_reasons
)
818 int summary_width
= transport_summary_width(refs
);
820 if (transport_color_config() < 0)
821 warning(_("could not parse transport.color.* config"));
823 head
= refs_resolve_refdup(get_main_ref_store(the_repository
), "HEAD",
824 RESOLVE_REF_READING
, NULL
, NULL
);
827 for (ref
= refs
; ref
; ref
= ref
->next
)
828 if (ref
->status
== REF_STATUS_UPTODATE
)
829 n
+= print_one_push_status(ref
, dest
, n
,
830 porcelain
, summary_width
);
833 for (ref
= refs
; ref
; ref
= ref
->next
)
834 if (ref
->status
== REF_STATUS_OK
)
835 n
+= print_one_push_status(ref
, dest
, n
,
836 porcelain
, summary_width
);
839 for (ref
= refs
; ref
; ref
= ref
->next
) {
840 if (ref
->status
!= REF_STATUS_NONE
&&
841 ref
->status
!= REF_STATUS_UPTODATE
&&
842 ref
->status
!= REF_STATUS_OK
)
843 n
+= print_one_push_status(ref
, dest
, n
,
844 porcelain
, summary_width
);
845 if (ref
->status
== REF_STATUS_REJECT_NONFASTFORWARD
) {
846 if (head
!= NULL
&& !strcmp(head
, ref
->name
))
847 *reject_reasons
|= REJECT_NON_FF_HEAD
;
849 *reject_reasons
|= REJECT_NON_FF_OTHER
;
850 } else if (ref
->status
== REF_STATUS_REJECT_ALREADY_EXISTS
) {
851 *reject_reasons
|= REJECT_ALREADY_EXISTS
;
852 } else if (ref
->status
== REF_STATUS_REJECT_FETCH_FIRST
) {
853 *reject_reasons
|= REJECT_FETCH_FIRST
;
854 } else if (ref
->status
== REF_STATUS_REJECT_NEEDS_FORCE
) {
855 *reject_reasons
|= REJECT_NEEDS_FORCE
;
856 } else if (ref
->status
== REF_STATUS_REJECT_REMOTE_UPDATED
) {
857 *reject_reasons
|= REJECT_REF_NEEDS_UPDATE
;
863 static int git_transport_push(struct transport
*transport
, struct ref
*remote_refs
, int flags
)
865 struct git_transport_data
*data
= transport
->data
;
866 struct send_pack_args args
;
869 if (transport_color_config() < 0)
872 if (!data
->finished_handshake
)
873 get_refs_via_connect(transport
, 1, NULL
);
875 memset(&args
, 0, sizeof(args
));
876 args
.send_mirror
= !!(flags
& TRANSPORT_PUSH_MIRROR
);
877 args
.force_update
= !!(flags
& TRANSPORT_PUSH_FORCE
);
878 args
.use_thin_pack
= data
->options
.thin
;
879 args
.verbose
= (transport
->verbose
> 0);
880 args
.quiet
= (transport
->verbose
< 0);
881 args
.progress
= transport
->progress
;
882 args
.dry_run
= !!(flags
& TRANSPORT_PUSH_DRY_RUN
);
883 args
.porcelain
= !!(flags
& TRANSPORT_PUSH_PORCELAIN
);
884 args
.atomic
= !!(flags
& TRANSPORT_PUSH_ATOMIC
);
885 args
.push_options
= transport
->push_options
;
886 args
.url
= transport
->url
;
888 if (flags
& TRANSPORT_PUSH_CERT_ALWAYS
)
889 args
.push_cert
= SEND_PACK_PUSH_CERT_ALWAYS
;
890 else if (flags
& TRANSPORT_PUSH_CERT_IF_ASKED
)
891 args
.push_cert
= SEND_PACK_PUSH_CERT_IF_ASKED
;
893 args
.push_cert
= SEND_PACK_PUSH_CERT_NEVER
;
895 switch (data
->version
) {
897 die(_("support for protocol v2 not implemented yet"));
901 ret
= send_pack(&args
, data
->fd
, data
->conn
, remote_refs
,
904 case protocol_unknown_version
:
905 BUG("unknown protocol version");
911 * Atomic push may abort the connection early and close the pipe,
912 * which may cause an error for `finish_connect()`. Ignore this error
913 * for atomic git-push.
915 if (ret
|| args
.atomic
)
916 finish_connect(data
->conn
);
918 ret
= finish_connect(data
->conn
);
920 data
->finished_handshake
= 0;
925 static int connect_git(struct transport
*transport
, const char *name
,
926 const char *executable
, int fd
[2])
928 struct git_transport_data
*data
= transport
->data
;
929 data
->conn
= git_connect(data
->fd
, transport
->url
,
930 name
, executable
, 0);
936 static int disconnect_git(struct transport
*transport
)
938 struct git_transport_data
*data
= transport
->data
;
940 if (data
->finished_handshake
&& !transport
->stateless_rpc
)
941 packet_flush(data
->fd
[1]);
943 if (data
->fd
[1] >= 0)
945 finish_connect(data
->conn
);
948 list_objects_filter_release(&data
->options
.filter_options
);
953 static struct transport_vtable taken_over_vtable
= {
954 .get_refs_list
= get_refs_via_connect
,
955 .get_bundle_uri
= get_bundle_uri
,
956 .fetch_refs
= fetch_refs_via_pack
,
957 .push_refs
= git_transport_push
,
958 .disconnect
= disconnect_git
961 void transport_take_over(struct transport
*transport
,
962 struct child_process
*child
)
964 struct git_transport_data
*data
;
966 if (!transport
->smart_options
)
967 BUG("taking over transport requires non-NULL "
968 "smart_options field.");
970 CALLOC_ARRAY(data
, 1);
971 data
->options
= *transport
->smart_options
;
973 data
->fd
[0] = data
->conn
->out
;
974 data
->fd
[1] = data
->conn
->in
;
975 data
->finished_handshake
= 0;
976 transport
->data
= data
;
978 transport
->vtable
= &taken_over_vtable
;
979 transport
->smart_options
= &(data
->options
);
981 transport
->cannot_reuse
= 1;
984 static int is_file(const char *url
)
989 return S_ISREG(buf
.st_mode
);
992 static int external_specification_len(const char *url
)
994 return strchr(url
, ':') - url
;
997 static const struct string_list
*protocol_allow_list(void)
999 static int enabled
= -1;
1000 static struct string_list allowed
= STRING_LIST_INIT_DUP
;
1003 const char *v
= getenv("GIT_ALLOW_PROTOCOL");
1005 string_list_split(&allowed
, v
, ':', -1);
1006 string_list_sort(&allowed
);
1013 return enabled
? &allowed
: NULL
;
1016 enum protocol_allow_config
{
1017 PROTOCOL_ALLOW_NEVER
= 0,
1018 PROTOCOL_ALLOW_USER_ONLY
,
1019 PROTOCOL_ALLOW_ALWAYS
1022 static enum protocol_allow_config
parse_protocol_config(const char *key
,
1025 if (!strcasecmp(value
, "always"))
1026 return PROTOCOL_ALLOW_ALWAYS
;
1027 else if (!strcasecmp(value
, "never"))
1028 return PROTOCOL_ALLOW_NEVER
;
1029 else if (!strcasecmp(value
, "user"))
1030 return PROTOCOL_ALLOW_USER_ONLY
;
1032 die(_("unknown value for config '%s': %s"), key
, value
);
1035 static enum protocol_allow_config
get_protocol_config(const char *type
)
1037 char *key
= xstrfmt("protocol.%s.allow", type
);
1040 /* first check the per-protocol config */
1041 if (!git_config_get_string(key
, &value
)) {
1042 enum protocol_allow_config ret
=
1043 parse_protocol_config(key
, value
);
1050 /* if defined, fallback to user-defined default for unknown protocols */
1051 if (!git_config_get_string("protocol.allow", &value
)) {
1052 enum protocol_allow_config ret
=
1053 parse_protocol_config("protocol.allow", value
);
1058 /* fallback to built-in defaults */
1060 if (!strcmp(type
, "http") ||
1061 !strcmp(type
, "https") ||
1062 !strcmp(type
, "git") ||
1063 !strcmp(type
, "ssh"))
1064 return PROTOCOL_ALLOW_ALWAYS
;
1066 /* known scary; err on the side of caution */
1067 if (!strcmp(type
, "ext"))
1068 return PROTOCOL_ALLOW_NEVER
;
1070 /* unknown; by default let them be used only directly by the user */
1071 return PROTOCOL_ALLOW_USER_ONLY
;
1074 int is_transport_allowed(const char *type
, int from_user
)
1076 const struct string_list
*allow_list
= protocol_allow_list();
1078 return string_list_has_string(allow_list
, type
);
1080 switch (get_protocol_config(type
)) {
1081 case PROTOCOL_ALLOW_ALWAYS
:
1083 case PROTOCOL_ALLOW_NEVER
:
1085 case PROTOCOL_ALLOW_USER_ONLY
:
1087 from_user
= git_env_bool("GIT_PROTOCOL_FROM_USER", 1);
1091 BUG("invalid protocol_allow_config type");
1094 void transport_check_allowed(const char *type
)
1096 if (!is_transport_allowed(type
, -1))
1097 die(_("transport '%s' not allowed"), type
);
1100 static struct transport_vtable bundle_vtable
= {
1101 .get_refs_list
= get_refs_from_bundle
,
1102 .fetch_refs
= fetch_refs_from_bundle
,
1103 .disconnect
= close_bundle
1106 static struct transport_vtable builtin_smart_vtable
= {
1107 .get_refs_list
= get_refs_via_connect
,
1108 .get_bundle_uri
= get_bundle_uri
,
1109 .fetch_refs
= fetch_refs_via_pack
,
1110 .push_refs
= git_transport_push
,
1111 .connect
= connect_git
,
1112 .disconnect
= disconnect_git
1115 struct transport
*transport_get(struct remote
*remote
, const char *url
)
1118 char *helper_to_free
= NULL
;
1120 struct transport
*ret
= xcalloc(1, sizeof(*ret
));
1122 ret
->progress
= isatty(2);
1123 string_list_init_dup(&ret
->pack_lockfiles
);
1125 CALLOC_ARRAY(ret
->bundles
, 1);
1126 init_bundle_list(ret
->bundles
);
1129 BUG("No remote provided to transport_get()");
1131 ret
->got_remote_refs
= 0;
1132 ret
->remote
= remote
;
1133 helper
= remote
->foreign_vcs
;
1136 url
= remote
->url
.v
[0];
1140 while (is_urlschemechar(p
== url
, *p
))
1142 if (starts_with(p
, "::"))
1143 helper
= helper_to_free
= xstrndup(url
, p
- url
);
1146 transport_helper_init(ret
, helper
);
1147 free(helper_to_free
);
1148 } else if (starts_with(url
, "rsync:")) {
1149 die(_("git-over-rsync is no longer supported"));
1150 } else if (url_is_local_not_ssh(url
) && is_file(url
) && is_bundle(url
, 1)) {
1151 struct bundle_transport_data
*data
= xcalloc(1, sizeof(*data
));
1152 bundle_header_init(&data
->header
);
1153 transport_check_allowed("file");
1155 ret
->vtable
= &bundle_vtable
;
1156 ret
->smart_options
= NULL
;
1157 } else if (!is_url(url
)
1158 || starts_with(url
, "file://")
1159 || starts_with(url
, "git://")
1160 || starts_with(url
, "ssh://")
1161 || starts_with(url
, "git+ssh://") /* deprecated - do not use */
1162 || starts_with(url
, "ssh+git://") /* deprecated - do not use */
1165 * These are builtin smart transports; "allowed" transports
1166 * will be checked individually in git_connect.
1168 struct git_transport_data
*data
= xcalloc(1, sizeof(*data
));
1169 list_objects_filter_init(&data
->options
.filter_options
);
1171 ret
->vtable
= &builtin_smart_vtable
;
1172 ret
->smart_options
= &(data
->options
);
1175 data
->finished_handshake
= 0;
1177 /* Unknown protocol in URL. Pass to external handler. */
1178 int len
= external_specification_len(url
);
1179 char *handler
= xmemdupz(url
, len
);
1180 transport_helper_init(ret
, handler
);
1184 if (ret
->smart_options
) {
1185 ret
->smart_options
->thin
= 1;
1186 ret
->smart_options
->uploadpack
= "git-upload-pack";
1187 if (remote
->uploadpack
)
1188 ret
->smart_options
->uploadpack
= remote
->uploadpack
;
1189 ret
->smart_options
->receivepack
= "git-receive-pack";
1190 if (remote
->receivepack
)
1191 ret
->smart_options
->receivepack
= remote
->receivepack
;
1194 ret
->hash_algo
= &hash_algos
[GIT_HASH_SHA1
];
1199 const struct git_hash_algo
*transport_get_hash_algo(struct transport
*transport
)
1201 return transport
->hash_algo
;
1204 int transport_set_option(struct transport
*transport
,
1205 const char *name
, const char *value
)
1207 int git_reports
= 1, protocol_reports
= 1;
1209 if (transport
->smart_options
)
1210 git_reports
= set_git_option(transport
->smart_options
,
1213 if (transport
->vtable
->set_option
)
1214 protocol_reports
= transport
->vtable
->set_option(transport
,
1217 /* If either report is 0, report 0 (success). */
1218 if (!git_reports
|| !protocol_reports
)
1220 /* If either reports -1 (invalid value), report -1. */
1221 if ((git_reports
== -1) || (protocol_reports
== -1))
1223 /* Otherwise if both report unknown, report unknown. */
1227 void transport_set_verbosity(struct transport
*transport
, int verbosity
,
1231 transport
->verbose
= verbosity
<= 3 ? verbosity
: 3;
1233 transport
->verbose
= -1;
1236 * Rules used to determine whether to report progress (processing aborts
1237 * when a rule is satisfied):
1239 * . Report progress, if force_progress is 1 (ie. --progress).
1240 * . Don't report progress, if force_progress is 0 (ie. --no-progress).
1241 * . Don't report progress, if verbosity < 0 (ie. -q/--quiet ).
1242 * . Report progress if isatty(2) is 1.
1244 if (force_progress
>= 0)
1245 transport
->progress
= !!force_progress
;
1247 transport
->progress
= verbosity
>= 0 && isatty(2);
1250 static void die_with_unpushed_submodules(struct string_list
*needs_pushing
)
1254 fprintf(stderr
, _("The following submodule paths contain changes that can\n"
1255 "not be found on any remote:\n"));
1256 for (i
= 0; i
< needs_pushing
->nr
; i
++)
1257 fprintf(stderr
, " %s\n", needs_pushing
->items
[i
].string
);
1258 fprintf(stderr
, _("\nPlease try\n\n"
1259 " git push --recurse-submodules=on-demand\n\n"
1260 "or cd to the path and use\n\n"
1262 "to push them to a remote.\n\n"));
1264 string_list_clear(needs_pushing
, 0);
1266 die(_("Aborting."));
1269 static int run_pre_push_hook(struct transport
*transport
,
1270 struct ref
*remote_refs
)
1274 struct child_process proc
= CHILD_PROCESS_INIT
;
1276 const char *hook_path
= find_hook("pre-push");
1281 strvec_push(&proc
.args
, hook_path
);
1282 strvec_push(&proc
.args
, transport
->remote
->name
);
1283 strvec_push(&proc
.args
, transport
->url
);
1286 proc
.trace2_hook_name
= "pre-push";
1288 if (start_command(&proc
)) {
1289 finish_command(&proc
);
1293 sigchain_push(SIGPIPE
, SIG_IGN
);
1295 strbuf_init(&buf
, 256);
1297 for (r
= remote_refs
; r
; r
= r
->next
) {
1298 if (!r
->peer_ref
) continue;
1299 if (r
->status
== REF_STATUS_REJECT_NONFASTFORWARD
) continue;
1300 if (r
->status
== REF_STATUS_REJECT_STALE
) continue;
1301 if (r
->status
== REF_STATUS_REJECT_REMOTE_UPDATED
) continue;
1302 if (r
->status
== REF_STATUS_UPTODATE
) continue;
1305 strbuf_addf( &buf
, "%s %s %s %s\n",
1306 r
->peer_ref
->name
, oid_to_hex(&r
->new_oid
),
1307 r
->name
, oid_to_hex(&r
->old_oid
));
1309 if (write_in_full(proc
.in
, buf
.buf
, buf
.len
) < 0) {
1310 /* We do not mind if a hook does not read all refs. */
1317 strbuf_release(&buf
);
1323 sigchain_pop(SIGPIPE
);
1325 x
= finish_command(&proc
);
1332 int transport_push(struct repository
*r
,
1333 struct transport
*transport
,
1334 struct refspec
*rs
, int flags
,
1335 unsigned int *reject_reasons
)
1337 struct ref
*remote_refs
= NULL
;
1338 struct ref
*local_refs
= NULL
;
1339 int match_flags
= MATCH_REFS_NONE
;
1340 int verbose
= (transport
->verbose
> 0);
1341 int quiet
= (transport
->verbose
< 0);
1342 int porcelain
= flags
& TRANSPORT_PUSH_PORCELAIN
;
1343 int pretend
= flags
& TRANSPORT_PUSH_DRY_RUN
;
1346 struct transport_ls_refs_options transport_options
=
1347 TRANSPORT_LS_REFS_OPTIONS_INIT
;
1349 *reject_reasons
= 0;
1351 if (transport_color_config() < 0)
1354 if (!transport
->vtable
->push_refs
)
1357 local_refs
= get_local_heads();
1359 if (check_push_refs(local_refs
, rs
) < 0)
1362 refspec_ref_prefixes(rs
, &transport_options
.ref_prefixes
);
1364 trace2_region_enter("transport_push", "get_refs_list", r
);
1365 remote_refs
= transport
->vtable
->get_refs_list(transport
, 1,
1366 &transport_options
);
1367 trace2_region_leave("transport_push", "get_refs_list", r
);
1369 transport_ls_refs_options_release(&transport_options
);
1371 if (flags
& TRANSPORT_PUSH_ALL
)
1372 match_flags
|= MATCH_REFS_ALL
;
1373 if (flags
& TRANSPORT_PUSH_MIRROR
)
1374 match_flags
|= MATCH_REFS_MIRROR
;
1375 if (flags
& TRANSPORT_PUSH_PRUNE
)
1376 match_flags
|= MATCH_REFS_PRUNE
;
1377 if (flags
& TRANSPORT_PUSH_FOLLOW_TAGS
)
1378 match_flags
|= MATCH_REFS_FOLLOW_TAGS
;
1380 if (match_push_refs(local_refs
, &remote_refs
, rs
, match_flags
))
1383 if (transport
->smart_options
&&
1384 transport
->smart_options
->cas
&&
1385 !is_empty_cas(transport
->smart_options
->cas
))
1386 apply_push_cas(transport
->smart_options
->cas
,
1387 transport
->remote
, remote_refs
);
1389 set_ref_status_for_push(remote_refs
,
1390 flags
& TRANSPORT_PUSH_MIRROR
,
1391 flags
& TRANSPORT_PUSH_FORCE
);
1393 if (!(flags
& TRANSPORT_PUSH_NO_HOOK
))
1394 if (run_pre_push_hook(transport
, remote_refs
))
1397 if ((flags
& (TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND
|
1398 TRANSPORT_RECURSE_SUBMODULES_ONLY
)) &&
1399 !is_bare_repository()) {
1400 struct ref
*ref
= remote_refs
;
1401 struct oid_array commits
= OID_ARRAY_INIT
;
1403 trace2_region_enter("transport_push", "push_submodules", r
);
1404 for (; ref
; ref
= ref
->next
)
1405 if (!is_null_oid(&ref
->new_oid
))
1406 oid_array_append(&commits
,
1409 if (!push_unpushed_submodules(r
,
1413 transport
->push_options
,
1415 oid_array_clear(&commits
);
1416 trace2_region_leave("transport_push", "push_submodules", r
);
1417 die(_("failed to push all needed submodules"));
1419 oid_array_clear(&commits
);
1420 trace2_region_leave("transport_push", "push_submodules", r
);
1423 if (((flags
& TRANSPORT_RECURSE_SUBMODULES_CHECK
) ||
1424 ((flags
& (TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND
|
1425 TRANSPORT_RECURSE_SUBMODULES_ONLY
)) &&
1426 !pretend
)) && !is_bare_repository()) {
1427 struct ref
*ref
= remote_refs
;
1428 struct string_list needs_pushing
= STRING_LIST_INIT_DUP
;
1429 struct oid_array commits
= OID_ARRAY_INIT
;
1431 trace2_region_enter("transport_push", "check_submodules", r
);
1432 for (; ref
; ref
= ref
->next
)
1433 if (!is_null_oid(&ref
->new_oid
))
1434 oid_array_append(&commits
,
1437 if (find_unpushed_submodules(r
,
1439 transport
->remote
->name
,
1441 oid_array_clear(&commits
);
1442 trace2_region_leave("transport_push", "check_submodules", r
);
1443 die_with_unpushed_submodules(&needs_pushing
);
1445 string_list_clear(&needs_pushing
, 0);
1446 oid_array_clear(&commits
);
1447 trace2_region_leave("transport_push", "check_submodules", r
);
1450 if (!(flags
& TRANSPORT_RECURSE_SUBMODULES_ONLY
)) {
1451 trace2_region_enter("transport_push", "push_refs", r
);
1452 push_ret
= transport
->vtable
->push_refs(transport
, remote_refs
, flags
);
1453 trace2_region_leave("transport_push", "push_refs", r
);
1456 err
= push_had_errors(remote_refs
);
1457 ret
= push_ret
| err
;
1460 transport_print_push_status(transport
->url
, remote_refs
,
1461 verbose
| porcelain
, porcelain
,
1464 if (flags
& TRANSPORT_PUSH_SET_UPSTREAM
)
1465 set_upstreams(transport
, remote_refs
, pretend
);
1467 if (!(flags
& (TRANSPORT_PUSH_DRY_RUN
|
1468 TRANSPORT_RECURSE_SUBMODULES_ONLY
))) {
1470 for (ref
= remote_refs
; ref
; ref
= ref
->next
)
1471 transport_update_tracking_ref(transport
->remote
, ref
, verbose
);
1474 if (porcelain
&& !push_ret
)
1476 else if (!quiet
&& !ret
&& !transport_refs_pushed(remote_refs
))
1477 /* stable plumbing output; do not modify or localize */
1478 fprintf(stderr
, "Everything up-to-date\n");
1481 free_refs(local_refs
);
1482 free_refs(remote_refs
);
1486 const struct ref
*transport_get_remote_refs(struct transport
*transport
,
1487 struct transport_ls_refs_options
*transport_options
)
1489 if (!transport
->got_remote_refs
) {
1490 transport
->remote_refs
=
1491 transport
->vtable
->get_refs_list(transport
, 0,
1493 transport
->got_remote_refs
= 1;
1496 return transport
->remote_refs
;
1499 void transport_ls_refs_options_release(struct transport_ls_refs_options
*opts
)
1501 strvec_clear(&opts
->ref_prefixes
);
1502 free((char *)opts
->unborn_head_target
);
1505 int transport_fetch_refs(struct transport
*transport
, struct ref
*refs
)
1508 int nr_heads
= 0, nr_alloc
= 0, nr_refs
= 0;
1509 struct ref
**heads
= NULL
;
1512 for (rm
= refs
; rm
; rm
= rm
->next
) {
1515 !is_null_oid(&rm
->old_oid
) &&
1516 oideq(&rm
->peer_ref
->old_oid
, &rm
->old_oid
))
1518 ALLOC_GROW(heads
, nr_heads
+ 1, nr_alloc
);
1519 heads
[nr_heads
++] = rm
;
1524 * When deepening of a shallow repository is requested,
1525 * then local and remote refs are likely to still be equal.
1526 * Just feed them all to the fetch method in that case.
1527 * This condition shouldn't be met in a non-deepening fetch
1528 * (see builtin/fetch.c:quickfetch()).
1530 ALLOC_ARRAY(heads
, nr_refs
);
1531 for (rm
= refs
; rm
; rm
= rm
->next
)
1532 heads
[nr_heads
++] = rm
;
1535 rc
= transport
->vtable
->fetch_refs(transport
, nr_heads
, heads
);
1541 int transport_get_remote_bundle_uri(struct transport
*transport
)
1544 const struct transport_vtable
*vtable
= transport
->vtable
;
1546 /* Check config only once. */
1547 if (transport
->got_remote_bundle_uri
)
1549 transport
->got_remote_bundle_uri
= 1;
1552 * Don't request bundle-uri from the server unless configured to
1553 * do so by the transfer.bundleURI=true config option.
1555 if (git_config_get_bool("transfer.bundleuri", &value
) || !value
)
1558 if (!transport
->bundles
->baseURI
)
1559 transport
->bundles
->baseURI
= xstrdup(transport
->url
);
1561 if (!vtable
->get_bundle_uri
)
1562 return error(_("bundle-uri operation not supported by protocol"));
1564 if (vtable
->get_bundle_uri(transport
) < 0)
1565 return error(_("could not retrieve server-advertised bundle-uri list"));
1569 void transport_unlock_pack(struct transport
*transport
, unsigned int flags
)
1571 int in_signal_handler
= !!(flags
& TRANSPORT_UNLOCK_PACK_IN_SIGNAL_HANDLER
);
1574 for (i
= 0; i
< transport
->pack_lockfiles
.nr
; i
++)
1575 if (in_signal_handler
)
1576 unlink(transport
->pack_lockfiles
.items
[i
].string
);
1578 unlink_or_warn(transport
->pack_lockfiles
.items
[i
].string
);
1579 if (!in_signal_handler
)
1580 string_list_clear(&transport
->pack_lockfiles
, 0);
1583 int transport_connect(struct transport
*transport
, const char *name
,
1584 const char *exec
, int fd
[2])
1586 if (transport
->vtable
->connect
)
1587 return transport
->vtable
->connect(transport
, name
, exec
, fd
);
1589 die(_("operation not supported by protocol"));
1592 int transport_disconnect(struct transport
*transport
)
1595 if (transport
->vtable
->disconnect
)
1596 ret
= transport
->vtable
->disconnect(transport
);
1597 if (transport
->got_remote_refs
)
1598 free_refs((void *)transport
->remote_refs
);
1599 clear_bundle_list(transport
->bundles
);
1600 free(transport
->bundles
);
1606 * Strip username (and password) from a URL and return
1607 * it in a newly allocated string.
1609 char *transport_anonymize_url(const char *url
)
1611 char *scheme_prefix
, *anon_part
;
1612 size_t anon_len
, prefix_len
= 0;
1614 anon_part
= strchr(url
, '@');
1615 if (url_is_local_not_ssh(url
) || !anon_part
)
1618 anon_len
= strlen(++anon_part
);
1619 scheme_prefix
= strstr(url
, "://");
1620 if (!scheme_prefix
) {
1621 if (!strchr(anon_part
, ':'))
1622 /* cannot be "me@there:/path/name" */
1626 /* make sure scheme is reasonable */
1627 for (cp
= url
; cp
< scheme_prefix
; cp
++) {
1630 case '+': case '.': case '-':
1639 /* @ past the first slash does not count */
1640 cp
= strchr(scheme_prefix
+ 3, '/');
1641 if (cp
&& cp
< anon_part
)
1643 prefix_len
= scheme_prefix
- url
+ 3;
1645 return xstrfmt("%.*s%.*s", (int)prefix_len
, url
,
1646 (int)anon_len
, anon_part
);
1648 return xstrdup(url
);