Skip to content

Commit db5723c

Browse files
committed
fetch: refactor code that prepares a transport
Make a helper function prepare_transport() that returns a transport to talk to a given remote. The set_option() helper that used to always affect the file-scope global "gtransport" now takes a transport as its parameter. Signed-off-by: Junio C Hamano <[email protected]>
1 parent af23445 commit db5723c

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

builtin/fetch.c

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,31 @@ static int truncate_fetch_head(void)
720720
return 0;
721721
}
722722

723+
static void set_option(struct transport *transport, const char *name, const char *value)
724+
{
725+
int r = transport_set_option(transport, name, value);
726+
if (r < 0)
727+
die(_("Option \"%s\" value \"%s\" is not valid for %s"),
728+
name, value, transport->url);
729+
if (r > 0)
730+
warning(_("Option \"%s\" is ignored for %s\n"),
731+
name, transport->url);
732+
}
733+
734+
struct transport *prepare_transport(struct remote *remote)
735+
{
736+
struct transport *transport;
737+
transport = transport_get(remote, NULL);
738+
transport_set_verbosity(transport, verbosity, progress);
739+
if (upload_pack)
740+
set_option(transport, TRANS_OPT_UPLOADPACK, upload_pack);
741+
if (keep)
742+
set_option(transport, TRANS_OPT_KEEP, "yes");
743+
if (depth)
744+
set_option(transport, TRANS_OPT_DEPTH, depth);
745+
return transport;
746+
}
747+
723748
static int do_fetch(struct transport *transport,
724749
struct refspec *refs, int ref_count)
725750
{
@@ -816,17 +841,6 @@ static int do_fetch(struct transport *transport,
816841
return retcode;
817842
}
818843

819-
static void set_option(const char *name, const char *value)
820-
{
821-
int r = transport_set_option(gtransport, name, value);
822-
if (r < 0)
823-
die(_("Option \"%s\" value \"%s\" is not valid for %s"),
824-
name, value, gtransport->url);
825-
if (r > 0)
826-
warning(_("Option \"%s\" is ignored for %s\n"),
827-
name, gtransport->url);
828-
}
829-
830844
static int get_one_remote_for_fetch(struct remote *remote, void *priv)
831845
{
832846
struct string_list *list = priv;
@@ -949,15 +963,7 @@ static int fetch_one(struct remote *remote, int argc, const char **argv)
949963
die(_("No remote repository specified. Please, specify either a URL or a\n"
950964
"remote name from which new revisions should be fetched."));
951965

952-
gtransport = transport_get(remote, NULL);
953-
transport_set_verbosity(gtransport, verbosity, progress);
954-
if (upload_pack)
955-
set_option(TRANS_OPT_UPLOADPACK, upload_pack);
956-
if (keep)
957-
set_option(TRANS_OPT_KEEP, "yes");
958-
if (depth)
959-
set_option(TRANS_OPT_DEPTH, depth);
960-
966+
gtransport = prepare_transport(remote);
961967
if (argc > 0) {
962968
int j = 0;
963969
refs = xcalloc(argc + 1, sizeof(const char *));

0 commit comments

Comments
 (0)