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 <gitster@pobox.com>
Junio C Hamano committed
Aug 7, 2013 at 14:43 UTC
db5723c6283d9a8dff3397c432af80cf5e2f7766
1 file changed
+26
-20
builtin/fetch.c
+26
-20
@@ -720,6 +720,31 @@ static int truncate_fetch_head(void)
720
return 0;
721
}
722
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
+
748
static int do_fetch(struct transport *transport,
749
struct refspec *refs, int ref_count)
750
{
@@ -816,17 +841,6 @@ static int do_fetch(struct transport *transport,
841
return retcode;
842
}
843
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
-
844
static int get_one_remote_for_fetch(struct remote *remote, void *priv)
845
{
846
struct string_list *list = priv;
@@ -949,15 +963,7 @@ static int fetch_one(struct remote *remote, int argc, const char **argv)
963
die(_("No remote repository specified. Please, specify either a URL or a\n"
964
"remote name from which new revisions should be fetched."));
965
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);
967
if (argc > 0) {
968
int j = 0;
969
refs = xcalloc(argc + 1, sizeof(const char *));