[PATCH 6/8] ls-files: add --column

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Default pathspec behavior is recursive which includes too many files
for effective column output. But if you can do

git ls-files --column ':(glob)*'

to limit to one level only. It's not exactly the same as GNU ls
(e.g. directories are never shown) but much closer.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx>
---
 builtin/ls-files.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 463280e..a43abdb 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -16,6 +16,7 @@
 #include "pathspec.h"
 #include "color.h"
 #include "ls_colors.h"
+#include "column.h"
 
 static int abbrev;
 static int show_deleted;
@@ -476,6 +477,7 @@ static int option_parse_exclude_standard(const struct option *opt,
 int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
 {
 	int require_work_tree = 0, show_tag = 0, i;
+	unsigned int colopts = 0;
 	const char *max_prefix;
 	struct dir_struct dir;
 	struct exclude_list *el;
@@ -532,6 +534,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
 		OPT_STRING(0, "with-tree", &with_tree, N_("tree-ish"),
 			N_("pretend that paths removed since <tree-ish> are still present")),
 		OPT__COLOR(&use_color, N_("show color")),
+		OPT_COLUMN(0, "column", &colopts, N_("show files in columns")),
 		OPT__ABBREV(&abbrev),
 		OPT_BOOL(0, "debug", &debug_mode, N_("show debugging data")),
 		OPT_END()
@@ -576,6 +579,10 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
 	if (dir.exclude_per_dir)
 		exc_given = 1;
 
+	finalize_colopts(&colopts, -1);
+	if (!line_terminator && explicitly_enable_column(colopts))
+		die(_("--column and -z are incompatible"));
+
 	if (require_work_tree && !is_inside_work_tree())
 		setup_work_tree();
 
@@ -614,10 +621,19 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
 			die("ls-files --with-tree is incompatible with -s or -u");
 		overlay_tree_on_cache(with_tree, max_prefix);
 	}
+
+	if (column_active(colopts)) {
+		struct column_options copts;
+		memset(&copts, 0, sizeof(copts));
+		run_column_filter(colopts, &copts);
+	}
 	show_files(&dir);
 	if (show_resolve_undo)
 		show_ru_info();
 
+	if (column_active(colopts))
+		stop_column_filter();
+
 	if (ps_matched) {
 		int bad;
 		bad = report_path_error(ps_matched, &pathspec, prefix);
-- 
1.9.0.40.gaa8c3ea

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]