diff mbox series

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

Message ID pull.1227.v4.git.1652095969026.gitgitgadget@gmail.com (mailing list archive)
State Accepted
Commit ef6d15ca536a50d916f8d9c7f600d650810161b1
Headers show
Series [v4] builtin/remote.c: teach `-v` to list filters for promisor remotes | expand

Commit Message

Abhradeep Chakraborty May 9, 2022, 11:32 a.m. UTC
From: Abhradeep Chakraborty <chakrabortyabhradeep79@gmail.com>

`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>
---
    builtin/remote.c: teach -v to list filters for promisor remotes
    
    Fixes #1211 [1]
    
    Changes since v3:
    
     * tests are moved to t5505-remote.sh
     * Documentation improved
     * Added Closes trailer in the commit message
    
    Changes since v2:
    
     * added more test cases
     * fixed broken indentations
    
    Changes since v1:
    
     * updated documentation
     * renamed url_buf into remote_info_buf
    
    [1] https://github.com/gitgitgadget/git/issues/1211

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1227%2FAbhra303%2Fpromisor_remote-v4
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1227/Abhra303/promisor_remote-v4
Pull-Request: https://github.com/gitgitgadget/git/pull/1227

Range-diff vs v3:

 1:  9ac6ca9a08e ! 1:  a067435285b builtin/remote.c: teach `-v` to list filters for promisor remotes
     @@ Commit message
          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
     +    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]
     @@ Commit message
      
          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>
      
       ## Documentation/git-remote.txt ##
     @@ Documentation/git-remote.txt: OPTIONS
       -v::
       --verbose::
       	Be a little more verbose and show remote url after name.
     -+	For promisor remotes it will show an extra information
     -+	(wrapped in square brackets) describing which filter
     -+	(`blob:none` etc.) that promisor remote use.
     ++	For promisor remotes, also show which filter (`blob:none` etc.)
     ++	are configured.
       	NOTE: This must be placed between `remote` and subcommand.
       
       
     @@ builtin/remote.c: static int get_one_entry(struct remote *remote, void *priv)
       
       	return 0;
      
     - ## t/t5616-partial-clone.sh ##
     -@@ t/t5616-partial-clone.sh: test_expect_success 'do partial clone 1' '
     - 	test "$(git -C pc1 config --local remote.origin.partialclonefilter)" = "blob:none"
     + ## t/t5505-remote.sh ##
     +@@ t/t5505-remote.sh: test_expect_success 'add another remote' '
     + 	)
       '
       
     ++test_expect_success 'setup bare clone for server' '
     ++	git clone --bare "file://$(pwd)/one" srv.bare &&
     ++	git -C srv.bare config --local uploadpack.allowfilter 1 &&
     ++	git -C srv.bare config --local uploadpack.allowanysha1inwant 1
     ++'
     ++
      +test_expect_success 'filters for promisor remotes are listed by git remote -v' '
     -+	test_when_finished "rm -rf pc2" &&
     -+	git clone --filter=blob:none "file://$(pwd)/srv.bare" pc2 &&
     -+	git -C pc2 remote -v >out &&
     ++	test_when_finished "rm -rf pc" &&
     ++	git clone --filter=blob:none "file://$(pwd)/srv.bare" pc &&
     ++	git -C pc remote -v >out &&
      +	grep "srv.bare (fetch) \[blob:none\]" out &&
      +
     -+	git -C pc2 config remote.origin.partialCloneFilter object:type=commit &&
     -+	git -C pc2 remote -v >out &&
     ++	git -C pc config remote.origin.partialCloneFilter object:type=commit &&
     ++	git -C pc remote -v >out &&
      +	grep "srv.bare (fetch) \[object:type=commit\]" out
      +'
      +
      +test_expect_success 'filters should not be listed for non promisor remotes (remote -v)' '
     -+	test_when_finished "rm -rf pc2" &&
     -+	git clone "file://$(pwd)/srv.bare" pc2 &&
     -+	git -C pc2 remote -v >out &&
     ++	test_when_finished "rm -rf pc" &&
     ++	git clone one pc &&
     ++	git -C pc remote -v >out &&
      +	! grep "(fetch) \[.*\]" out
      +'
      +
      +test_expect_success 'filters are listed by git remote -v only' '
     -+	test_when_finished "rm -rf pc2" &&
     -+	git clone --filter=blob:none "file://$(pwd)/srv.bare" pc2 &&
     -+	git -C pc2 remote >out &&
     ++	test_when_finished "rm -rf pc" &&
     ++	git clone --filter=blob:none "file://$(pwd)/srv.bare" pc &&
     ++	git -C pc remote >out &&
      +	! grep "\[blob:none\]" out &&
      +
     -+	git -C pc2 remote show >out &&
     ++	git -C pc remote show >out &&
      +	! grep "\[blob:none\]" out
      +'
      +
     - test_expect_success 'verify that .promisor file contains refs fetched' '
     - 	ls pc1/.git/objects/pack/pack-*.promisor >promisorlist &&
     - 	test_line_count = 1 promisorlist &&
     + test_expect_success 'check remote-tracking' '
     + 	(
     + 		cd test &&


 Documentation/git-remote.txt |  2 ++
 builtin/remote.c             | 18 +++++++++++++-----
 t/t5505-remote.sh            | 34 ++++++++++++++++++++++++++++++++++
 3 files changed, 49 insertions(+), 5 deletions(-)


base-commit: 0f828332d5ac36fc63b7d8202652efa152809856

Comments

Taylor Blau May 9, 2022, 3:34 p.m. UTC | #1
On Mon, May 09, 2022 at 11:32:48AM +0000, Abhradeep Chakraborty via GitGitGadget wrote:
> From: Abhradeep Chakraborty <chakrabortyabhradeep79@gmail.com>
>
> `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 -

This version looks like it has addressed many (all?) of the comments
previously discussed during review. On a quick scan, the code and tests
look good to my eyes, too.

But there was a good question raised by Phillip in

    https://lore.kernel.org/git/ab047b4b-6037-af78-1af6-ad35ac6d7c90@iee.email/

that I didn't see addressed in your response, which was "why not put
this behind a new `--show-partial-filter` option"?

I share (what I think is) Junio's feeling that having information that
is readily available from e.g., running "git config --get
remote.<name>.partialObjectFilter" seems redundant. I could understand
forcing a user to know the config key's name feels like a hurdle. But
cluttering the output of `git remote -v` seems like the wrong solution
to that hurdle.

But I can see where it _would_ be useful. So it would be nice to be able
to turn the extra output on in those cases, but _only_ those cases, and
a flag would be a nice way to go about doing that.

Thanks,
Taylor
Philippe Blain May 9, 2022, 5:01 p.m. UTC | #2
Hi Taylor,

Le 2022-05-09 à 11:34, Taylor Blau a écrit :
> On Mon, May 09, 2022 at 11:32:48AM +0000, Abhradeep Chakraborty via GitGitGadget wrote:
>> From: Abhradeep Chakraborty <chakrabortyabhradeep79@gmail.com>
>>
>> `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 -
> 
> This version looks like it has addressed many (all?) of the comments
> previously discussed during review. On a quick scan, the code and tests
> look good to my eyes, too.
> 
> But there was a good question raised by Phillip in
> 
>     https://lore.kernel.org/git/ab047b4b-6037-af78-1af6-ad35ac6d7c90@iee.email/
> 
> that I didn't see addressed in your response, which was "why not put
> this behind a new `--show-partial-filter` option"?

I originally opened the issue on GGG that this series adresses.
My justification, and asnwer to that question, is simple:
'git remote -v', for me, is a way to ask Git to give me all the information it 
knows about my configured remotes. That's why I thought that it would 
be really nice if partial clones filters would be shown. 

After all, 'git remote' is listed in the 'porcelain' section of the 
Git commands [1], and isn't the goal of declaring commands "porcelain"
that we can make their output more useful to the users without worrying as
much about backwards compatibility than with plumbing commands?

> I share (what I think is) Junio's feeling that having information that
> is readily available from e.g., running "git config --get
> remote.<name>.partialObjectFilter" seems redundant. I could understand
> forcing a user to know the config key's name feels like a hurdle. But
> cluttering the output of `git remote -v` seems like the wrong solution
> to that hurdle.

As I said above, I have 'git rem' (my alias for 'git remote -v') in my muscle
memory and use it when I want to have an outline of my configured remotes.
I think it would be really easier to add the filters info to the existing output.
It's really faster to type than using 'git config', and you do not have to remember
which remote name to query. I think "clutter" is a little strong word here :)

> But I can see where it _would_ be useful. So it would be nice to be able
> to turn the extra output on in those cases, but _only_ those cases, and
> a flag would be a nice way to go about doing that.

If really this topic is blocked by "we do not want to change the default output
of 'git remote -v'", then I agree it would be nice to be able to set 
'remote.showFilters' (or similar) to get such output, I agree.

Or, making 'git remote' act like 'git branch' and accept a second '-v', i.e.
'git remote -vv' would list filters (then I would just adjust my alias :P). 
Then we can outright declare "the output of 'git remote -vv' is subject to 
future changes to show more useful information", or similar, so we do not
have to do the same dance the next time we want to add some other info.

The downside of hiding such new features behing config values or additional flags
is that it really, really limits their discoverability. This is something that I 
often think about and think we should really do better in Git, in general. 
For example, features like 'remote.pushDefault' or the 'diff=*' attribute
for language-aware hunk headers (and funcname-limited log/blame etc) are immensely 
useful, but often even experienced and long-time Git users do not even know they exist, 
because they are not covered in "regular" Git tutorials...

Cheers,

Philippe.

[1] https://git-scm.com/docs/git#Documentation/git.txt-ahrefdocsgit-remotegit-remote1a
Abhradeep Chakraborty May 9, 2022, 5:21 p.m. UTC | #3
Taylor Blau <me@ttaylorr.com> wrote:

> But there was a good question raised by Phillip in
>
>     https://lore.kernel.org/git/ab047b4b-6037-af78-1af6-ad35ac6d7c90@iee.email/
>
> that I didn't see addressed in your response, which was "why not put
> this behind a new `--show-partial-filter` option"?

Actually, I addressed it[1] -

> ... Another point is that
> it's important for an user to know which one is a promisor remote and what
> filter type they use. If we go with the current implementation the output
> would be let's say - 
> origin <remote-url> (fetch)
> origin <remote-url> (push)
> upstream <remote-url> (fetch)
> upstream <remote-url> (push)
>
> By seeing the above output anyone may assume that all the remotes are
> normal remotes. If the user now try to run `git pull origin` and suddenly
> he/she discover that some blobs are not downloaded. He/she run the above
> mentioned (1) command and find that this is a promisor remote!
>
> Here `remote -v` didn't warn the user about the origin remote being an
> promisor remote. Instead it makes him/her assume that all are normal
> remotes. Providing only these three info (i.e. <remote-name>, <remote-url>
> and <direction>) is not sufficient - it only shows the half of the picture.

If we use a new `--show-partial-clone` flag, users can get to know about
promisor remotes only if he/she use this flag. As I said in the refered
comment, it may happen that the user unfortunately use the flag AFTER the
accident - to know about if that was the promisor remote!

See this also[2] - 

> ... If
> we can specify `(fetch)` in the output then why not the filter of that
> `fetch` on which the behaviour of `fetch` functionality highly depends?

Taylor Blau <me@ttaylorr.com> wrote:

> But I can see where it _would_ be useful. So it would be nice to be able
> to turn the extra output on in those cases, but _only_ those cases, and
> a flag would be a nice way to go about doing that.

Adding the extra flag is not a good approach to me due to the above reason.
But at the end of the day, all of you have a lots of experience in this field
than me. You all could better tell which one is better approach.


[1] https://lore.kernel.org/git/20220501193807.94369-1-chakrabortyabhradeep79@gmail.com/
[2] https://lore.kernel.org/git/20220502145624.12702-1-chakrabortyabhradeep79@gmail.com/

Thanks :)
Abhradeep Chakraborty May 9, 2022, 5:44 p.m. UTC | #4
Taylor Blau <me@ttaylorr.com> wrote:

> This version looks like it has addressed many (all?) of the comments
previously discussed during review.

To my knowledge, yeah, I addressed all the comments :)


Thanks :)
Junio C Hamano May 9, 2022, 5:52 p.m. UTC | #5
Philippe Blain <levraiphilippeblain@gmail.com> writes:

> Or, making 'git remote' act like 'git branch' and accept a second '-v', i.e.
> 'git remote -vv' would list filters (then I would just adjust my alias :P). 
> Then we can outright declare "the output of 'git remote -vv' is subject to 
> future changes to show more useful information", or similar, so we do not
> have to do the same dance the next time we want to add some other info.

Isn't it where we already are with "remote -v", though?  I am not
sure addition of excess information that may not be universally
useful is a very welcome change, even with "remote -v -v".  I am not
worried about showing the "list-object-filter", but I worry about
managing temptations of future developers to add other stuff.

> The downside of hiding such new features behing config values or additional flags
> is that it really, really limits their discoverability. This is something that I 
> often think about and think we should really do better in Git, in general. 
> For example, features like 'remote.pushDefault' or the 'diff=*' attribute
> for language-aware hunk headers (and funcname-limited log/blame etc) are immensely 
> useful, but often even experienced and long-time Git users do not even know they exist, 
> because they are not covered in "regular" Git tutorials...

Unfortunately, it is not exactly a solution for that to update the
tutorial, because experienced and long-time users rightly consider
themselves beyond tutorials and sometimes documentation.
Taylor Blau May 9, 2022, 10:22 p.m. UTC | #6
On Mon, May 09, 2022 at 10:51:57PM +0530, Abhradeep Chakraborty wrote:
> Taylor Blau <me@ttaylorr.com> wrote:
>
> > But there was a good question raised by Phillip in
> >
> >     https://lore.kernel.org/git/ab047b4b-6037-af78-1af6-ad35ac6d7c90@iee.email/
> >
> > that I didn't see addressed in your response, which was "why not put
> > this behind a new `--show-partial-filter` option"?
>
> Actually, I addressed it[1] -

Ah, sorry that I missed it! I think Phillipe's GGG issue is probably a
good signal that we are not making this information as discoverable to
users as we could be.

I share Junio's concern that this change may tempt future contributors
to add more output still to "git remote", but perhaps not. So I'd be OK
with this change as-is.

> [1] https://lore.kernel.org/git/20220501193807.94369-1-chakrabortyabhradeep79@gmail.com/

Thanks,
Taylor
Abhradeep Chakraborty May 13, 2022, 1:49 p.m. UTC | #7
Junio C Hamano <gitster@pobox.com> wrote:

> Isn't it where we already are with "remote -v", though?  I am not
> sure addition of excess information that may not be universally
> useful is a very welcome change, even with "remote -v -v".  I am not
> worried about showing the "list-object-filter", but I worry about
> managing temptations of future developers to add other stuff.

If future developers come up with some really useful stuff (i.e. 
universally useful), I think those should be added in the output
irrespective of the no of existing info in the output. If the
output becomes messy, we should focus on how we can make the output
clear may be using tabular format.

Else you can drop the idea and suggest them to introduce a new flag
(depending on the situation). If you still have some doubt about my
PR i.e. if you can not determine which category my PR belongs to, I
can go with adding `show-partial-clone` flag. The downside would
be that `remote -v` will not give the full summary in case of partial
clone.

If you like the tabular format approach, I am further going to propose
a table format -

+---------------+----------------------------------------------+
|  remote name  |          remote info                         |
+---------------+--------+--------+----------------------------+
|               |        | url    | https://blah.com/blah.git  |
|  origin       |        +--------+----------------------------+
|               |        | filter | blob:none                  |
|               | fetch  +--------+----------------------------+
|               |        | .                                   |
|               |        | .     (some important data)         |
|               +--------+--------+----------------------------+
|               |        | url    | https://blah.com/blah.git  |
|               | push   +--------+----------------------------+
|               |        | ... (some important data)           |
+---------------+--------+-------------------------------------+

In this way, user can see the summary of all remotes with visual ease.
Of course it is not suitable for scripting. In that case we can use
a new flag `--raw` which will let `-v` to provide a space/tab seperated
sequence of info (similar to current format).

Let me know if you (as in all) like/dislike my view and give your
arguments regarding my proposal.

Thanks :)
Junio C Hamano May 13, 2022, 6:37 p.m. UTC | #8
Abhradeep Chakraborty <chakrabortyabhradeep79@gmail.com> writes:

> Else you can drop the idea and suggest them to introduce a new flag
> (depending on the situation). If you still have some doubt about my
> PR i.e. if you can not determine which category my PR belongs to, I
> can go with adding `show-partial-clone` flag. The downside would
> be that `remote -v` will not give the full summary in case of partial
> clone.

If majority of partial-clone users find it unnecessary noise, then
it may be an upside to give only reduced summary that is less than
full that may be given by `remote -v -v`.

Worse downside of adding it as an option is that it invites more
options.  It is less worse to add new ones to `remote -v -v` (or to
`remote -v`, or not adding it at all) than adding another option, I
would think.

Perhaps tagged output that can be easier to parse would be better
"extensible" output format for adding more random pieces of
information than going tabular.  I dunno.
Abhradeep Chakraborty May 16, 2022, 3:38 p.m. UTC | #9
Junio C Hamano <gitster@pobox.com> wrote:

> If majority of partial-clone users find it unnecessary noise, then
> it may be an upside to give only reduced summary that is less than
> full that may be given by `remote -v -v`.

Should I add this to `remote -v -v` then?  `remote -vv` is currently
not implemented I guess.

> Perhaps tagged output that can be easier to parse would be better
> "extensible" output format for adding more random pieces of
> information than going tabular.  I dunno.

I am not sure what exactly you are refering by 'tagged output' but
it is true that tabular form is hard to parse. That's why I suggested
`--raw` flag which would be used for parsing. It would give the info
following the currently implemented format.

If you like the tagged output format, then should we implement `-vv` which
would give the output as the tagged output format and also can be
extended?
diff mbox series

Patch

diff --git a/Documentation/git-remote.txt b/Documentation/git-remote.txt
index cde9614e362..1dec3148348 100644
--- a/Documentation/git-remote.txt
+++ b/Documentation/git-remote.txt
@@ -35,6 +35,8 @@  OPTIONS
 -v::
 --verbose::
 	Be a little more verbose and show remote url after name.
+	For promisor remotes, also show which filter (`blob:none` etc.)
+	are configured.
 	NOTE: This must be placed between `remote` and subcommand.
 
 
diff --git a/builtin/remote.c b/builtin/remote.c
index 5f4cde9d784..d4b69fe7789 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -1185,14 +1185,22 @@  static int show_push_info_item(struct string_list_item *item, void *cb_data)
 static int get_one_entry(struct remote *remote, void *priv)
 {
 	struct string_list *list = priv;
-	struct strbuf url_buf = STRBUF_INIT;
+	struct strbuf remote_info_buf = STRBUF_INIT;
 	const char **url;
 	int i, url_nr;
 
 	if (remote->url_nr > 0) {
-		strbuf_addf(&url_buf, "%s (fetch)", remote->url[0]);
+		struct strbuf promisor_config = STRBUF_INIT;
+		const char *partial_clone_filter = NULL;
+
+		strbuf_addf(&promisor_config, "remote.%s.partialclonefilter", remote->name);
+		strbuf_addf(&remote_info_buf, "%s (fetch)", remote->url[0]);
+		if (!git_config_get_string_tmp(promisor_config.buf, &partial_clone_filter))
+			strbuf_addf(&remote_info_buf, " [%s]", partial_clone_filter);
+
+		strbuf_release(&promisor_config);
 		string_list_append(list, remote->name)->util =
-				strbuf_detach(&url_buf, NULL);
+				strbuf_detach(&remote_info_buf, NULL);
 	} else
 		string_list_append(list, remote->name)->util = NULL;
 	if (remote->pushurl_nr) {
@@ -1204,9 +1212,9 @@  static int get_one_entry(struct remote *remote, void *priv)
 	}
 	for (i = 0; i < url_nr; i++)
 	{
-		strbuf_addf(&url_buf, "%s (push)", url[i]);
+		strbuf_addf(&remote_info_buf, "%s (push)", url[i]);
 		string_list_append(list, remote->name)->util =
-				strbuf_detach(&url_buf, NULL);
+				strbuf_detach(&remote_info_buf, NULL);
 	}
 
 	return 0;
diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh
index c90cf47acdb..fff14e13ed4 100755
--- a/t/t5505-remote.sh
+++ b/t/t5505-remote.sh
@@ -78,6 +78,40 @@  test_expect_success 'add another remote' '
 	)
 '
 
+test_expect_success 'setup bare clone for server' '
+	git clone --bare "file://$(pwd)/one" srv.bare &&
+	git -C srv.bare config --local uploadpack.allowfilter 1 &&
+	git -C srv.bare config --local uploadpack.allowanysha1inwant 1
+'
+
+test_expect_success 'filters for promisor remotes are listed by git remote -v' '
+	test_when_finished "rm -rf pc" &&
+	git clone --filter=blob:none "file://$(pwd)/srv.bare" pc &&
+	git -C pc remote -v >out &&
+	grep "srv.bare (fetch) \[blob:none\]" out &&
+
+	git -C pc config remote.origin.partialCloneFilter object:type=commit &&
+	git -C pc remote -v >out &&
+	grep "srv.bare (fetch) \[object:type=commit\]" out
+'
+
+test_expect_success 'filters should not be listed for non promisor remotes (remote -v)' '
+	test_when_finished "rm -rf pc" &&
+	git clone one pc &&
+	git -C pc remote -v >out &&
+	! grep "(fetch) \[.*\]" out
+'
+
+test_expect_success 'filters are listed by git remote -v only' '
+	test_when_finished "rm -rf pc" &&
+	git clone --filter=blob:none "file://$(pwd)/srv.bare" pc &&
+	git -C pc remote >out &&
+	! grep "\[blob:none\]" out &&
+
+	git -C pc remote show >out &&
+	! grep "\[blob:none\]" out
+'
+
 test_expect_success 'check remote-tracking' '
 	(
 		cd test &&