Thread (65 messages) flat view 65 messages, 4 authors, 2016-06-15

Re: [PATCH v2 07/17] ls-files: add --column

From: Eric Sunshine <hidden>
Date: 2016-06-15 23:00:33

On Wed, Mar 26, 2014 at 9:48 AM, Nguyễn Thái Ngọc Duy [off-list ref] wrote:
quoted hunk ↗ jump to hunk
Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
 Documentation/git-ls-files.txt |  6 ++++++
 builtin/ls-files.c             | 25 +++++++++++++++++++++++++
 2 files changed, 31 insertions(+)
diff --git a/Documentation/git-ls-files.txt b/Documentation/git-ls-files.txt
index 5c1b7f3..cd52461 100644
--- a/Documentation/git-ls-files.txt
+++ b/Documentation/git-ls-files.txt
@@ -156,6 +156,12 @@ a space) at the start of each line:
        default to color output, same as `--color=never`. This is the
        default.

+--column[=<options>]::
+--no-column::
+       Display files in columns. See configuration variable column.ui
+       for option syntax.`--column` and `--no-column` without options
Missing space after period.
quoted hunk ↗ jump to hunk
+       are equivalent to 'always' and 'never' respectively.
+
 \--::
        Do not interpret any more arguments as options.
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 2857b38..335d3b0 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -15,6 +15,7 @@
 #include "string-list.h"
 #include "pathspec.h"
 #include "color.h"
+#include "column.h"

 static int abbrev;
 static int show_deleted;
@@ -29,6 +30,7 @@ static int show_valid_bit;
 static int line_terminator = '\n';
 static int debug_mode;
 static int use_color;
+static unsigned int colopts;

 static const char *prefix;
 static int max_prefix_len;
@@ -39,6 +41,7 @@ static char *ps_matched;
 static const char *with_tree;
 static int exc_given;
 static int exclude_args;
+static struct string_list output = STRING_LIST_INIT_NODUP;

 static const char *tag_cached = "";
 static const char *tag_unmerged = "";
@@ -66,6 +69,10 @@ static void write_name(struct strbuf *sb, const char *name)

 static void strbuf_fputs(struct strbuf *sb, FILE *fp)
 {
+       if (column_active(colopts)) {
+               string_list_append(&output, strbuf_detach(sb, NULL));
+               return;
+       }
        fwrite(sb->buf, sb->len, 1, fp);
 }
@@ -552,6 +559,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()
@@ -596,6 +604,18 @@ 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 (explicitly_enable_column(colopts)) {
+               if (!line_terminator)
+                       die(_("--column and -z are incompatible"));
+               if (show_resolve_undo)
+                       die(_("--column and --resolve-undo are incompatible"));
+               if (debug_mode)
+                       die(_("--column and --debug are incompatible"));
+       }
+       if (column_active(colopts))
+               line_terminator = 0;
+
        if (require_work_tree && !is_inside_work_tree())
                setup_work_tree();
@@ -638,6 +658,11 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
        if (show_resolve_undo)
                show_ru_info();

+       if (column_active(colopts)) {
+               print_columns(&output, colopts, NULL);
+               string_list_clear(&output, 0);
+       }
+
        if (ps_matched) {
                int bad;
                bad = report_path_error(ps_matched, &pathspec, prefix);
--
1.9.1.345.ga1a145c

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help