From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 3/3] Add "ls", which is basically ls-files with user-friendly settings
Date: Fri, 8 Jan 2010 00:07:56 +0700 [thread overview]
Message-ID: <1262884076-12293-4-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1262884076-12293-1-git-send-email-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
builtin-ls-files.c | 31 +++++++++++++++++++++++++++++++
builtin.h | 1 +
git.c | 1 +
3 files changed, 33 insertions(+), 0 deletions(-)
diff --git a/builtin-ls-files.c b/builtin-ls-files.c
index e16638e..f63b039 100644
--- a/builtin-ls-files.c
+++ b/builtin-ls-files.c
@@ -11,6 +11,7 @@
#include "builtin.h"
#include "tree.h"
#include "parse-options.h"
+#include "run-command.h"
static int abbrev;
static int show_deleted;
@@ -31,6 +32,7 @@ static char *ps_matched;
static const char *with_tree;
static int exc_given;
static int max_depth = 0;
+static int show_colums = 0;
static const char *tag_cached = "";
static const char *tag_unmerged = "";
@@ -461,6 +463,7 @@ static int option_parse_exclude_standard(const struct option *opt,
int cmd_ls_files(int argc, const char **argv, const char *prefix)
{
+ struct child_process cp;
int require_work_tree = 0, show_tag = 0;
struct dir_struct dir;
struct option builtin_ls_files_options[] = {
@@ -513,6 +516,7 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
OPT_STRING(0, "with-tree", &with_tree, "tree-ish",
"pretend that paths removed since <tree-ish> are still present"),
OPT_INTEGER(0, "max-depth", &max_depth, "max recursive depth"),
+ OPT_BOOLEAN(0, "columns", &show_colums, "show in columns"),
OPT__ABBREV(&abbrev),
OPT_END()
};
@@ -591,6 +595,20 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
die("ls-files --with-tree is incompatible with -s or -u");
overlay_tree_on_cache(with_tree, prefix);
}
+
+ if (show_colums) {
+ const char *argv[] = { "column", NULL };
+
+ memset(&cp, 0, sizeof(cp));
+ cp.in = -1;
+ cp.out = dup(1);
+ cp.argv = argv;
+ start_command(&cp);
+ close(1);
+ dup2(cp.in, 1);
+ close(cp.in);
+ }
+
show_files(&dir, prefix);
if (ps_matched) {
@@ -602,5 +620,18 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
return bad ? 1 : 0;
}
+ if (show_colums) {
+ fflush(stdout);
+ close(1);
+ finish_command(&cp);
+ }
+
return 0;
}
+
+int cmd_ls(int argc, const char **argv, const char *prefix)
+{
+ max_depth = 1;
+ show_colums = 1;
+ return cmd_ls_files(argc, argv, prefix);
+}
diff --git a/builtin.h b/builtin.h
index c3f83c0..d8980e5 100644
--- a/builtin.h
+++ b/builtin.h
@@ -61,6 +61,7 @@ extern int cmd_init_db(int argc, const char **argv, const char *prefix);
extern int cmd_log(int argc, const char **argv, const char *prefix);
extern int cmd_log_reflog(int argc, const char **argv, const char *prefix);
extern int cmd_ls_files(int argc, const char **argv, const char *prefix);
+extern int cmd_ls(int argc, const char **argv, const char *prefix);
extern int cmd_ls_tree(int argc, const char **argv, const char *prefix);
extern int cmd_ls_remote(int argc, const char **argv, const char *prefix);
extern int cmd_mailinfo(int argc, const char **argv, const char *prefix);
diff --git a/git.c b/git.c
index 11544cd..4aff5ec 100644
--- a/git.c
+++ b/git.c
@@ -323,6 +323,7 @@ static void handle_internal_command(int argc, const char **argv)
{ "init-db", cmd_init_db },
{ "log", cmd_log, RUN_SETUP | USE_PAGER },
{ "ls-files", cmd_ls_files, RUN_SETUP },
+ { "ls", cmd_ls, RUN_SETUP },
{ "ls-tree", cmd_ls_tree, RUN_SETUP },
{ "ls-remote", cmd_ls_remote },
{ "mailinfo", cmd_mailinfo },
--
1.6.6.315.g1a406
next prev parent reply other threads:[~2010-01-07 17:09 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-07 17:07 [PATCH 0/3] Bringing git-ls-files to porcelain level Nguyễn Thái Ngọc Duy
2010-01-07 17:07 ` [PATCH 1/3] ls-files: support --max-depth Nguyễn Thái Ngọc Duy
2010-01-07 17:07 ` [PATCH 2/3] ls-files: support -o --max-depth (more of a hack as fill_directory should support this) Nguyễn Thái Ngọc Duy
2010-01-07 18:01 ` Junio C Hamano
2010-01-07 17:07 ` Nguyễn Thái Ngọc Duy [this message]
2010-01-07 18:01 ` [PATCH 3/3] Add "ls", which is basically ls-files with user-friendly settings Junio C Hamano
2010-01-07 18:09 ` Nguyen Thai Ngoc Duy
2010-01-08 14:16 ` Nguyen Thai Ngoc Duy
2010-01-07 18:12 ` Matthieu Moy
2010-01-07 17:40 ` [PATCH 0/3] Bringing git-ls-files to porcelain level Matthieu Moy
2010-01-07 17:47 ` Nguyen Thai Ngoc Duy
2010-11-01 10:30 ` Kan-Ru Chen
2010-11-01 11:20 ` Nguyen Thai Ngoc Duy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1262884076-12293-4-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).