tag: add --column

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Apr 13, 2012 at 17:54 UTC d96e3c150f2b4508f2e7d23ce9183d5b807c2155
5 files changed +82 -4
Documentation/config.txt
+4
@@ -870,6 +870,10 @@ column.status::
870 Specify whether to output untracked files in `git status` in columns.
871 See `column.ui` for details.
872
873 +column.tag::
874 + Specify whether to output tag listing in `git tag` in columns.
875 + See `column.ui` for details.
876 +
877 commit.status::
878 A boolean to enable/disable inclusion of status information in the
879 commit message template when using an editor to prepare the commit
Documentation/git-tag.txt
+9
@@ -13,6 +13,7 @@ SYNOPSIS
13 <tagname> [<commit> | <object>]
14 'git tag' -d <tagname>...
15 'git tag' [-n[<num>]] -l [--contains <commit>] [--points-at <object>]
16 + [--column[=<options>] | --no-column] [<pattern>...]
17 [<pattern>...]
18 'git tag' -v <tagname>...
19
@@ -84,6 +85,14 @@ OPTIONS
85 using fnmatch(3)). Multiple patterns may be given; if any of
86 them matches, the tag is shown.
87
88 +--column[=<options>]::
89 +--no-column::
90 + Display tag listing in columns. See configuration variable
91 + column.tag for option syntax.`--column` and `--no-column`
92 + without options are equivalent to 'always' and 'never' respectively.
93 ++
94 +This option is only applicable when listing tags without annotation lines.
95 +
96 --contains <commit>::
97 Only list tags which contain the specified commit.
98
Makefile
+1 -1
@@ -2168,7 +2168,7 @@ builtin/prune.o builtin/reflog.o reachable.o: reachable.h
2168 builtin/commit.o builtin/revert.o wt-status.o: wt-status.h
2169 builtin/tar-tree.o archive-tar.o: tar.h
2170 connect.o transport.o url.o http-backend.o: url.h
2171 -builtin/branch.o builtin/commit.o column.o help.o pager.o: column.h
2171 +builtin/branch.o builtin/commit.o builtin/tag.o column.o help.o pager.o: column.h
2172 http-fetch.o http-walker.o remote-curl.o transport.o walker.o: walker.h
2173 http.o http-walker.o http-push.o http-fetch.o remote-curl.o: http.h url.h
2174
builtin/tag.c
+24 -3
@@ -16,6 +16,7 @@
16 #include "revision.h"
17 #include "gpg-interface.h"
18 #include "sha1-array.h"
19 +#include "column.h"
20
21 static const char * const git_tag_usage[] = {
22 "git tag [-a|-s|-u <key-id>] [-f] [-m <msg>|-F <file>] <tagname> [<head>]",
@@ -33,6 +34,7 @@ struct tag_filter {
34 };
35
36 static struct sha1_array points_at;
37 +static unsigned int colopts;
38
39 static int match_pattern(const char **patterns, const char *ref)
40 {
@@ -263,6 +265,8 @@ static int git_tag_config(const char *var, const char *value, void *cb)
265 int status = git_gpg_config(var, value, cb);
266 if (status)
267 return status;
268 + if (!prefixcmp(var, "column."))
269 + return git_column_config(var, value, "tag", &colopts);
270 return git_default_config(var, value, cb);
271 }
272
@@ -459,6 +463,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
463 OPT_STRING('u', "local-user", &keyid, "key-id",
464 "use another key to sign the tag"),
465 OPT__FORCE(&force, "replace the tag if exists"),
466 + OPT_COLUMN(0, "column", &colopts, "show tag list in columns"),
467
468 OPT_GROUP("Tag listing options"),
469 {
@@ -495,9 +500,25 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
500
501 if (list + delete + verify > 1)
502 usage_with_options(git_tag_usage, options);
498 - if (list)
499 - return list_tags(argv, lines == -1 ? 0 : lines,
500 - with_commit);
503 + finalize_colopts(&colopts, -1);
504 + if (list && lines != -1) {
505 + if (explicitly_enable_column(colopts))
506 + die(_("--column and -n are incompatible"));
507 + colopts = 0;
508 + }
509 + if (list) {
510 + int ret;
511 + if (column_active(colopts)) {
512 + struct column_options copts;
513 + memset(&copts, 0, sizeof(copts));
514 + copts.padding = 2;
515 + run_column_filter(colopts, &copts);
516 + }
517 + ret = list_tags(argv, lines == -1 ? 0 : lines, with_commit);
518 + if (column_active(colopts))
519 + stop_column_filter();
520 + return ret;
521 + }
522 if (lines != -1)
523 die(_("-n option is only allowed with -l."));
524 if (with_commit)
t/t7004-tag.sh
+44
@@ -263,6 +263,50 @@ test_expect_success 'tag -l can accept multiple patterns' '
263 test_cmp expect actual
264 '
265
266 +test_expect_success 'listing tags in column' '
267 + COLUMNS=40 git tag -l --column=row >actual &&
268 + cat >expected <<\EOF &&
269 +a1 aa1 cba t210 t211
270 +v0.2.1 v1.0 v1.0.1 v1.1.3
271 +EOF
272 + test_cmp expected actual
273 +'
274 +
275 +test_expect_success 'listing tags in column with column.*' '
276 + git config column.tag row &&
277 + git config column.ui dense &&
278 + COLUMNS=40 git tag -l >actual &&
279 + git config --unset column.ui &&
280 + git config --unset column.tag &&
281 + cat >expected <<\EOF &&
282 +a1 aa1 cba t210 t211
283 +v0.2.1 v1.0 v1.0.1 v1.1.3
284 +EOF
285 + test_cmp expected actual
286 +'
287 +
288 +test_expect_success 'listing tag with -n --column should fail' '
289 + test_must_fail git tag --column -n
290 +'
291 +
292 +test_expect_success 'listing tags -n in column with column.ui ignored' '
293 + git config column.ui "row dense" &&
294 + COLUMNS=40 git tag -l -n >actual &&
295 + git config --unset column.ui &&
296 + cat >expected <<\EOF &&
297 +a1 Foo
298 +aa1 Foo
299 +cba Foo
300 +t210 Foo
301 +t211 Foo
302 +v0.2.1 Foo
303 +v1.0 Foo
304 +v1.0.1 Foo
305 +v1.1.3 Foo
306 +EOF
307 + test_cmp expected actual
308 +'
309 +
310 # creating and verifying lightweight tags:
311
312 test_expect_success \