Skip to contentSkip to conversation

show git tag output in pager

PATCH In review Michal Vyskocil 3 participants 8 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 show git tag output in pager

---
 builtin/tag.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
builtin/tag.c +2 -0
index 667515e..9f70fa8 100644
@@ -147,6 +147,8 @@ static int list_tags(const char **patterns, int lines,
 			struct commit_list *with_commit)
 {
 	struct tag_filter filter;
+        
+        setup_pager();
 
 	filter.patterns = patterns;
 	filter.lines = lines;
Signature · 1 line
1.7.6.3
#1 lore raw

The commit message should explain why this is needed, and in particular why you prefer this to setting pager.tag in your ~/.gitconfig.

builtin/tag.c static int list_tags(const char **patterns, int lines, · line 151

Quoted 8 lines · Michal Vyskocil
builtin/tag.c +2 -0
@@ -147,6 +147,8 @@ static int list_tags(const char **patterns, int lines,
 			struct commit_list *with_commit)
 {
 	struct tag_filter filter;
+        
+        setup_pager();

Git indents with tabs, not spaces, and does not leave trailing whitespaces.

Signature · 2 lines
Matthieu Moy
http://www-verimag.imag.fr/~moy/
#2 lore raw
Quoted 2 lines · Matthieu Moy

The commit message should explain why this is needed, and in particular why you prefer this to setting pager.tag in your ~/.gitconfig.

Opps! I read a documentation, but I did not realize this works for all commands and not only for them calling setup_pager(). Then sorry, no change is needed.

Quoted 14 lines

builtin/tag.c static int list_tags(const char **patterns, int lines, · line 151

Quoted 8 lines · Michal Vyskocil
builtin/tag.c +2 -0
@@ -147,6 +147,8 @@ static int list_tags(const char **patterns, int lines,
 			struct commit_list *with_commit)
 {
 	struct tag_filter filter;
+        
+        setup_pager();

Git indents with tabs, not spaces, and does not leave trailing whitespaces.

OK, thanks for the feedbac. I will try to be more carefull in the future.

Regards
Michal Vyskocil

Quoted 4 lines
Signature · 3 lines
-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
#3 lore raw
Quoted 7 lines · Michal Vyskocil
Quoted 2 lines · Matthieu Moy

The commit message should explain why this is needed, and in particular why you prefer this to setting pager.tag in your ~/.gitconfig.

Opps! I read a documentation, but I did not realize this works for all commands and not only for them calling setup_pager(). Then sorry, no change is needed.

I don't think you want to set pager.tag. It will invoke the pager for all tag subcommands, including tag creation and deletion. It's not a huge deal if your pager exits immediately when the input is less than a page (which I think our default LESS settings will do). But I wouldn't be surprised if it ends up confusing some program at some point.

I think instead, you want some way for commands to say "OK, I'm in a subcommand that might or might not want a pager now".

Something like the (thoroughly not tested) patch below, which you can use like:

git config pager.tag.list

builtin.h +1 -0
index 0e9da90..d0fe971 100644
@@ -35,6 +35,7 @@ int copy_note_for_rewrite(struct notes_rewrite_cfg *c,
 void finish_copy_notes_for_rewrite(struct notes_rewrite_cfg *c);
 
 extern int check_pager_config(const char *cmd);
+extern void try_subcommand_pager(const char *subcommand);
 
 extern int textconv_object(const char *path, unsigned mode, const unsigned char *sha1, char **buf, unsigned long *buf_size);
 
builtin/tag.c +1 -0
index 667515e..bc45fe6 100644
@@ -152,6 +152,7 @@ static int list_tags(const char **patterns, int lines,
 	filter.lines = lines;
 	filter.with_commit = with_commit;
 
+	try_subcommand_pager("tag.list");
 	for_each_tag_ref(show_reference, (void *) &filter);
 
 	return 0;
git.c +10 -0
index 8e34903..60fbf1e 100644
@@ -64,6 +64,16 @@ static void commit_pager_choice(void) {
 	}
 }
 
+void try_subcommand_pager(const char *subcommand)
+{
+	/* it's too late to turn off a running pager */
+	if (pager_in_use())
+		return;
+
+	use_pager = check_pager_config(subcommand);
+	commit_pager_choice();
+}
+
 static int handle_options(const char ***argv, int *argc, int *envchanged)
 {
 	const char **orig_argv = *argv;

Other programs like "git branch list" would probably want similar hooks.

For commands like "tag" and "branch" where there's really only one operation that you would want to be paged (i.e., "list"), it's tempting to also (or instead) make "pager.tag" only affect the useful command.

That's not too hard for internal commands like "tag" (patch below). But I'm not sure how you would do it for something external like "stash"; from git.c's perspective, we don't know anything about stash or whether it would want to respect pager config or not.

builtin/tag.c +1 -1
index bc45fe6..bbdb135 100644
@@ -152,7 +152,7 @@ static int list_tags(const char **patterns, int lines,
 	filter.lines = lines;
 	filter.with_commit = with_commit;
 
-	try_subcommand_pager("tag.list");
+	try_subcommand_pager("tag");
 	for_each_tag_ref(show_reference, (void *) &filter);
 
 	return 0;
git.c +5 -2
index 60fbf1e..64a078d 100644
@@ -276,6 +276,7 @@ static int handle_alias(int *argcp, const char ***argv)
  * RUN_SETUP for reading from the configuration file.
  */
 #define NEED_WORK_TREE		(1<<3)
+#define NO_PAGER_CONFIG		(1<<4)
 
 struct cmd_struct {
 	const char *cmd;
@@ -299,7 +300,9 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
 			prefix = setup_git_directory_gently(&nongit_ok);
 		}
 
-		if (use_pager == -1 && p->option & (RUN_SETUP | RUN_SETUP_GENTLY))
+		if (use_pager == -1 &&
+		    p->option & (RUN_SETUP | RUN_SETUP_GENTLY) &&
+		    !(p->option & NO_PAGER_CONFIG))
 			use_pager = check_pager_config(p->cmd);
 		if (use_pager == -1 && p->option & USE_PAGER)
 			use_pager = 1;
@@ -436,7 +439,7 @@ static void handle_internal_command(int argc, const char **argv)
 		{ "status", cmd_status, RUN_SETUP | NEED_WORK_TREE },
 		{ "stripspace", cmd_stripspace },
 		{ "symbolic-ref", cmd_symbolic_ref, RUN_SETUP },
-		{ "tag", cmd_tag, RUN_SETUP },
+		{ "tag", cmd_tag, RUN_SETUP | NO_PAGER_CONFIG },
 		{ "tar-tree", cmd_tar_tree },
 		{ "unpack-file", cmd_unpack_file, RUN_SETUP },
 		{ "unpack-objects", cmd_unpack_objects, RUN_SETUP },

-Peff

#4 lore raw
Quoted 6 lines · Jeff King
Quoted 4 lines · Michal Vyskocil
Quoted 2 lines · Matthieu Moy

The commit message should explain why this is needed, and in particular why you prefer this to setting pager.tag in your ~/.gitconfig.

Quoted 6 lines
Quoted 3 lines

Opps! I read a documentation, but I did not realize this works for all commands and not only for them calling setup_pager(). Then sorry, no change is needed.

I don't think you want to set pager.tag. It will invoke the pager for all tag subcommands, including tag creation and deletion.

That's the kind of argument/discussion I was expecting in the commit message.

Quoted 2 lines

I think instead, you want some way for commands to say "OK, I'm in a subcommand that might or might not want a pager now".

Right.

I like the try_subcommand_pager idea. Ideally, there would also be a nice mechanism to set defaults for subcommands, so that "git tag <whatever>" does the right thing without configuration.

Signature · 2 lines
Matthieu Moy
http://www-verimag.imag.fr/~moy/
#5 lore raw
Quoted 3 lines · Matthieu Moy

I like the try_subcommand_pager idea. Ideally, there would also be a nice mechanism to set defaults for subcommands, so that "git tag <whatever>" does the right thing without configuration.

That's easy enough. Something like the patch below?

Still thoroughly untested, but it looks Obviously Correct to me. :)

---
 builtin.h     |    1 +
 builtin/tag.c |    1 +
 git.c         |   13 +++++++++++++
 3 files changed, 15 insertions(+), 0 deletions(-)
builtin.h +1 -0
index 0e9da90..b2badf8 100644
@@ -35,6 +35,7 @@ int copy_note_for_rewrite(struct notes_rewrite_cfg *c,
 void finish_copy_notes_for_rewrite(struct notes_rewrite_cfg *c);
 
 extern int check_pager_config(const char *cmd);
+extern void try_subcommand_pager(const char *subcommand, int fallback);
 
 extern int textconv_object(const char *path, unsigned mode, const unsigned char *sha1, char **buf, unsigned long *buf_size);
 
builtin/tag.c +1 -0
index 9d89616..c77adc4 100644
@@ -152,6 +152,7 @@ static int list_tags(const char **patterns, int lines,
 	filter.lines = lines;
 	filter.with_commit = with_commit;
 
+	try_subcommand_pager("tag.list", 1);
 	for_each_tag_ref(show_reference, (void *) &filter);
 
 	return 0;
git.c +13 -0
index 8e34903..11ee1a8 100644
@@ -64,6 +64,19 @@ static void commit_pager_choice(void) {
 	}
 }
 
+void try_subcommand_pager(const char *subcommand, int fallback)
+{
+	/* it's too late to turn off a running pager */
+	if (pager_in_use())
+		return;
+
+	if (use_pager == -1)
+		use_pager = check_pager_config(subcommand);
+	if (use_pager == -1)
+		use_pager = fallback;
+	commit_pager_choice();
+}
+
 static int handle_options(const char ***argv, int *argc, int *envchanged)
 {
 	const char **orig_argv = *argv;
Signature · 1 line
1.7.7.rc2.7.gdfc92
#6 lore raw
Quoted 7 lines · Jeff King
Quoted 3 lines · Matthieu Moy

I like the try_subcommand_pager idea. Ideally, there would also be a nice mechanism to set defaults for subcommands, so that "git tag <whatever>" does the right thing without configuration.

That's easy enough. Something like the patch below?

It may have been better with a big centralized array of configurations like

	static struct cmd_struct commands[] = {
		{ "add", cmd_add, RUN_SETUP | NEED_WORK_TREE },
                ...

in git.c, but if we have only a few instances of this, your system is probably fine. I like it.

Signature · 2 lines
Matthieu Moy
http://www-verimag.imag.fr/~moy/
#7 lore raw
Quoted 11 lines · Matthieu Moy
Quoted 7 lines · Matthieu Moy
Quoted 4 lines

I like the try_subcommand_pager idea. Ideally, there would also be a nice mechanism to set defaults for subcommands, so that "git tag <whatever>" does the right thing without configuration.

That's easy enough. Something like the patch below?

It may have been better with a big centralized array of configurations like

Quoted 6 lines
	static struct cmd_struct commands[] = {
		{ "add", cmd_add, RUN_SETUP | NEED_WORK_TREE },
                ...

in git.c, but if we have only a few instances of this, your system is probably fine. I like it.

I don't think you can centralize it in the same way, because some of it will have to be implemented in shell script (unlike the full-command ones, which we can always trigger at the git.c wrapper layer).

So you could have:

  static struct pager_default subcommands[] = {
          { "tag.list", 1 },
          { "branch.list", 1 },

};

but you'll never be able to put "stash.list" into that structure (and as you probably guessed, my patch isn't enough to implement stash.list, either; it would need a shell implementation of try_subcommand_pager).

-Peff