git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 09/12] branch: support column output with --columns

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Mar 7, 2010, 12:09 UTC
Message-ID
<1267963785-473-10-git-send-email-pclouds@gmail.com>
In-Reply-To
<1267963785-473-1-git-send-email-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 Documentation/git-branch.txt |    8 ++++++++
 builtin/branch.c             |   18 +++++++++++++++---
 2 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt
index 903a690..3d1d600 100644
--- a/Documentation/git-branch.txt
+++ b/Documentation/git-branch.txt
@@ -9,6 +9,7 @@ SYNOPSIS
 --------
 [verse]
 'git branch' [--color[=<when>] | --no-color] [-r | -a]
+	[--columns | --no-columns]
 	[-v [--abbrev=<length> | --no-abbrev]]
 	[(--merged | --no-merged | --contains) [<commit>]]
 'git branch' [--set-upstream | --track | --no-track] [-l] [-f] <branchname> [<start-point>]
@@ -93,6 +94,13 @@ OPTIONS
 	default to color output.
 	Same as `--color=never`.
 
+--columns::
+	Show branches in columns. This option is ignored in verbose mode.
+
+--no-columns::
+	Show branches in a single list. This option is used to override
+	core.columns if set.
+
 -r::
 	List or delete (if used with -d) the remote-tracking branches.
 
diff --git a/builtin/branch.c b/builtin/branch.c
index 6cf7e72..16273cb 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -15,6 +15,7 @@
 #include "branch.h"
 #include "diff.h"
 #include "revision.h"
+#include "column.h"
 
 static const char * const builtin_branch_usage[] = {
 	"git branch [options] [-r | -a] [--merged | --no-merged]",
@@ -598,7 +599,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 {
 	int delete = 0, rename = 0, force_create = 0;
 	int verbose = 0, abbrev = DEFAULT_ABBREV, detached = 0;
-	int reflog = 0;
+	int reflog = 0, column_output = 0;
 	enum branch_track track;
 	int kinds = REF_LOCAL_BRANCH;
 	struct commit_list *with_commit = NULL;
@@ -648,10 +649,12 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 			PARSE_OPT_LASTARG_DEFAULT | PARSE_OPT_NONEG,
 			opt_parse_merge_filter, (intptr_t) "HEAD",
 		},
+		OPT_BOOLEAN(0, "columns", &column_output, "list branches in columns"),
 		OPT_END(),
 	};
 
 	git_config(git_branch_config, NULL);
+	column_output = core_column_output;
 
 	if (branch_use_color == -1)
 		branch_use_color = git_use_color_default;
@@ -678,8 +681,17 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 
 	if (delete)
 		return delete_branches(argc, argv, delete > 1, kinds);
-	else if (argc == 0)
-		print_ref_list(kinds, detached, verbose, abbrev, with_commit);
+	else if (argc == 0) {
+		if (verbose)
+			print_ref_list(kinds, detached, verbose, abbrev, with_commit);
+		else {
+			if (column_output)
+				start_columnizer(NULL);
+			print_ref_list(kinds, detached, verbose, abbrev, with_commit);
+			if (column_output)
+				stop_columnizer();
+		}
+	}
 	else if (rename && (argc == 1))
 		rename_branch(head, argv[0], rename > 1);
 	else if (rename && (argc == 2))
-- 
1.7.0.1.370.gd3c5
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 10 of 24 in “Support columinized output in tag/branch/ls-files/grep”
  1. 00/12 Support columinized output in tag/branch/ls-files/grepNguyễn Thái Ngọc Duy, Mar 7, 2010
  2. 01/12 Move term_columns() to pager.cNguyễn Thái Ngọc Duy, Mar 7, 2010
  3. 02/12 setup_pager(): save terminal width before redirecting stdoutNguyễn Thái Ngọc Duy, Mar 7, 2010
  4. 03/12 Add columnizerNguyễn Thái Ngọc Duy, Mar 7, 2010
  5. 04/12 help: use columnizerNguyễn Thái Ngọc Duy, Mar 7, 2010
  6. 05/12 Add builtin command "column"Nguyễn Thái Ngọc Duy, Mar 7, 2010
  7. 06/12 Add helpers to redirect stdout to "git column"Nguyễn Thái Ngọc Duy, Mar 7, 2010
  8. 07/12 add core.columnsNguyễn Thái Ngọc Duy, Mar 7, 2010
  9. 08/12 tag: support column output with --columnsNguyễn Thái Ngọc Duy, Mar 7, 2010
  10. 09/12 branch: support column output with --columnsNguyễn Thái Ngọc Duy, Mar 7, 2010
  11. 10/12 ls-files: support column output with --columnsNguyễn Thái Ngọc Duy, Mar 7, 2010
  12. 11/12 grep: do not return early in cmd_grep() if there is no errorNguyễn Thái Ngọc Duy, Mar 7, 2010
  13. 12/12 grep: support column output with --columnsNguyễn Thái Ngọc Duy, Mar 7, 2010
  14. René ScharfeMar 8, 2010
  15. Nguyen Thai Ngoc DuyMar 8, 2010
  16. René ScharfeMar 9, 2010
  17. Nguyen Thai Ngoc DuyMar 10, 2010
  18. Johannes SixtMar 10, 2010
  19. Nguyen Thai Ngoc DuyMar 10, 2010
  20. René ScharfeMar 11, 2010
  21. Nguyen Thai Ngoc DuyMar 12, 2010
  22. Junio C HamanoMar 8, 2010
  23. Nguyen Thai Ngoc DuyMar 9, 2010
  24. Junio C HamanoMar 9, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.