Thread (17 messages) flat view 17 messages, 1 author, 2016-06-15
DORMANTno replies

[PATCH 09/16] tag: add --column

From: Nguyễn Thái Ngọc Duy <hidden>
Date: 2016-06-15 22:50:32
Subsystem: documentation, kernel build + files below scripts/ (unless maintained elsewhere), the rest · Maintainers: Jonathan Corbet, Nathan Chancellor, Nicolas Schier, Linus Torvalds

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
 Documentation/git-tag.txt |    9 ++++++++-
 Makefile                  |    2 +-
 builtin/tag.c             |   21 +++++++++++++++++----
 3 files changed, 26 insertions(+), 6 deletions(-)
diff --git a/Documentation/git-tag.txt b/Documentation/git-tag.txt
index 8b169e3..89c55fb 100644
--- a/Documentation/git-tag.txt
+++ b/Documentation/git-tag.txt
@@ -12,7 +12,8 @@ SYNOPSIS
 'git tag' [-a | -s | -u <key-id>] [-f] [-m <msg> | -F <file>]
 	<tagname> [<commit> | <object>]
 'git tag' -d <tagname>...
-'git tag' [-n[<num>]] -l [--contains <commit>] [<pattern>]
+'git tag' [-n[<num>]] -l [--column[=<options>] | --no-column]
+	[--contains <commit>] [<pattern>]
 'git tag' -v <tagname>...
 
 DESCRIPTION
@@ -71,6 +72,12 @@ OPTIONS
 	List tags with names that match the given pattern (or all if no pattern is given).
 	Typing "git tag" without arguments, also lists all tags.
 
+--column::
+--no-column::
+	Whether show tags in columns. This option is only applicable if `git
+	tag` is used to list tags without annotation lines. See core.column
+	for options.
+
 --contains <commit>::
 	Only list tags which contain the specified commit.
 
diff --git a/Makefile b/Makefile
index a687e73..c9fd9aa 100644
--- a/Makefile
+++ b/Makefile
@@ -1958,7 +1958,7 @@ builtin/prune.o builtin/reflog.o reachable.o: reachable.h
 builtin/commit.o builtin/revert.o wt-status.o: wt-status.h
 builtin/tar-tree.o archive-tar.o: tar.h
 connect.o transport.o http-backend.o: url.h
-column.o pager.o help.o: column.h
+column.o pager.o help.o tag.o: column.h
 http-fetch.o http-walker.o remote-curl.o transport.o walker.o: walker.h
 http.o http-walker.o http-push.o http-fetch.o remote-curl.o: http.h url.h
 
diff --git a/builtin/tag.c b/builtin/tag.c
index aa1f87d..2b6cae9 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -12,6 +12,8 @@
 #include "tag.h"
 #include "run-command.h"
 #include "parse-options.h"
+#include "string-list.h"
+#include "column.h"
 
 static const char * const git_tag_usage[] = {
 	"git tag [-a|-s|-u <key-id>] [-f] [-m <msg>|-F <file>] <tagname> [<head>]",
@@ -22,6 +24,7 @@ static const char * const git_tag_usage[] = {
 };
 
 static char signingkey[1000];
+static struct string_list output;
 
 struct tag_filter {
 	const char *pattern;
@@ -52,7 +55,7 @@ static int show_reference(const char *refname, const unsigned char *sha1,
 		}
 
 		if (!filter->lines) {
-			printf("%s\n", refname);
+			string_list_append(&output, refname);
 			return 0;
 		}
 		printf("%-15s ", refname);
@@ -361,7 +364,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 	struct ref_lock *lock;
 
 	int annotate = 0, sign = 0, force = 0, lines = -1,
-		list = 0, delete = 0, verify = 0;
+		list = 0, delete = 0, verify = 0, column_mode;
 	const char *msgfile = NULL, *keyid = NULL;
 	struct msg_arg msg = { 0, STRBUF_INIT };
 	struct commit_list *with_commit = NULL;
@@ -383,6 +386,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 		OPT_STRING('u', NULL, &keyid, "key-id",
 					"use another key to sign the tag"),
 		OPT__FORCE(&force, "replace the tag if exists"),
+		OPT_COLUMN(0, "column", &column_mode, "show tag list in columns" ),
 
 		OPT_GROUP("Tag listing options"),
 		{
@@ -395,6 +399,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 	};
 
 	git_config(git_tag_config, NULL);
+	column_mode = core_column;
+	output.strdup_strings = 1;
 
 	argc = parse_options(argc, argv, prefix, options, git_tag_usage, 0);
 
@@ -413,9 +419,16 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 
 	if (list + delete + verify > 1)
 		usage_with_options(git_tag_usage, options);
-	if (list)
-		return list_tags(argv[0], lines == -1 ? 0 : lines,
+	if (list) {
+		int ret;
+
+		if (lines != -1)
+			column_mode = COL_MODE_PLAIN;
+		ret =  list_tags(argv[0], lines == -1 ? 0 : lines,
 				 with_commit);
+		display_columns(&output, column_mode, term_columns(), 2, "");
+		return ret;
+	}
 	if (lines != -1)
 		die("-n option is only allowed with -l.");
 	if (with_commit)
-- 
1.7.2.2
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help