builtin/remote.c: teach `-v` to list filters for promisor remotes

`git remote -v` (`--verbose`) lists down the names of remotes along with their URLs. It would be beneficial for users to also specify the filter types for promisor remotes. Something like this - origin remote-url (fetch) [blob:none] origin remote-url (push) Teach `git remote -v` to also specify the filters for promisor remotes. Closes: https://github.com/gitgitgadget/git/issues/1211 Signed-off-by: Abhradeep Chakraborty <chakrabortyabhradeep79@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Abhradeep Chakraborty committed May 9, 2022 at 11:32 UTC ef6d15ca536a50d916f8d9c7f600d650810161b1
3 files changed +49 -5
Documentation/git-remote.txt
+2
@@ -35,6 +35,8 @@ OPTIONS
35 -v::
36 --verbose::
37 Be a little more verbose and show remote url after name.
38 + For promisor remotes, also show which filter (`blob:none` etc.)
39 + are configured.
40 NOTE: This must be placed between `remote` and subcommand.
41
42
builtin/remote.c
+13 -5
@@ -1185,14 +1185,22 @@ static int show_push_info_item(struct string_list_item *item, void *cb_data)
1185 static int get_one_entry(struct remote *remote, void *priv)
1186 {
1187 struct string_list *list = priv;
1188 - struct strbuf url_buf = STRBUF_INIT;
1188 + struct strbuf remote_info_buf = STRBUF_INIT;
1189 const char **url;
1190 int i, url_nr;
1191
1192 if (remote->url_nr > 0) {
1193 - strbuf_addf(&url_buf, "%s (fetch)", remote->url[0]);
1193 + struct strbuf promisor_config = STRBUF_INIT;
1194 + const char *partial_clone_filter = NULL;
1195 +
1196 + strbuf_addf(&promisor_config, "remote.%s.partialclonefilter", remote->name);
1197 + strbuf_addf(&remote_info_buf, "%s (fetch)", remote->url[0]);
1198 + if (!git_config_get_string_tmp(promisor_config.buf, &partial_clone_filter))
1199 + strbuf_addf(&remote_info_buf, " [%s]", partial_clone_filter);
1200 +
1201 + strbuf_release(&promisor_config);
1202 string_list_append(list, remote->name)->util =
1195 - strbuf_detach(&url_buf, NULL);
1203 + strbuf_detach(&remote_info_buf, NULL);
1204 } else
1205 string_list_append(list, remote->name)->util = NULL;
1206 if (remote->pushurl_nr) {
@@ -1204,9 +1212,9 @@ static int get_one_entry(struct remote *remote, void *priv)
1212 }
1213 for (i = 0; i < url_nr; i++)
1214 {
1207 - strbuf_addf(&url_buf, "%s (push)", url[i]);
1215 + strbuf_addf(&remote_info_buf, "%s (push)", url[i]);
1216 string_list_append(list, remote->name)->util =
1209 - strbuf_detach(&url_buf, NULL);
1217 + strbuf_detach(&remote_info_buf, NULL);
1218 }
1219
1220 return 0;
t/t5505-remote.sh
+34
@@ -78,6 +78,40 @@ test_expect_success 'add another remote' '
78 )
79 '
80
81 +test_expect_success 'setup bare clone for server' '
82 + git clone --bare "file://$(pwd)/one" srv.bare &&
83 + git -C srv.bare config --local uploadpack.allowfilter 1 &&
84 + git -C srv.bare config --local uploadpack.allowanysha1inwant 1
85 +'
86 +
87 +test_expect_success 'filters for promisor remotes are listed by git remote -v' '
88 + test_when_finished "rm -rf pc" &&
89 + git clone --filter=blob:none "file://$(pwd)/srv.bare" pc &&
90 + git -C pc remote -v >out &&
91 + grep "srv.bare (fetch) \[blob:none\]" out &&
92 +
93 + git -C pc config remote.origin.partialCloneFilter object:type=commit &&
94 + git -C pc remote -v >out &&
95 + grep "srv.bare (fetch) \[object:type=commit\]" out
96 +'
97 +
98 +test_expect_success 'filters should not be listed for non promisor remotes (remote -v)' '
99 + test_when_finished "rm -rf pc" &&
100 + git clone one pc &&
101 + git -C pc remote -v >out &&
102 + ! grep "(fetch) \[.*\]" out
103 +'
104 +
105 +test_expect_success 'filters are listed by git remote -v only' '
106 + test_when_finished "rm -rf pc" &&
107 + git clone --filter=blob:none "file://$(pwd)/srv.bare" pc &&
108 + git -C pc remote >out &&
109 + ! grep "\[blob:none\]" out &&
110 +
111 + git -C pc remote show >out &&
112 + ! grep "\[blob:none\]" out
113 +'
114 +
115 test_expect_success 'check remote-tracking' '
116 (
117 cd test &&