{"thread":{"id":"22119","subject":"[PATCH 0/3] Bringing git-ls-files to porcelain level","startedAt":"2010-01-07T17:07:53Z","lastAt":"2010-11-01T11:20:59Z","messageCount":13,"participants":["Nguyễn Thái Ngọc Duy","Matthieu Moy","Nguyen Thai Ngoc Duy","Junio C Hamano","Kan-Ru Chen"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"131012","messageId":"1262884076-12293-1-git-send-email-pclouds@gmail.com","threadId":"22119","inReplyTo":null,"subject":"[PATCH 0/3] Bringing git-ls-files to porcelain level","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-01-07T17:07:53Z","receivedAt":"2010-01-07T17:07:53Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"This is a hack, to scratch my itch. These patches add \"git ls\",\nwhich is equivalent to \"git ls-files --max-depth 1|column\"\n\nAnyone up for coloring? ;)\n\nNguyễn Thái Ngọc Duy (3):\n  ls-files: support --max-depth\n  ls-files: support -o --max-depth (more of a hack as fill_directory\n    should support this)\n  Add \"ls\", which is basically ls-files with user-friendly settings\n\n builtin-ls-files.c |   72 ++++++++++++++++++++++++++++++++++++++++++++++++++++\n builtin.h          |    1 +\n git.c              |    1 +\n 3 files changed, 74 insertions(+), 0 deletions(-)\n"},{"id":"131013","messageId":"1262884076-12293-2-git-send-email-pclouds@gmail.com","threadId":"22119","inReplyTo":"1262884076-12293-1-git-send-email-pclouds@gmail.com","subject":"[PATCH 1/3] ls-files: support --max-depth","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-01-07T17:07:54Z","receivedAt":"2010-01-07T17:07:54Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin-ls-files.c |   30 ++++++++++++++++++++++++++++++\n 1 files changed, 30 insertions(+), 0 deletions(-)\n\ndiff --git a/builtin-ls-files.c b/builtin-ls-files.c\nindex 7382157..2bb851a 100644\n--- a/builtin-ls-files.c\n+++ b/builtin-ls-files.c\n@@ -30,6 +30,7 @@ static int error_unmatch;\n static char *ps_matched;\n static const char *with_tree;\n static int exc_given;\n+static int max_depth = 0;\n \n static const char *tag_cached = \"\";\n static const char *tag_unmerged = \"\";\n@@ -232,6 +233,30 @@ static void prune_cache(const char *prefix)\n \tactive_nr = last;\n }\n \n+/*\n+ * It is assumed that prune_cache() as been called before this\n+ */\n+static void prune_cache_by_depth(const char *prefix, int max_depth)\n+{\n+\tint i = active_nr-1;\n+\n+\twhile (i >= 0) {\n+\t\tint slashes = 0;\n+\t\tconst char *entry = active_cache[i]->name + prefix_len;\n+\t\twhile ((entry = strchr(entry, '/')) != NULL) {\n+\t\t\tslashes++;\n+\t\t\tif (slashes >= max_depth) {\n+\t\t\t\tmemmove(active_cache + i, active_cache + i + 1,\n+\t\t\t\t\t(active_nr - i - 1) * sizeof(struct cache_entry *));\n+\t\t\t\tactive_nr--;\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t\tentry++;\n+\t\t}\n+\t\ti--;\n+\t}\n+}\n+\n static const char *verify_pathspec(const char *prefix)\n {\n \tconst char **p, *n, *prev;\n@@ -476,6 +501,7 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)\n \t\t\t\"if any <file> is not in the index, treat this as an error\"),\n \t\tOPT_STRING(0, \"with-tree\", &with_tree, \"tree-ish\",\n \t\t\t\"pretend that paths removed since <tree-ish> are still present\"),\n+\t\tOPT_INTEGER(0, \"max-depth\", &max_depth, \"max recursive depth\"),\n \t\tOPT__ABBREV(&abbrev),\n \t\tOPT_END()\n \t};\n@@ -541,6 +567,10 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)\n \n \tif (prefix)\n \t\tprune_cache(prefix);\n+\n+\tif (max_depth)\n+\t\tprune_cache_by_depth(prefix, max_depth);\n+\n \tif (with_tree) {\n \t\t/*\n \t\t * Basic sanity check; show-stages and show-unmerged\n-- \n1.6.6.315.g1a406\n"},{"id":"131014","messageId":"1262884076-12293-3-git-send-email-pclouds@gmail.com","threadId":"22119","inReplyTo":"1262884076-12293-1-git-send-email-pclouds@gmail.com","subject":"[PATCH 2/3] ls-files: support -o --max-depth (more of a hack as fill_directory should support this)","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-01-07T17:07:55Z","receivedAt":"2010-01-07T17:07:55Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin-ls-files.c |   11 +++++++++++\n 1 files changed, 11 insertions(+), 0 deletions(-)\n\ndiff --git a/builtin-ls-files.c b/builtin-ls-files.c\nindex 2bb851a..e16638e 100644\n--- a/builtin-ls-files.c\n+++ b/builtin-ls-files.c\n@@ -51,6 +51,17 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent)\n \tif (!match_pathspec(pathspec, ent->name, ent->len, len, ps_matched))\n \t\treturn;\n \n+\tif (max_depth) {\n+\t\tint slashes = 0;\n+\t\tconst char *entry = ent->name + prefix_offset;\n+\t\twhile ((entry = strchr(entry, '/')) != NULL) {\n+\t\t\tslashes++;\n+\t\t\tif (slashes >= max_depth)\n+\t\t\t\treturn;\n+\t\t\tentry++;\n+\t\t}\n+\t}\n+\n \tfputs(tag, stdout);\n \twrite_name_quoted(ent->name + offset, stdout, line_terminator);\n }\n-- \n1.6.6.315.g1a406\n"},{"id":"131015","messageId":"1262884076-12293-4-git-send-email-pclouds@gmail.com","threadId":"22119","inReplyTo":"1262884076-12293-1-git-send-email-pclouds@gmail.com","subject":"[PATCH 3/3] Add \"ls\", which is basically ls-files with user-friendly settings","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-01-07T17:07:56Z","receivedAt":"2010-01-07T17:07:56Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin-ls-files.c |   31 +++++++++++++++++++++++++++++++\n builtin.h          |    1 +\n git.c              |    1 +\n 3 files changed, 33 insertions(+), 0 deletions(-)\n\ndiff --git a/builtin-ls-files.c b/builtin-ls-files.c\nindex e16638e..f63b039 100644\n--- a/builtin-ls-files.c\n+++ b/builtin-ls-files.c\n@@ -11,6 +11,7 @@\n #include \"builtin.h\"\n #include \"tree.h\"\n #include \"parse-options.h\"\n+#include \"run-command.h\"\n \n static int abbrev;\n static int show_deleted;\n@@ -31,6 +32,7 @@ static char *ps_matched;\n static const char *with_tree;\n static int exc_given;\n static int max_depth = 0;\n+static int show_colums = 0;\n \n static const char *tag_cached = \"\";\n static const char *tag_unmerged = \"\";\n@@ -461,6 +463,7 @@ static int option_parse_exclude_standard(const struct option *opt,\n \n int cmd_ls_files(int argc, const char **argv, const char *prefix)\n {\n+\tstruct child_process cp;\n \tint require_work_tree = 0, show_tag = 0;\n \tstruct dir_struct dir;\n \tstruct option builtin_ls_files_options[] = {\n@@ -513,6 +516,7 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)\n \t\tOPT_STRING(0, \"with-tree\", &with_tree, \"tree-ish\",\n \t\t\t\"pretend that paths removed since <tree-ish> are still present\"),\n \t\tOPT_INTEGER(0, \"max-depth\", &max_depth, \"max recursive depth\"),\n+\t\tOPT_BOOLEAN(0, \"columns\", &show_colums, \"show in columns\"),\n \t\tOPT__ABBREV(&abbrev),\n \t\tOPT_END()\n \t};\n@@ -591,6 +595,20 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)\n \t\t\tdie(\"ls-files --with-tree is incompatible with -s or -u\");\n \t\toverlay_tree_on_cache(with_tree, prefix);\n \t}\n+\n+\tif (show_colums) {\n+\t\tconst char *argv[] = { \"column\", NULL };\n+\n+\t\tmemset(&cp, 0, sizeof(cp));\n+\t\tcp.in = -1;\n+\t\tcp.out = dup(1);\n+\t\tcp.argv = argv;\n+\t\tstart_command(&cp);\n+\t\tclose(1);\n+\t\tdup2(cp.in, 1);\n+\t\tclose(cp.in);\n+\t}\n+\n \tshow_files(&dir, prefix);\n \n \tif (ps_matched) {\n@@ -602,5 +620,18 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)\n \t\treturn bad ? 1 : 0;\n \t}\n \n+\tif (show_colums) {\n+\t\tfflush(stdout);\n+\t\tclose(1);\n+\t\tfinish_command(&cp);\n+\t}\n+\n \treturn 0;\n }\n+\n+int cmd_ls(int argc, const char **argv, const char *prefix)\n+{\n+\tmax_depth = 1;\n+\tshow_colums = 1;\n+\treturn cmd_ls_files(argc, argv, prefix);\n+}\ndiff --git a/builtin.h b/builtin.h\nindex c3f83c0..d8980e5 100644\n--- a/builtin.h\n+++ b/builtin.h\n@@ -61,6 +61,7 @@ extern int cmd_init_db(int argc, const char **argv, const char *prefix);\n extern int cmd_log(int argc, const char **argv, const char *prefix);\n extern int cmd_log_reflog(int argc, const char **argv, const char *prefix);\n extern int cmd_ls_files(int argc, const char **argv, const char *prefix);\n+extern int cmd_ls(int argc, const char **argv, const char *prefix);\n extern int cmd_ls_tree(int argc, const char **argv, const char *prefix);\n extern int cmd_ls_remote(int argc, const char **argv, const char *prefix);\n extern int cmd_mailinfo(int argc, const char **argv, const char *prefix);\ndiff --git a/git.c b/git.c\nindex 11544cd..4aff5ec 100644\n--- a/git.c\n+++ b/git.c\n@@ -323,6 +323,7 @@ static void handle_internal_command(int argc, const char **argv)\n \t\t{ \"init-db\", cmd_init_db },\n \t\t{ \"log\", cmd_log, RUN_SETUP | USE_PAGER },\n \t\t{ \"ls-files\", cmd_ls_files, RUN_SETUP },\n+\t\t{ \"ls\", cmd_ls, RUN_SETUP },\n \t\t{ \"ls-tree\", cmd_ls_tree, RUN_SETUP },\n \t\t{ \"ls-remote\", cmd_ls_remote },\n \t\t{ \"mailinfo\", cmd_mailinfo },\n-- \n1.6.6.315.g1a406\n"},{"id":"131018","messageId":"vpq3a2hlsnx.fsf@bauges.imag.fr","threadId":"22119","inReplyTo":"1262884076-12293-1-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH 0/3] Bringing git-ls-files to porcelain level","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2010-01-07T17:40:50Z","receivedAt":"2010-01-07T17:40:50Z","isPatch":true,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:\n\n> This is a hack, to scratch my itch. These patches add \"git ls\",\n> which is equivalent to \"git ls-files --max-depth 1|column\"\n\nYou also want --exclude-standard to be the default in porcelain.\n\nI've had \"alias.ls = ls-files --exclude-standard\" for a while in my\n~/.gitconfig ;-).\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"131019","messageId":"fcaeb9bf1001070947u5859dda0vacbcc27298d664a4@mail.gmail.com","threadId":"22119","inReplyTo":"vpq3a2hlsnx.fsf@bauges.imag.fr","subject":"Re: [PATCH 0/3] Bringing git-ls-files to porcelain level","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-01-07T17:47:30Z","receivedAt":"2010-01-07T17:47:30Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On 1/8/10, Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> wrote:\n> Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:\n>\n>  > This is a hack, to scratch my itch. These patches add \"git ls\",\n>  > which is equivalent to \"git ls-files --max-depth 1|column\"\n>\n>\n> You also want --exclude-standard to be the default in porcelain.\n>\n>  I've had \"alias.ls = ls-files --exclude-standard\" for a while in my\n>  ~/.gitconfig ;-).\n\nYeah, just added that after realizing \"git ls -o\" is too annoying.\n-- \nDuy\n"},{"id":"131022","messageId":"7vljg94ww7.fsf@alter.siamese.dyndns.org","threadId":"22119","inReplyTo":"1262884076-12293-3-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH 2/3] ls-files: support -o --max-depth (more of a hack as fill_directory should support this)","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-01-07T18:01:28Z","receivedAt":"2010-01-07T18:01:28Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:\n\n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> ---\n\nSubject: Re: [PATCH 2/3] ls-files: support -o --max-depth (more of a hack\nas fill_directory should support this)\n\nPerhaps you would want to look at how builtin_grep()'s walker and the\nwalker in dir.c can be consolidated?  The former has support for\nmax_depth.\n"},{"id":"131023","messageId":"7vfx6h4ww3.fsf@alter.siamese.dyndns.org","threadId":"22119","inReplyTo":"1262884076-12293-4-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH 3/3] Add \"ls\", which is basically ls-files with user-friendly settings","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-01-07T18:01:32Z","receivedAt":"2010-01-07T18:01:32Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:\n\n> +\n> +\tif (show_colums) {\n> +\t\tconst char *argv[] = { \"column\", NULL };\n> +\n> +\t\tmemset(&cp, 0, sizeof(cp));\n> +\t\tcp.in = -1;\n> +\t\tcp.out = dup(1);\n> +\t\tcp.argv = argv;\n> +\t\tstart_command(&cp);\n> +\t\tclose(1);\n> +\t\tdup2(cp.in, 1);\n> +\t\tclose(cp.in);\n> +\t}\n\nI think the code for columnar output used in producing \"git help -a\"\noutput should be reusable (if not, should be made reusable and reused\nhere).\n"},{"id":"131026","messageId":"fcaeb9bf1001071009m11a7adfehdad485a4baeeb958@mail.gmail.com","threadId":"22119","inReplyTo":"7vfx6h4ww3.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH 3/3] Add \"ls\", which is basically ls-files with user-friendly settings","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-01-07T18:09:32Z","receivedAt":"2010-01-07T18:09:32Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On 1/8/10, Junio C Hamano <gitster@pobox.com> wrote:\n> Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:\n>\n>  > +\n>  > +     if (show_colums) {\n>  > +             const char *argv[] = { \"column\", NULL };\n>  > +\n>  > +             memset(&cp, 0, sizeof(cp));\n>  > +             cp.in = -1;\n>  > +             cp.out = dup(1);\n>  > +             cp.argv = argv;\n>  > +             start_command(&cp);\n>  > +             close(1);\n>  > +             dup2(cp.in, 1);\n>  > +             close(cp.in);\n>  > +     }\n>\n>\n> I think the code for columnar output used in producing \"git help -a\"\n>  output should be reusable (if not, should be made reusable and reused\n>  here).\n\nI saw that and even exported term_columns() but was too lazy to make\npretty_print_string_list() something reusable. Will think of it again\nwhen I see this command is worth pushing forward.\n-- \nDuy\n"},{"id":"131028","messageId":"vpq1vi1kcna.fsf@bauges.imag.fr","threadId":"22119","inReplyTo":"1262884076-12293-4-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH 3/3] Add \"ls\", which is basically ls-files with user-friendly settings","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2010-01-07T18:12:09Z","receivedAt":"2010-01-07T18:12:09Z","isPatch":true,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:\n\n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n\nYou should put the \"which is equivalent to \"git ls-files --max-depth\n1|column\"\" part of your cover letter here I think to make the patch\nself-contained.\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"131092","messageId":"fcaeb9bf1001080616r5835f504t14e51231afb03709@mail.gmail.com","threadId":"22119","inReplyTo":"fcaeb9bf1001071009m11a7adfehdad485a4baeeb958@mail.gmail.com","subject":"Re: [PATCH 3/3] Add \"ls\", which is basically ls-files with user-friendly settings","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-01-08T14:16:15Z","receivedAt":"2010-01-08T14:16:15Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On 1/8/10, Nguyen Thai Ngoc Duy <pclouds@gmail.com> wrote:\n> On 1/8/10, Junio C Hamano <gitster@pobox.com> wrote:\n>  > I think the code for columnar output used in producing \"git help -a\"\n>  >  output should be reusable (if not, should be made reusable and reused\n>  >  here).\n>\n>\n> I saw that and even exported term_columns() but was too lazy to make\n>  pretty_print_string_list() something reusable. Will think of it again\n>  when I see this command is worth pushing forward.\n\nI think again. There are a few places that may benefit from column\ndisplay: git tag -l, git grep -l, git branch (if you have lots of\nbranches) and probably untracked part of \"git status\". Moreover, I\nhave to implement it anyway because Solaris does not have command\n\"column\". How about an external \"git-column\"? This way we don't have\nto modify lots of code for columnized output. We may want to name it\n\"git-pager\" if we want an internal pager someday ;)\n-- \nDuy\n"},{"id":"154927","messageId":"87zkttqqse.fsf@anar.kanru.info","threadId":"22119","inReplyTo":"1262884076-12293-1-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH 0/3] Bringing git-ls-files to porcelain level","fromName":"Kan-Ru Chen","fromEmail":"kanru@kanru.info","sentAt":"2010-11-01T10:30:57Z","receivedAt":"2010-11-01T10:30:57Z","isPatch":true,"sender":{"key":"kanru@kanru.info","avatar":null},"body":"Hi,\n\nNguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:\n\n> This is a hack, to scratch my itch. These patches add \"git ls\",\n> which is equivalent to \"git ls-files --max-depth 1|column\"\n\nWhat is the status of this patch?\n\nI found it might be useful for zsh completion codes. Currently zsh _git\ncompletion relies heavily on ls-files and can be very slow on large\nrepository like linux kernel.\n\nIf ls-files supports --max-depth then zsh can do incremental\ncompletion. (hopefully)\n\n  kanru\n\n-- \n“A badly written book is only a blunder. A bad\n translation of a good book is a crime.” -- Gilbert Highet\n"},{"id":"154926","messageId":"AANLkTin5uw-O=7gOO+uPP1zKy0RghiZLmroZyEWO_EKg@mail.gmail.com","threadId":"22119","inReplyTo":"87zkttqqse.fsf@anar.kanru.info","subject":"Re: [PATCH 0/3] Bringing git-ls-files to porcelain level","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-11-01T11:20:59Z","receivedAt":"2010-11-01T11:20:59Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"2010/11/1 Kan-Ru Chen <kanru@kanru.info>:\n> Hi,\n>\n> Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:\n>\n>> This is a hack, to scratch my itch. These patches add \"git ls\",\n>> which is equivalent to \"git ls-files --max-depth 1|column\"\n>\n> What is the status of this patch?\n\nStalled. I found that there's some more to do. \"ls\" shows directories.\n\"git ls\" may not.\n\nThere were suggestions on improving the columnization part. I should\nhave resubmitted the column patches because it's really useful. Will\ntry to make it before the original series celebrates one year old.\n-- \nDuy\n"}]}