]> git.ipfire.org Git - thirdparty/git.git/blob - t/helper/test-bundle-uri.c
test-lib: ignore uninteresting LSan output
[thirdparty/git.git] / t / helper / test-bundle-uri.c
1 #include "test-tool.h"
2 #include "parse-options.h"
3 #include "bundle-uri.h"
4 #include "strbuf.h"
5 #include "string-list.h"
6 #include "transport.h"
7 #include "ref-filter.h"
8 #include "remote.h"
9 #include "refs.h"
10
11 enum input_mode {
12 KEY_VALUE_PAIRS,
13 CONFIG_FILE,
14 };
15
16 static int cmd__bundle_uri_parse(int argc, const char **argv, enum input_mode mode)
17 {
18 const char *key_value_usage[] = {
19 "test-tool bundle-uri parse-key-values <input>",
20 NULL
21 };
22 const char *config_usage[] = {
23 "test-tool bundle-uri parse-config <input>",
24 NULL
25 };
26 const char **usage = key_value_usage;
27 struct option options[] = {
28 OPT_END(),
29 };
30 struct strbuf sb = STRBUF_INIT;
31 struct bundle_list list;
32 int err = 0;
33 FILE *fp;
34
35 if (mode == CONFIG_FILE)
36 usage = config_usage;
37
38 argc = parse_options(argc, argv, NULL, options, usage,
39 PARSE_OPT_STOP_AT_NON_OPTION);
40
41 init_bundle_list(&list);
42
43 list.baseURI = xstrdup("<uri>");
44
45 switch (mode) {
46 case KEY_VALUE_PAIRS:
47 if (argc != 1)
48 goto usage;
49 fp = fopen(argv[0], "r");
50 if (!fp)
51 die("failed to open '%s'", argv[0]);
52 while (strbuf_getline(&sb, fp) != EOF) {
53 if (bundle_uri_parse_line(&list, sb.buf))
54 err = error("bad line: '%s'", sb.buf);
55 }
56 fclose(fp);
57 break;
58
59 case CONFIG_FILE:
60 if (argc != 1)
61 goto usage;
62 err = bundle_uri_parse_config_format("<uri>", argv[0], &list);
63 break;
64 }
65 strbuf_release(&sb);
66
67 print_bundle_list(stdout, &list);
68
69 clear_bundle_list(&list);
70
71 return !!err;
72
73 usage:
74 usage_with_options(usage, options);
75 }
76
77 static int cmd_ls_remote(int argc, const char **argv)
78 {
79 const char *dest;
80 struct remote *remote;
81 struct transport *transport;
82 int status = 0;
83
84 dest = argc > 1 ? argv[1] : NULL;
85
86 remote = remote_get(dest);
87 if (!remote) {
88 if (dest)
89 die(_("bad repository '%s'"), dest);
90 die(_("no remote configured to get bundle URIs from"));
91 }
92 if (!remote->url_nr)
93 die(_("remote '%s' has no configured URL"), dest);
94
95 transport = transport_get(remote, NULL);
96 if (transport_get_remote_bundle_uri(transport) < 0) {
97 error(_("could not get the bundle-uri list"));
98 status = 1;
99 goto cleanup;
100 }
101
102 print_bundle_list(stdout, transport->bundles);
103
104 cleanup:
105 if (transport_disconnect(transport))
106 return 1;
107 return status;
108 }
109
110 int cmd__bundle_uri(int argc, const char **argv)
111 {
112 const char *usage[] = {
113 "test-tool bundle-uri <subcommand> [<options>]",
114 NULL
115 };
116 struct option options[] = {
117 OPT_END(),
118 };
119
120 argc = parse_options(argc, argv, NULL, options, usage,
121 PARSE_OPT_STOP_AT_NON_OPTION |
122 PARSE_OPT_KEEP_ARGV0);
123 if (argc == 1)
124 goto usage;
125
126 if (!strcmp(argv[1], "parse-key-values"))
127 return cmd__bundle_uri_parse(argc - 1, argv + 1, KEY_VALUE_PAIRS);
128 if (!strcmp(argv[1], "parse-config"))
129 return cmd__bundle_uri_parse(argc - 1, argv + 1, CONFIG_FILE);
130 if (!strcmp(argv[1], "ls-remote"))
131 return cmd_ls_remote(argc - 1, argv + 1);
132 error("there is no test-tool bundle-uri tool '%s'", argv[1]);
133
134 usage:
135 usage_with_options(usage, options);
136 }