git-ls
Subsystems (2)
cover git-ls
Last time I tried this was more than two years ago [1]. It's time for another try and see if the community has any interest in it.
The command is straight forward, it's a ls-like version for listing things in git. It respects $LS_COLORS and does column output like GNU ls. "ls" shows cached entries (but no recursion), "ls -o" show untracked files. I want ls-tree, "diff --name-only" and "diff --name-only --cached" too, but they are not implemented yet.
WIP quality, this is to gather comments on the idea.
[1] http://thread.gmane.org/gmane.comp.version-control.git/166405
Nguyễn Thái Ngọc Duy (8):
Import $LS_COLORS parsing code from coreutils ls_colors.c: a bit of document on print_color_indicator input ls_colors.c: enable coloring on u+x files ls_colors.c: new color descriptors
ls-files: add --color to highlight based on $LS_COLORS
ls-files: add --column
ls-files: support --max-depth
Add git-ls, a user friendly version of ls-files and more
Makefile | 1 + builtin.h | 1 + builtin/ls-files.c | 80 ++++++++- git.c | 1 + ls_colors.c (new) | 487 +++++++++++++++++++++++++++++++++++++++++++++++++++++ ls_colors.h (new) | 20 +++ 6 files changed, 588 insertions(+), 2 deletions(-) create mode 100644 ls_colors.c create mode 100644 ls_colors.h
Signature · 1 line
1.9.0.40.gaa8c3ea
PATCH 1/8 Import $LS_COLORS parsing code from coreutils
This could could help highlight files in ls-files or status output, or even diff --name-only (but that's questionable).
This code is from coreutils.git commit 7326d1f1a67edf21947ae98194f98c38b6e9e527 file src/ls.c. This is the last GPL-2 commit before coreutils turns to GPL-3.
The code is reformatted to fit Git coding style, which is more than just adding and removing spaces. For example, "bool" is replaced with "int", or true/false replaced with 1/0, or the use of git's error() instead of error(3). There are also two "#if 0" to make it build with git-compat-util.h.
--- Makefile | 1 + ls_colors.c (new) | 477 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ ls_colors.h (new) | 20 +++ 3 files changed, 498 insertions(+) create mode 100644 ls_colors.c create mode 100644 ls_colors.h
Makefile +1 -0
@@ -819,6 +819,7 @@ LIB_OBJS += list-objects.o LIB_OBJS += ll-merge.o LIB_OBJS += lockfile.o LIB_OBJS += log-tree.o +LIB_OBJS += ls_colors.o LIB_OBJS += mailmap.o LIB_OBJS += match-trees.o LIB_OBJS += merge.o
ls_colors.c new file +477 -0
477 lines not on this page · raw message
ls_colors.h new file +20 -0
@@ -0,0 +1,20 @@ +#ifndef LS_COLORS_H +#define LS_COLORS_H + +enum filetype { + unknown, + fifo, + chardev, + directory, + blockdev, + normal, + symbolic_link, + sock, + whiteout, + arg_directory +}; + +void parse_ls_color (void ); +void print_color_indicator (const char *name,mode_t mode,int linkok, +int stat_ok,enum filetype filetype); +#endif
Signature · 1 line
1.9.0.40.gaa8c3ea
Re: [PATCH 1/8] Import $LS_COLORS parsing code from coreutils
Quoted 7 lines · Nguyễn Thái Ngọc Duy <pclouds <at> gmail.com> writes:
This could could help highlight files in ls-files or status output, or even diff --name-only (but that's questionable).
This code is from coreutils.git commit
7326d1f1a67edf21947ae98194f98c38b6e9e527filesrc/ls.c. This is the last GPL-2 commit before coreutils turns to GPL-3.
I don't know if this is something to consider but for my mac, I have another variable CLICOLOR which shows the colors if it is set. This is also true with FreeBSD[1] as well. I don't know if that should be checked if you're on those systems.
I think it would be nice to have --color flag as well if you want to enable color output for just that one output.
[1]: https://unix.stackexchange.com/questions/2897/clicolor-and-ls-colors-in-
bash
Re: [PATCH 1/8] Import $LS_COLORS parsing code from coreutils
Quoted 10 lines · David Tran
Quoted 7 lines · Nguyễn Thái Ngọc Duy <pclouds <at> gmail.com> writes:
This could could help highlight files in ls-files or status output, or even diff --name-only (but that's questionable).
This code is from coreutils.git commit
7326d1f1a67edf21947ae98194f98c38b6e9e527filesrc/ls.c. This is the last GPL-2 commit before coreutils turns to GPL-3.
Quoted 7 lines
I don't know if this is something to consider but for my mac, I have another variable CLICOLOR which shows the colors if it is set. This is also true with FreeBSD[1] as well. I don't know if that should be checked if you're on those systems.
I think it would be nice to have --color flag as well if you want to enable color output for just that one output.
My plan is stick to how git handles colors (e.g. --color and color.* config variables). Is that enough or do you think git CLICOLOR should override --color and color.*?
Quoted 8 lines
[1]: https://unix.stackexchange.com/questions/2897/clicolor-and-ls-colors-in-
bash--
To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 1 line
Duy
Re: [PATCH 1/8] Import $LS_COLORS parsing code from coreutils
Quoted 1 line · Duy Nguyen <pclouds <at> gmail.com> writes:
On Fri, Mar 21, 2014 at 2:09 AM, David Tran <unsignedzero <at> gmail.com>
Quoted 5 lines · wrote:
Quoted 5 lines
Quoted 3 lines · Nguyễn Thái Ngọc Duy <pclouds <at> gmail.com> writes:
This could could help highlight files in ls-files or status output, or even diff --name-only (but that's questionable).
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
This code is from coreutils.git commit
7326d1f1a67edf21947ae98194f98c38b6e9e527filesrc/ls.c. This is the last GPL-2 commit before coreutils turns to GPL-3.I don't know if this is something to consider but for my mac, I have another variable CLICOLOR which shows the colors if it is set. This is also true
with
Quoted 1 line
Quoted 1 line
FreeBSD[1] as well. I don't know if that should be checked if you're on
those
Quoted 9 lines
Quoted 4 lines
systems.
I think it would be nice to have --color flag as well if you want to enable color output for just that one output.
My plan is stick to how git handles colors (e.g. --color and color.* config variables). Is that enough or do you think git CLICOLOR should override --color and color.*?
I would say it is not an essential feature to have but something that might be looked into once the color is implemented. If its not set, ignore it. If it is set, check if it is truthy, is what I would do.
PATCH 2/8 ls_colors.c: a bit of document on print_color_indicator input
In reply to Nguyễn Thái Ngọc Duy--- ls_colors.c | 5 +++++ 1 file changed, 5 insertions(+)
ls_colors.c +5 -0
@@ -401,6 +401,11 @@ static void put_indicator(const struct bin_str *ind)putchar (*(p++)); } +/* +* mode is only used if stat_ok is true, else filetype is used. if +* linkok is -1, shows broken link. If linkok is zero and mode says +* it's a link, then show orphan link. +*/ void print_color_indicator (const char *name,mode_t mode,int linkok,int stat_ok,enum filetype filetype) {
Signature · 1 line
1.9.0.40.gaa8c3ea
PATCH 3/8 ls_colors.c: enable coloring on u+x files
In reply to Nguyễn Thái Ngọc Duygit-compat-util.h does not seem to carry S_IXUGO. Anyway as far as Git is concerned, we only care one executable bit. Hard code it.
--- ls_colors.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
ls_colors.c +1 -3
@@ -427,10 +427,8 @@ void print_color_indicator(const char *name, mode_t mode, int linkok, type =C_SETUID ; else if ((mode & S_ISGID) != 0) type =C_SETGID ; -#if 0 - else if ((mode & S_IXUGO) != 0) + else if ((mode & 0100) != 0) type = C_EXEC; -#endif }else if (S_ISDIR (mode)) {if ((mode &S_ISVTX ) && (mode &S_IWOTH )) type =C_STICKY_OTHER_WRITABLE ;
Signature · 1 line
1.9.0.40.gaa8c3ea
Re: [PATCH 3/8] ls_colors.c: enable coloring on u+x files
Quoted 2 lines · Nguyễn Thái Ngọc Duy
git-compat-util.hdoes not seem to carryS_IXUGO. Anyway as far as Git is concerned, we only care one executable bit. Hard code it.
Why not use S_IXUSR instead of a hardcoded value? (already used in path.c, so shouldn't be a problem wrt portability)
Signature · 2 lines
Matthieu Moy http://www-verimag.imag.fr/~moy/
Re: [PATCH 3/8] ls_colors.c: enable coloring on u+x files
Quoted 7 lines · Matthieu Moy
Quoted 2 lines · Nguyễn Thái Ngọc Duy
git-compat-util.hdoes not seem to carryS_IXUGO. Anyway as far as Git is concerned, we only care one executable bit. Hard code it.Why not use
S_IXUSRinstead of a hardcoded value? (already used inpath.c, so shouldn't be a problem wrt portability)
Hmm..maybe cache.h does something to that macro. Will drop this patch and include cache.h.
Signature · 1 line
Duy
Re: [PATCH 3/8] ls_colors.c: enable coloring on u+x files
Quoted 4 lines · Duy Nguyen
Quoted 2 lines · Matthieu Moy
Nguyễn Thái Ngọc Duy <[email protected]> writes:
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
git-compat-util.hdoes not seem to carryS_IXUGO. Anyway as far as Git is concerned, we only care one executable bit. Hard code it.Why not use
S_IXUSRinstead of a hardcoded value? (already used inpath.c, so shouldn't be a problem wrt portability)Hmm..maybe
cache.hdoes something to that macro. Will drop this patch and includecache.h.
Why even include cache.h for S_IXUSR?
In the context of the patch I see S_ISGID mentioned and other S_* st_mode things are already in use in this function before this step, and presumably you are using them without problems, no?
Re: [PATCH 3/8] ls_colors.c: enable coloring on u+x files
Quoted 5 lines · Junio C Hamano
Why even include
cache.hforS_IXUSR?In the context of the patch I see
S_ISGIDmentioned and other S_*st_modethings are already in use in this function before this step, and presumably you are using them without problems, no?
My mistake. git-compat-util.h does include S_IXUSR. The original code was S_IXUGO that's in neither files.
Signature · 1 line
Duy
PATCH 4/8 ls_colors.c: new color descriptors
In reply to Nguyễn Thái Ngọc DuyAfter coreutils moved to GPL-3 a couple more color descriptors were added. parse_ls_color() will abort if it finds any of these so just add them recognized (but never actually use them).
Reference commits (in coreutils.git)
0df338f (ls --color: do not colorize files with multiple hard links by default - 2009-06-10) adc62b5 (ls: clean up after wrapped+colored file names with clear-to-EOL - 2008-12-31) 1e48b1f (ls: --color now highlights hard linked files, too - 2008-10-27) 84f6abf (ls: --color now highlights files with capabilities, too - 2008-08-01) 483297d (ls --color no longer outputs unnecessary escape sequences - 2008-02-12)
--- ls_colors.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
ls_colors.c +11 -4
@@ -5,9 +5,12 @@#define STREQ (a, b) (strcmp(a, b) == 0)enum indicator_no { -C_LEFT ,C_RIGHT ,C_END ,C_NORM ,C_FILE ,C_DIR ,C_LINK ,C_FIFO ,C_SOCK , +C_LEFT ,C_RIGHT ,C_END ,C_RESET ,C_NORM , +C_FILE ,C_DIR ,C_LINK ,C_FIFO ,C_SOCK ,C_BLK ,C_CHR ,C_MISSING ,C_ORPHAN ,C_EXEC ,C_DOOR ,C_SETUID ,C_SETGID , -C_STICKY ,C_OTHER_WRITABLE ,C_STICKY_OTHER_WRITABLE +C_STICKY ,C_OTHER_WRITABLE ,C_STICKY_OTHER_WRITABLE , +C_CAP ,C_MULTIHARDLINK ,C_CLR_TO_EOL + };#define FILETYPE_INDICATORS \
@@ -28,9 +31,9 @@ struct color_ext_type { };static const char *const indicator_name[]= { -"lc" ,"rc" ,"ec" ,"no" ,"fi" ,"di" ,"ln" ,"pi" ,"so" , +"lc" ,"rc" ,"ec" ,"rs" ,"no" ,"fi" ,"di" ,"ln" ,"pi" ,"so" ,"bd" ,"cd" ,"mi" ,"or" ,"ex" ,"do" ,"su" ,"sg" ,"st" , -"ow" ,"tw" ,NULL +"ow" ,"tw" ,"ca" ,"mh" ,"cl" ,NULL };#define LEN_STR_PAIR (s) sizeof(s) - 1, s
@@ -38,6 +41,7 @@ static struct bin_str color_indicator[] = { { LEN_STR_PAIR("\033[") }, /* lc: Left of color sequence */ { LEN_STR_PAIR("m") }, /* rc: Right of color sequence */ { 0, NULL }, /* ec: End color (replaces lc+no+rc) */ + { 0, NULL }, /* rs: Reset to ordinary colors */ { LEN_STR_PAIR("0") }, /* no: Normal */ { LEN_STR_PAIR("0") }, /* fi: File: default */ { LEN_STR_PAIR("01;34") }, /* di: Directory: bright blue */
@@ -55,6 +59,9 @@ static struct bin_str color_indicator[] = { { LEN_STR_PAIR("37;44") }, /* st: sticky: black on blue */ { LEN_STR_PAIR("34;42") }, /* ow: other-writable: blue on green */ { LEN_STR_PAIR("30;42") }, /* tw: ow w/ sticky: black on green */ + { 0, NULL }, /* ca: black on red */ + { 0, NULL }, /* mh: disabled by default */ + { 0, NULL }, /* cl: clear to end of line */ };static struct color_ext_type *color_ext_list =NULL ;
Signature · 1 line
1.9.0.40.gaa8c3ea
PATCH 5/8 ls-files: add --color to highlight based on $LS_COLORS
In reply to Nguyễn Thái Ngọc Duy--- builtin/ls-files.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-)
builtin/ls-files.c +36 -2
@@ -14,6 +14,8 @@#include "resolve-undo.h" #include "string-list.h" #include "pathspec.h" +#include "color.h" +#include "ls_colors.h" static int abbrev;static int show_deleted;
@@ -27,6 +29,7 @@ static int show_killed;static int show_valid_bit;static int line_terminator ='\n' ;static int debug_mode; +static int use_color;static const char *prefix;static int max_prefix_len;
@@ -57,6 +60,33 @@ static void write_name(const char *name) stdout, line_terminator); } +static void write_dir_entry (const struct dir_entry *ent) +{ +if (want_color (use_color)) { +static struct strbuf sb =STRBUF_INIT ; +struct stat st; +int statok; +quote_path_relative (ent->name, prefix_len ? prefix :NULL , &sb); + statok =stat (ent->name, &st) ==0 ; +print_color_indicator (sb.buf, st.st_mode,0 , statok,0 ); +fputs (sb.buf, stdout); +printf ("%s%c" ,GIT_COLOR_RESET , line_terminator); + }else +write_name (ent->name); +} + +static void write_ce_name (const struct cache_entry *ce) +{ +if (want_color (use_color)) { +static struct strbuf sb =STRBUF_INIT ; +quote_path_relative (ce->name, prefix_len ? prefix :NULL , &sb); +print_color_indicator (sb.buf, ce->ce_mode,1 ,1 ,0 ); +fputs (sb.buf, stdout); +printf ("%s%c" ,GIT_COLOR_RESET , line_terminator); + }else +write_name (ce->name); +} +static void show_dir_entry (const char *tag,struct dir_entry *ent) {int len = max_prefix_len;
@@ -68,7 +98,7 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent)return ;fputs (tag, stdout); -write_name (ent->name); +write_dir_entry (ent); }static void show_other_files (struct dir_struct *dir)
@@ -170,7 +200,7 @@ static void show_ce_entry(const char *tag, const struct cache_entry *ce)find_unique_abbrev (ce->sha1,abbrev), ce_stage(ce)); } -write_name (ce->name); +write_ce_name (ce);if (debug_mode) {const struct stat_data *sd = &ce->ce_stat_data;
@@ -501,6 +531,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) N_("if any <file> is not in the index, treat this as an error")),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__ABBREV (&abbrev),OPT_BOOL (0 ,"debug" , &debug_mode,N_ ("show debugging data" )),OPT_END ()
@@ -548,6 +579,9 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)if (require_work_tree && !is_inside_work_tree ())setup_work_tree (); +if (want_color (use_color)) +parse_ls_color (); + parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD | PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP,
Signature · 1 line
1.9.0.40.gaa8c3ea
PATCH 6/8 ls-files: add --column
In reply to Nguyễn Thái Ngọc DuyDefault 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.
--- builtin/ls-files.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
builtin/ls-files.c +16 -0
@@ -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);
Signature · 1 line
1.9.0.40.gaa8c3ea
Re: [PATCH 6/8] ls-files: add --column
builtin/ls-files.c int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) · line 537
Quoted 1 line · Nguyễn Thái Ngọc Duy
builtin/ls-files.c +1
-0+ OPT_COLUMN(0, "column", &colopts, N_("show files in columns")),
To look a bit more like "ls", you could add a -1 option as an alias for --no-column.
That would be a good idea only if there is no plan to ever add a -N option (like "git log -42"). I don't know if any -N option could make sense.
Signature · 2 lines
Matthieu Moy http://www-verimag.imag.fr/~moy/
PATCH 7/8 ls-files: support --max-depth
In reply to Nguyễn Thái Ngọc DuyThe use case in mind is --max-depth=0 to stop recursion. With this we can do
git config --global alias.ls 'ls-files --column --color --max-depth=0'
and have "git ls" with an output very similar to GNU ls. Another interesting one is
git config --global alias.lso 'ls-files --column --color --max-depth=0 -o --exclude-standard'
--- builtin/ls-files.c | 7 +++++++ 1 file changed, 7 insertions(+)
builtin/ls-files.c +7 -0
@@ -478,6 +478,7 @@ 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 ; +int max_depth =-1 ;const char *max_prefix;struct dir_struct dir;struct exclude_list *el;
@@ -535,6 +536,9 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) 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" )), + { OPTION_INTEGER, 0, "max-depth", &max_depth, N_("depth"), +N_ ("descend at most <depth> levels" ),PARSE_OPT_NONEG , + NULL, 1 },OPT__ABBREV (&abbrev),OPT_BOOL (0 ,"debug" , &debug_mode,N_ ("show debugging data" )),OPT_END ()
@@ -591,8 +595,11 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)parse_pathspec (&pathspec,0 ,PATHSPEC_PREFER_CWD | + (max_depth !=-1 ?PATHSPEC_MAXDEPTH_VALID :0 ) |PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP , prefix, argv); + pathspec.max_depth = max_depth; + pathspec.recursive =1 ;/* Find common prefix for all pathspec's */ max_prefix =common_prefix (&pathspec);
Signature · 1 line
1.9.0.40.gaa8c3ea
Re: [PATCH 7/8] ls-files: support --max-depth
----- Original Message -----
Quoted 5 lines
The use case in mind is --max-depth=0 to stop recursion. With this we can do
git config --global alias.ls 'ls-files --column --color --max-depth=0'
and have "git ls" with an output very similar to GNU ls.
One big difference though: your "git ls" does not show directories. I understand that this is easier to implement, but from the user point of view it resulted in a "wtf" from me running "git ls" in a repository containing essentially directories, and seeing just a README file in the output.
Ideally (for me), directories should be shown with a trailing / like "ls -F" does.
Signature · 2 lines
Matthieu Moy http://www-verimag.imag.fr/~moy/
Re: [PATCH 7/8] ls-files: support --max-depth
Quoted 8 lines · Matthieu Moy
----- Original Message -----
Quoted 5 lines
The use case in mind is --max-depth=0 to stop recursion. With this we can do
git config --global alias.ls 'ls-files --column --color --max-depth=0'
and have "git ls" with an output very similar to GNU ls.
One big difference though: your "git ls" does not show directories. I understand that this is easier to implement, but from the user point of view it resulted in a "wtf" from me running "git ls" in a repository containing essentially directories, and seeing just a README file in the output.
I was hoping you didn't notice :) It'll be more difficult but not impossible.
Quoted 1 line
Ideally (for me), directories should be shown with a trailing / like "ls -F" does.
I'd rather go with no trailing slash by default and add -F (which seems to be more than just '/')
Signature · 1 line
Duy
Re: [PATCH 7/8] ls-files: support --max-depth
Quoted 9 lines · Duy Nguyen
Quoted 7 lines · Matthieu Moy
----- Original Message -----
Quoted 5 lines
The use case in mind is --max-depth=0 to stop recursion. With this we can do
git config --global alias.ls 'ls-files --column --color --max-depth=0'
and have "git ls" with an output very similar to GNU ls.
Quoted 8 lines
Quoted 1 line
One big difference though: your "git ls" does not show directories. I understand that this is easier to implement, but from the user point of view it resulted in a "wtf" from me running "git ls" in a repository containing essentially directories, and seeing just a README file in the output.
I was hoping you didn't notice :) It'll be more difficult but not impossible.
Quoted 1 line
Ideally (for me), directories should be shown with a trailing / like "ls -F" does.
I'd rather go with no trailing slash by default and add -F (which seems to be more than just '/')
And we need a new indicator for submodules when -F is used. I think it should be different than '/'. I randomly picked '&' for now. Any suggestions welcome.
Signature · 1 line
Duy
Re: [PATCH 7/8] ls-files: support --max-depth
In reply to Duy NguyenQuoted 2 lines · Duy Nguyen
I'd rather go with no trailing slash by default and add -F (which seems to be more than just '/')
... and then add a configuration variable to let users enable it by default.
For GNU ls, I have "alias ls='ls -F --color=auto'" in my shell's configuration, but I cannot push the analogy by aliasing "git ls" because Git doesn't allow aliasing existing commands.
Signature · 2 lines
Matthieu Moy http://www-verimag.imag.fr/~moy/
Re: [PATCH 7/8] ls-files: support --max-depth
Quoted 11 lines · Matthieu Moy
Quoted 2 lines · Duy Nguyen
I'd rather go with no trailing slash by default and add -F (which seems to be more than just '/')
... and then add a configuration variable to let users enable it by default.
For GNU ls, I have "alias ls='ls -F --color=auto'" in my shell's configuration, but I cannot push the analogy by aliasing "git ls" because Git doesn't allow aliasing existing commands.
I can do that but I want to push for a general solution instead of ls-only. How about config key defaults.<cmd>, containing a list of arguments, that will be prepended to git-<cmd>? Only some commands are marked to support this by adding USE_DEFAULTS in the array commands[] in git.c. And "git --no-defaults <cmd>" will ignore defaults.<cmd> (or "git -c defaults.<cmd>= <cmd>" but it's less obvious). GIT_NO_DEFAULTS can also be set, which has the same effect for all commands.
Signature · 1 line
Duy
Re: [PATCH 7/8] ls-files: support --max-depth
Quoted 14 lines · Duy Nguyen
Quoted 11 lines · Matthieu Moy
Quoted 2 lines · Duy Nguyen
I'd rather go with no trailing slash by default and add -F (which seems to be more than just '/')
... and then add a configuration variable to let users enable it by default.
For GNU ls, I have "alias ls='ls -F --color=auto'" in my shell's configuration, but I cannot push the analogy by aliasing "git ls" because Git doesn't allow aliasing existing commands.
Quoted 7 lines
I can do that but I want to push for a general solution instead of ls-only. How about config key defaults.<cmd>, containing a list of arguments, that will be prepended to git-<cmd>? Only some commands are marked to support this by adding
USE_DEFAULTSin the array commands[] ingit.c. And "git --no-defaults <cmd>" will ignore defaults.<cmd> (or "git -c defaults.<cmd>= <cmd>" but it's less obvious).GIT_NO_DEFAULTScan also be set, which has the same effect for all commands.
Another option is to make git recognize program name g<something> and auto map it to the alias <something>. For example, the symlink "gls" will be executed as "git ls" (and the alias version is preferred over the builtin one). Of course you can't have alias "it" because "git" is already taken. It works for many cases, it's faster to type, and it does not break current scripts.
Signature · 1 line
Duy
PATCH 8/8 Add git-ls, a user friendly version of ls-files and more
In reply to Nguyễn Thái Ngọc DuyFor now it's simply a wrapper of ls-files with some default goodies. But I want it to be the UI for ls-tree and perhaps git diff --name-only [--cached] too.
--- builtin.h | 1 + builtin/ls-files.c | 19 +++++++++++++++++++ git.c | 1 + 3 files changed, 21 insertions(+)
builtin.h +1 -0
@@ -75,6 +75,7 @@ extern int cmd_index_pack(int argc, const char **argv, const char *prefix);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 (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_tree (int argc,const char **argv,const char *prefix);extern int cmd_ls_remote (int argc,const char **argv,const char *prefix);
builtin/ls-files.c +19 -0
@@ -17,6 +17,7 @@#include "color.h" #include "ls_colors.h" #include "column.h" +#include "argv-array.h" static int abbrev;static int show_deleted;
@@ -479,6 +480,7 @@ 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 ;int max_depth =-1 ; +int refresh =0 ;const char *max_prefix;struct dir_struct dir;struct exclude_list *el;
@@ -539,6 +541,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) {OPTION_INTEGER ,0 ,"max-depth" , &max_depth,N_ ("depth" ),N_ ("descend at most <depth> levels" ),PARSE_OPT_NONEG , NULL, 1 }, +OPT_HIDDEN_BOOL (0 ,"refresh-index" , &refresh,N_ ("refresh index" )),OPT__ABBREV (&abbrev),OPT_BOOL (0 ,"debug" , &debug_mode,N_ ("show debugging data" )),OPT_END ()
@@ -555,6 +558,8 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)if (read_cache () <0 )die ("index file corrupt" ); +if (refresh) +refresh_cache (REFRESH_QUIET ); argc =parse_options (argc, argv, prefix, builtin_ls_files_options, ls_files_usage,0 );
@@ -652,3 +657,17 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)return 0 ; } + +int cmd_ls (int argc,const char **argv,const char *cmd_prefix) +{ +struct argv_array av =ARGV_ARRAY_INIT ; +argv_array_pushl (&av,"ls-files" , +"--color" ,"--column" ,"--max-depth=0" , +"--exclude-standard" ,"--refresh-index" , +NULL ); + argv++; +while (*argv) +argv_array_push (&av, *argv++); +trace_argv_printf (av.argv,"trace: built-in: git" ); +return cmd_ls_files (av.argc, av.argv, cmd_prefix); +}
git.c +1 -0
@@ -381,6 +381,7 @@ static struct cmd_struct commands[] = { { "init", cmd_init_db }, { "init-db", cmd_init_db }, { "log", cmd_log, RUN_SETUP }, + { "ls", cmd_ls, RUN_SETUP }, { "ls-files", cmd_ls_files, RUN_SETUP }, { "ls-remote", cmd_ls_remote, RUN_SETUP_GENTLY }, { "ls-tree", cmd_ls_tree, RUN_SETUP },
Signature · 1 line
1.9.0.40.gaa8c3ea
Re: [PATCH 8/8] Add git-ls, a user friendly version of ls-files and more
builtin/ls-files.c int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) · line 667
Quoted 7 lines · Nguyễn Thái Ngọc Duy
builtin/ls-files.c +7
-0+int cmd_ls (int argc,const char **argv,const char *cmd_prefix) +{ +struct argv_array av =ARGV_ARRAY_INIT ; +argv_array_pushl (&av,"ls-files" , +"--color" ,"--column" ,"--max-depth=0" , +"--exclude-standard" ,"--refresh-index" , +NULL );
I already have "git ls" as an alias for "git ls-files --exclude-standard", so this change would bring me even more goodies, I like it.
I'm a bit hesitant on the --max-depth=0 part by default. I like the way my "git ls" alias recurses by default, but that may be just because I'm used to it. Also, disabling it is can only be done by adding --max-depth=-1 to the command-line, which isn't very convenient. Perhaps there should be a "git ls -R" shorthand for "git ls --max-depth=-1".
Signature · 2 lines
Matthieu Moy http://www-verimag.imag.fr/~moy/
v2 cover git-ls
In reply to Nguyễn Thái Ngọc DuyCompared to v1, git-ls now does not accept ls-files options (previous git-ls is more like an alias of ls-files). I want this because ls may take a different set of options than ls-files. Most functionality is shared so if you're not happy with ls, you can fall back to ls-files.
New alias options are supported, -1 == --no-column, -R == --max-depth=-1. If more than one file criteria is chosen (e.g. "ls -cmo") then --tag is implied. File order is fixed ("ls-files -cmo" actually shows two or three separate listings, "ls -cmo" shows one sorted listing). It also shows directories from the index.
Documentation is there. No tests yet because the behavior may still need some polishing.
Nguyễn Thái Ngọc Duy (17):
ls_colors.c: add $LS_COLORS parsing code ls_colors.c: parse color.ls.* from config file ls_colors.c: add function to color a file name ls_colors.c: highlight submodules like directories
ls-files: buffer full item in strbuf before printing
ls-files: add --color to highlight file names
ls-files: add --column
ls-files: support --max-depth
ls-files: split main ls-files logic into ls_files() function Add git-ls, a user friendly version of ls-files and more
ls: -u does not imply showing stages
ls: add -R/--recursive short for --max-depth=-1
ls: add -1 short for --no-column in the spirit of GNU ls
ls: add -t back
ls: sort output and remove duplicates
ls: do not show duplicate cached entries
ls: show directories as well as files
.gitignore | 1 + Documentation/config.txt | 22 ++ Documentation/git-ls-files.txt | 22 ++ Documentation/git-ls.txt (new) | 95 ++++++++ Makefile | 2 + builtin.h | 1 + builtin/ls-files.c | 446 +++++++++++++++++++++++++++++------- color.h | 10 + command-list.txt | 1 + git.c | 1 + ls_colors.c (new) | 496 +++++++++++++++++++++++++++++++++++++++++ 11 files changed, 1012 insertions(+), 85 deletions(-) create mode 100644 Documentation/git-ls.txt create mode 100644 ls_colors.c
Signature · 1 line
1.9.1.345.ga1a145c
PATCH v2 1/17 ls_colors.c: add $LS_COLORS parsing code
Reusing color settings from $LS_COLORS could give a native look and feel on file coloring.
This code is basically from coreutils.git [1], rewritten to fit Git.
As this is from GNU ls, the environment variable CLICOLOR is not tested. It is to be decided later whether we should ignore $LS_COLORS if $CLICOLOR is not set on Mac or FreeBSD.
[1] commit 7326d1f1a67edf21947ae98194f98c38b6e9e527 file src/ls.c. This is the last GPL-2 commit before coreutils turns to GPL-3.
--- Makefile | 1 + color.h | 8 ++ ls_colors.c (new) | 398 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 407 insertions(+) create mode 100644 ls_colors.c
Makefile +1 -0
@@ -819,6 +819,7 @@ LIB_OBJS += list-objects.o LIB_OBJS += ll-merge.o LIB_OBJS += lockfile.o LIB_OBJS += log-tree.o +LIB_OBJS += ls_colors.o LIB_OBJS += mailmap.o LIB_OBJS += match-trees.o LIB_OBJS += merge.o
color.h +8 -0
@@ -45,6 +45,12 @@ struct strbuf;#define GIT_COLOR_BG_MAGENTA "\033[45m"#define GIT_COLOR_BG_CYAN "\033[46m" +#define GIT_COLOR_WHITE_ON_RED "\033[37;41m" +#define GIT_COLOR_WHITE_ON_BLUE "\033[37;44m" +#define GIT_COLOR_BLACK_ON_YELLOW "\033[30;43m" +#define GIT_COLOR_BLUE_ON_GREEN "\033[34;42m" +#define GIT_COLOR_BLACK_ON_GREEN "\033[30;42m" +/* A special value meaning "no color selected" */ #define GIT_COLOR_NIL "NIL"
@@ -87,4 +93,6 @@ void color_print_strbuf(FILE *fp, const char *color, const struct strbuf *sb);int color_is_nil (const char *color); +void parse_ls_color (void ); +#endif /* COLOR_H */
ls_colors.c new file +398 -0
398 lines not on this page · raw message
Signature · 1 line
1.9.1.345.ga1a145c
PATCH v2 2/17 ls_colors.c: parse color.ls.* from config file
In reply to Nguyễn Thái Ngọc DuyThis is the second (and preferred) source for color information. This will override $LS_COLORS.
--- Documentation/config.txt | 11 +++++++++++ ls_colors.c | 26 ++++++++++++++++++++++++++ 2 files changed, 37 insertions(+)
Documentation/config.txt +11 -0
@@ -909,6 +909,17 @@ color.status.<slot>:: to red). The values of these variables may be specified as in color.branch.<slot>. +color.ls.<slot>:: + Use customized color for file name colorization. If not set + and the environment variable LS_COLORS is set, color settings + from $LS_COLORS are used. `<slot>` can be `normal`, `file`, + `directory`, `symlink`, `fifo`, `socket`, `block`, `char`, + `missing`, `orphan`, `executable`, `door`, `setuid`, `setgid`, + `sticky`, `otherwritable`, `stickyotherwritable`, `cap`, + `multihardlink`. The values of these variables may be + specified as in color.branch.<slot>. + + color.ui:: This variable determines the default value for variables such as `color.diff` and `color.grep` that control the use of color
ls_colors.c +26 -0
@@ -68,6 +68,14 @@ static const char *const indicator_name[] = {NULL }; +static const char *const config_name[] = { +"" ,"" ,"" ,"" ,"normal" ,"file" ,"directory" ,"symlink" , +"fifo" ,"socket" ,"block" ,"char" ,"missing" ,"orphan" ,"executable" , +"door" ,"setuid" ,"setgid" ,"sticky" ,"otherwritable" , +"stickyotherwritable" ,"cap" ,"multihardlink" ,"" , +NULL +}; +struct bin_str {size_t len;/* Number of bytes */ const char *string;/* Pointer to the same */
@@ -285,6 +293,23 @@ static int get_funky_string(char **dest, const char **src, int equals_end,return state !=ST_ERROR ; } +static int ls_colors_config (const char *var,const char *value,void *cb) +{ +int slot; +if (!starts_with (var,"color.ls." )) +return 0 ; + var +=9 ; +for (slot =0 ; config_name[slot]; slot++) +if (!strcasecmp (var, config_name[slot])) +break ; +if (!config_name[slot]) +return 0 ; +if (!value) +return config_error_nonbool (var); +color_parse (value, var, ls_colors[slot]); +return 0 ; +} +void parse_ls_color (void ) {const char *p;/* Pointer to character being parsed */
@@ -395,4 +420,5 @@ void parse_ls_color(void)if (!strcmp (ls_colors[LS_LN ],"target" )) color_symlink_as_referent =1 ; +git_config (ls_colors_config,NULL ); }
Signature · 1 line
1.9.1.345.ga1a145c
PATCH v2 3/17 ls_colors.c: add function to color a file name
In reply to Nguyễn Thái Ngọc DuyTthe new function is based on print_color_indicator() from commit 7326d1f1a67edf21947ae98194f98c38b6e9e527 in coreutils.git.
--- color.h | 2 ++ ls_colors.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+)
color.h +2 -0
@@ -94,5 +94,7 @@ void color_print_strbuf(FILE *fp, const char *color, const struct strbuf *sb);int color_is_nil (const char *color);void parse_ls_color (void ); +void color_filename (struct strbuf *sb,const char *name, +const char *display_name,mode_t mode,int linkok);#endif /* COLOR_H */
ls_colors.c +66 -0
69 lines not on this page · raw message
Signature · 1 line
1.9.1.345.ga1a145c
Re: [PATCH v2 03/17] ls_colors.c: add function to color a file name
Quoted 1 line · Nguyễn Thái Ngọc Duy
Tthe new function is based on
print_color_indicator()from commit
s/Tthe/The/
Quoted 101 lines
7326d1f1a67edf21947ae98194f98c38b6e9e527in coreutils.git.Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>--- color.h | 2 ++ ls_colors.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+)color.h +2
-0@@ -94,5 +94,7 @@ void color_print_strbuf(FILE *fp, const char *color, const struct strbuf *sb);int color_is_nil (const char *color);void parse_ls_color (void ); +void color_filename (struct strbuf *sb,const char *name, +const char *display_name,mode_t mode,int linkok);#endif /* COLOR_H */ ls_colors.c +66
-1@@ -422,3 +422,69 @@ void parse_ls_color(void) color_symlink_as_referent =1 ;git_config (ls_colors_config,NULL ); } + +void color_filename (struct strbuf *sb,const char *name, +const char *display_name,mode_t mode,int linkok) +{ +int type; +struct color_ext_type *ext;/* Color extension */ + +if (S_ISREG (mode)) { + type =LS_FL ; +if ((mode &S_ISUID ) !=0 ) + type =LS_SU ; +else if ((mode &S_ISGID ) !=0 ) + type =LS_SG ; +else if ((mode & (S_IXUSR |S_IXGRP |S_IXOTH )) !=0 ) + type =LS_EX ; + }else if (S_ISDIR (mode)) { +if ((mode &S_ISVTX ) && (mode &S_IWOTH )) + type =LS_TW ; +else if ((mode &S_IWOTH ) !=0 ) + type =LS_OW ; +else if ((mode &S_ISVTX ) !=0 ) + type =LS_ST ; +else + type =LS_DI ; + }else if (S_ISLNK (mode)) + type = (!linkok && *ls_colors[LS_OR ]) ?LS_OR :LS_LN ; +else if (S_ISFIFO (mode)) + type =LS_PI ; +else if (S_ISSOCK (mode)) + type =LS_SO ; +else if (S_ISBLK (mode)) + type =LS_BD ; +else if (S_ISCHR (mode)) + type =LS_CD ; +#ifdef S_ISDOOR + else if (S_ISDOOR (mode)) + type =LS_DO ; +#endif + else +/* Classify a file of some other type as C_ORPHAN. */ + type =LS_OR ; + +/* Check the file's suffix only if still classified as C_FILE. */ + ext =NULL ; +if (type ==LS_FL ) { +/* Test if NAME has a recognized suffix. */ +size_t len =strlen (name); +const char *p = name + len;/* Pointer to final \0. */ +for (ext = color_ext_list; ext !=NULL ; ext = ext->next) { +if (ext->ext.len <= len && + !strncmp (p - ext->ext.len, ext->ext.string, ext->ext.len)) +break ; + } + } + +if (display_name) + name = display_name; +if (ext) +strbuf_addf (sb,"\033[%.*sm%s%s" , + (int )ext->seq.len, ext->seq.string, + name,GIT_COLOR_RESET ); +else if (*ls_colors[type]) +strbuf_addf (sb,"%s%s%s" , ls_colors[type], name,GIT_COLOR_RESET ); +else +strbuf_addstr (sb, name); +} --1.9.1.345.ga1a145c
--
To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v2 4/17 ls_colors.c: highlight submodules like directories
In reply to Nguyễn Thái Ngọc Duy--- Documentation/config.txt | 3 ++- ls_colors.c | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-)
Documentation/config.txt +2 -1
@@ -913,7 +913,8 @@ color.ls.<slot>:: Use customized color for file name colorization. If not set and the environment variable LS_COLORS is set, color settings from $LS_COLORS are used. `<slot>` can be `normal`, `file`, - `directory`, `symlink`, `fifo`, `socket`, `block`, `char`, + `directory`, `submodule`, + `symlink`, `fifo`, `socket`, `block`, `char`, `missing`, `orphan`, `executable`, `door`, `setuid`, `setgid`, `sticky`, `otherwritable`, `stickyotherwritable`, `cap`, `multihardlink`. The values of these variables may be
ls_colors.c +7 -1
@@ -29,6 +29,8 @@ enum color_ls {LS_MH ,/* multi hardlink */ LS_CL ,/* clear end of line */ +LS_SUBMODULE , + MAX_LS };
@@ -58,7 +60,8 @@ static char ls_colors[MAX_LS][COLOR_MAXLEN] = {GIT_COLOR_BLACK_ON_GREEN ,"" ,"" , -"" +"" , +GIT_COLOR_BOLD_BLUE }; static const char *const indicator_name[] = {
@@ -73,6 +76,7 @@ static const char* const config_name[] = {"fifo" ,"socket" ,"block" ,"char" ,"missing" ,"orphan" ,"executable" ,"door" ,"setuid" ,"setgid" ,"sticky" ,"otherwritable" ,"stickyotherwritable" ,"cap" ,"multihardlink" ,"" , +"submodule" ,NULL };
@@ -448,6 +452,8 @@ void color_filename(struct strbuf *sb, const char *name, type =LS_DI ; }else if (S_ISLNK (mode)) type = (!linkok && *ls_colors[LS_OR ]) ?LS_OR :LS_LN ; +else if (S_ISGITLINK (mode)) + type =LS_SUBMODULE ;else if (S_ISFIFO (mode)) type =LS_PI ;else if (S_ISSOCK (mode))
Signature · 1 line
1.9.1.345.ga1a145c
PATCH v2 5/17 ls-files: buffer full item in strbuf before printing
In reply to Nguyễn Thái Ngọc DuyBuffering so that we can manipulate the strings (e.g. coloring) further before finally printing them.
--- builtin/ls-files.c | 48 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 13 deletions(-)
builtin/ls-files.c +35 -13
@@ -47,18 +47,30 @@ static const char *tag_modified = "";static const char *tag_skip_worktree ="" ;static const char *tag_resolve_undo ="" ; -static void write_name (const char *name) +static void write_name (struct strbuf *sb,const char *name) {/* * With "--full-name", prefix_len=0; this caller needs to pass * an empty string in that case (a NULL is good for ""). */ -write_name_quoted_relative (name, prefix_len ? prefix :NULL , - stdout, line_terminator); +const char *real_prefix = prefix_len ? prefix :NULL ; +if (!line_terminator) { +struct strbuf sb2 =STRBUF_INIT ; +strbuf_addstr (sb,relative_path (name, real_prefix, &sb2)); +strbuf_release (&sb2); + }else +quote_path_relative (name, real_prefix, sb); +strbuf_addch (sb, line_terminator); +} + +static void strbuf_fputs (struct strbuf *sb,FILE *fp) +{ +fwrite (sb->buf, sb->len,1 , fp); }static void show_dir_entry (const char *tag,struct dir_entry *ent) { +static struct strbuf sb =STRBUF_INIT ;int len = max_prefix_len;if (len >= ent->len)
@@ -67,8 +79,10 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent)if (!dir_path_match (ent, &pathspec, len, ps_matched))return ; -fputs (tag, stdout); -write_name (ent->name); +strbuf_reset (&sb); +strbuf_addstr (&sb, tag); +write_name (&sb, ent->name); +strbuf_fputs (&sb, stdout); }static void show_other_files (struct dir_struct *dir)
@@ -134,6 +148,7 @@ static void show_killed_files(struct dir_struct *dir)static void show_ce_entry (const char *tag,const struct cache_entry *ce) { +static struct strbuf sb =STRBUF_INIT ;int len = max_prefix_len;if (len >=ce_namelen (ce))
@@ -161,16 +176,18 @@ static void show_ce_entry(const char *tag, const struct cache_entry *ce) tag = alttag; } +strbuf_reset (&sb);if (!show_stage) { -fputs (tag, stdout); +strbuf_addstr (&sb, tag); }else { -printf ("%s%06o %s %d\t" , - tag, - ce->ce_mode, -find_unique_abbrev (ce->sha1,abbrev), -ce_stage (ce)); +strbuf_addf (&sb,"%s%06o %s %d\t" , + tag, + ce->ce_mode, +find_unique_abbrev (ce->sha1,abbrev), +ce_stage (ce)); } -write_name (ce->name); +write_name (&sb, ce->name); +strbuf_fputs (&sb, stdout);if (debug_mode) {const struct stat_data *sd = &ce->ce_stat_data;
@@ -206,7 +223,12 @@ static void show_ru_info(void)printf ("%s%06o %s %d\t" , tag_resolve_undo, ui->mode[i],find_unique_abbrev (ui->sha1[i], abbrev), i +1 ); -write_name (path); +/* +* With "--full-name", prefix_len=0; this caller needs to pass +* an empty string in that case (a NULL is good for ""). +*/ +write_name_quoted_relative (path, prefix_len ? prefix :NULL , + stdout, line_terminator); } } }
Signature · 1 line
1.9.1.345.ga1a145c
Re: [PATCH v2 05/17] ls-files: buffer full item in strbuf before printing
Quoted 47 lines · Nguyễn Thái Ngọc Duy
Buffering so that we can manipulate the strings (e.g. coloring) further before finally printing them.
Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>--- builtin/ls-files.c | 48 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 13 deletions(-)builtin/ls-files.c +15
-3@@ -47,18 +47,30 @@ static const char *tag_modified = "";static const char *tag_skip_worktree ="" ;static const char *tag_resolve_undo ="" ; -static void write_name (const char *name) +static void write_name (struct strbuf *sb,const char *name) {/* * With "--full-name", prefix_len=0; this caller needs to pass * an empty string in that case (a NULL is good for ""). */ -write_name_quoted_relative (name, prefix_len ? prefix :NULL , - stdout, line_terminator); +const char *real_prefix = prefix_len ? prefix :NULL ; +if (!line_terminator) { +struct strbuf sb2 =STRBUF_INIT ; +strbuf_addstr (sb,relative_path (name, real_prefix, &sb2)); +strbuf_release (&sb2); + }else +quote_path_relative (name, real_prefix, sb); +strbuf_addch (sb, line_terminator); +} + +static void strbuf_fputs (struct strbuf *sb,FILE *fp) +{ +fwrite (sb->buf, sb->len,1 , fp); }static void show_dir_entry (const char *tag,struct dir_entry *ent) { +static struct strbuf sb =STRBUF_INIT ;int len = max_prefix_len;if (len >= ent->len)
builtin/ls-files.c static void show_dir_entry(const char *tag, struct dir_entry *ent) · line 85
Quoted 9 lines
builtin/ls-files.c +4
-2@@ -67,8 +79,10 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent)if (!dir_path_match (ent, &pathspec, len, ps_matched))return ; -fputs (tag, stdout); -write_name (ent->name); +strbuf_reset (&sb); +strbuf_addstr (&sb, tag); +write_name (&sb, ent->name); +strbuf_fputs (&sb, stdout);
strbuf_release(&sb);
Quoted 12 lines
builtin/ls-files.c +1
-0}static void show_other_files (struct dir_struct *dir)@@ -134,6 +148,7 @@ static void show_killed_files(struct dir_struct *dir)static void show_ce_entry (const char *tag,const struct cache_entry *ce) { +static struct strbuf sb =STRBUF_INIT ;int len = max_prefix_len;if (len >=ce_namelen (ce))
builtin/ls-files.c static void show_ce_entry(const char *tag, const struct cache_entry *ce) · line 179
Quoted 4 lines
builtin/ls-files.c +1
-0@@ -161,16 +176,18 @@ static void show_ce_entry(const char *tag, const struct cache_entry *ce) tag = alttag; } +strbuf_reset (&sb);
'sb' is empty at this point. Why reset it?
Quoted 8 lines
builtin/ls-files.c +1
-5if (!show_stage) { -fputs (tag, stdout); +strbuf_addstr (&sb, tag); }else { - printf("%s%06o %s %d\t", - tag, - ce->ce_mode, - find_unique_abbrev(ce->sha1,abbrev),
builtin/ls-files.c static void show_ce_entry(const char *tag, const struct cache_entry *ce) · line 190
Quoted 10 lines
builtin/ls-files.c +7
-2- ce_stage(ce)); +strbuf_addf (&sb,"%s%06o %s %d\t" , + tag, + ce->ce_mode, +find_unique_abbrev (ce->sha1,abbrev), +ce_stage (ce)); } -write_name (ce->name); +write_name (&sb, ce->name); +strbuf_fputs (&sb, stdout);
strbuf_release(&sb);
Quoted 19 lines
builtin/ls-files.c +6
-2if (debug_mode) {const struct stat_data *sd = &ce->ce_stat_data;@@ -206,7 +223,12 @@ static void show_ru_info(void)printf ("%s%06o %s %d\t" , tag_resolve_undo, ui->mode[i],find_unique_abbrev (ui->sha1[i], abbrev), i +1 ); -write_name (path); +/* +* With "--full-name", prefix_len=0; this caller needs to pass +* an empty string in that case (a NULL is good for ""). +*/ +write_name_quoted_relative (path, prefix_len ? prefix :NULL , + stdout, line_terminator); } } } --1.9.1.345.ga1a145c
Re: [PATCH v2 05/17] ls-files: buffer full item in strbuf before printing
Quoted 10 lines · Eric Sunshine
Quoted 10 lines
static void
show_dir_entry(const char *tag, struct dir_entry *ent){builtin/ls-files.c +1
-0+static struct strbuf sb =STRBUF_INIT ;int len = max_prefix_len;if (len >= ent->len)@@ -67,8 +79,10 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent)if (!dir_path_match (ent, &pathspec, len, ps_matched))return ;
Quoted 8 lines
builtin/ls-files.c static void show_dir_entry(const char *tag, struct dir_entry *ent) · line 85
Quoted 6 lines
builtin/ls-files.c +4
-2-fputs (tag, stdout); -write_name (ent->name); +strbuf_reset (&sb); +strbuf_addstr (&sb, tag); +write_name (&sb, ent->name); +strbuf_fputs (&sb, stdout);
strbuf_release(&sb);
Not strictly necessary because sb is static and will be reset at the next call. I just want to lower the number of allocation (write_name allocates some more). It may be a premature optimization though.
The same for changes in show_ce_entry().
Signature · 1 line
Duy
Re: [PATCH v2 05/17] ls-files: buffer full item in strbuf before printing
Quoted 20 lines · Duy Nguyen
Quoted 10 lines · Eric Sunshine
Quoted 10 lines
static void
show_dir_entry(const char *tag, struct dir_entry *ent){builtin/ls-files.c +1
-0+static struct strbuf sb =STRBUF_INIT ;int len = max_prefix_len;if (len >= ent->len)@@ -67,8 +79,10 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent)if (!dir_path_match (ent, &pathspec, len, ps_matched))return ;Quoted 8 lines
builtin/ls-files.c static void show_dir_entry(const char *tag, struct dir_entry *ent) · line 85
Quoted 6 lines
builtin/ls-files.c +4
-2-fputs (tag, stdout); -write_name (ent->name); +strbuf_reset (&sb); +strbuf_addstr (&sb, tag); +write_name (&sb, ent->name); +strbuf_fputs (&sb, stdout);
strbuf_release(&sb);
Quoted 3 lines
Not strictly necessary because sb is static and will be reset at the next call. I just want to lower the number of allocation (
write_nameallocates some more). It may be a premature optimization though.
Ah, yes. I noted the 'static' on my initial read-through but had forgotten about it by the time I finally got to a computer with which I could send plain-text email. Sorry for the noise.
Quoted 3 lines
The same for changes in
show_ce_entry().
--
Duy
PATCH v2 6/17 ls-files: add --color to highlight file names
In reply to Nguyễn Thái Ngọc Duy--- Documentation/git-ls-files.txt | 9 +++++++++ builtin/ls-files.c | 38 +++++++++++++++++++++++++++++++++++--- 2 files changed, 44 insertions(+), 3 deletions(-)
Documentation/git-ls-files.txt +9 -0
@@ -147,6 +147,15 @@ a space) at the start of each line: possible for manual inspection; the exact format may change at any time. +--color[=<when>]:: + Color file names. The value must be always (default), never, + or auto. + +--no-color:: + Turn off coloring, even when the configuration file gives the + default to color output, same as `--color=never`. This is the + default. + \--:: Do not interpret any more arguments as options.
builtin/ls-files.c +35 -3
@@ -14,6 +14,7 @@#include "resolve-undo.h" #include "string-list.h" #include "pathspec.h" +#include "color.h" static int abbrev;static int show_deleted;
@@ -27,6 +28,7 @@ static int show_killed;static int show_valid_bit;static int line_terminator ='\n' ;static int debug_mode; +static int use_color;static const char *prefix;static int max_prefix_len;
@@ -60,7 +62,6 @@ static void write_name(struct strbuf *sb, const char *name)strbuf_release (&sb2); }else quote_path_relative (name, real_prefix, sb); -strbuf_addch (sb, line_terminator); }static void strbuf_fputs (struct strbuf *sb,FILE *fp)
@@ -68,6 +69,21 @@ static void strbuf_fputs(struct strbuf *sb, FILE *fp)fwrite (sb->buf, sb->len,1 , fp); } +static void write_dir_entry (struct strbuf *sb,const struct dir_entry *ent) +{ +struct strbuf quoted =STRBUF_INIT ; +struct stat st; +if (stat (ent->name, &st)) + st.st_mode =0 ; +write_name ("ed, ent->name); +if (want_color (use_color)) +color_filename (sb, ent->name, quoted.buf, st.st_mode,1 ); +else +strbuf_addbuf (sb, "ed); +strbuf_addch (sb, line_terminator); +strbuf_release ("ed); +} +static void show_dir_entry (const char *tag,struct dir_entry *ent) {static struct strbuf sb =STRBUF_INIT ;
@@ -81,7 +97,7 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent)strbuf_reset (&sb);strbuf_addstr (&sb, tag); -write_name (&sb, ent->name); +write_dir_entry (&sb, ent);strbuf_fputs (&sb, stdout); }
@@ -146,6 +162,18 @@ static void show_killed_files(struct dir_struct *dir) } } +static void write_ce_name (struct strbuf *sb,const struct cache_entry *ce) +{ +struct strbuf quoted =STRBUF_INIT ; +write_name ("ed, ce->name); +if (want_color (use_color)) +color_filename (sb, ce->name, quoted.buf, ce->ce_mode,1 ); +else +strbuf_addbuf (sb, "ed); +strbuf_addch (sb, line_terminator); +strbuf_release ("ed); +} +static void show_ce_entry (const char *tag,const struct cache_entry *ce) {static struct strbuf sb =STRBUF_INIT ;
@@ -186,7 +214,7 @@ static void show_ce_entry(const char *tag, const struct cache_entry *ce)find_unique_abbrev (ce->sha1,abbrev), ce_stage(ce)); } -write_name (&sb, ce->name); +write_ce_name (&sb, ce);strbuf_fputs (&sb, stdout);if (debug_mode) {const struct stat_data *sd = &ce->ce_stat_data;
@@ -523,6 +551,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) N_("if any <file> is not in the index, treat this as an error")),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__ABBREV (&abbrev),OPT_BOOL (0 ,"debug" , &debug_mode,N_ ("show debugging data" )),OPT_END ()
@@ -570,6 +599,9 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)if (require_work_tree && !is_inside_work_tree ())setup_work_tree (); +if (want_color (use_color)) +parse_ls_color (); + parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD | PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP,
Signature · 1 line
1.9.1.345.ga1a145c
Re: [PATCH v2 06/17] ls-files: add --color to highlight file names
Quoted 11 lines · Nguyễn Thái Ngọc Duy
Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>--- Documentation/git-ls-files.txt | 9 +++++++++ builtin/ls-files.c | 38 +++++++++++++++++++++++++++++++++++--- 2 files changed, 44 insertions(+), 3 deletions(-)Documentation/git-ls-files.txt +0
-0
Documentation/git-ls-files.txt a space) at the start of each line: · line 152
Quoted 6 lines
Documentation/git-ls-files.txt +3
-0@@ -147,6 +147,15 @@ a space) at the start of each line: possible for manual inspection; the exact format may change at any time. +--color[=<when>]:: + Color file names. The value must be always (default), never, + or auto.
Here, the default is "always"...
Documentation/git-ls-files.txt a space) at the start of each line: · line 157
Quoted 4 lines
Documentation/git-ls-files.txt +4
-0+--no-color:: + Turn off coloring, even when the configuration file gives the + default to color output, same as `--color=never`. This is the + default.
But, here the default is "never".
Quoted 116 lines
Documentation/git-ls-files.txt +1
-0+ \--:: Do not interpret any more arguments as options.builtin/ls-files.c +35
-4@@ -14,6 +14,7 @@#include "resolve-undo.h" #include "string-list.h" #include "pathspec.h" +#include "color.h" static int abbrev;static int show_deleted;@@ -27,6 +28,7 @@ static int show_killed;static int show_valid_bit;static int line_terminator ='\n' ;static int debug_mode; +static int use_color;static const char *prefix;static int max_prefix_len;@@ -60,7 +62,6 @@ static void write_name(struct strbuf *sb, const char *name)strbuf_release (&sb2); }else quote_path_relative (name, real_prefix, sb); -strbuf_addch (sb, line_terminator); }static void strbuf_fputs (struct strbuf *sb,FILE *fp)@@ -68,6 +69,21 @@ static void strbuf_fputs(struct strbuf *sb, FILE *fp)fwrite (sb->buf, sb->len,1 , fp); } +static void write_dir_entry (struct strbuf *sb,const struct dir_entry *ent) +{ +struct strbuf quoted =STRBUF_INIT ; +struct stat st; +if (stat (ent->name, &st)) + st.st_mode =0 ; +write_name ("ed, ent->name); +if (want_color (use_color)) +color_filename (sb, ent->name, quoted.buf, st.st_mode,1 ); +else +strbuf_addbuf (sb, "ed); +strbuf_addch (sb, line_terminator); +strbuf_release ("ed); +} +static void show_dir_entry (const char *tag,struct dir_entry *ent) {static struct strbuf sb =STRBUF_INIT ;@@ -81,7 +97,7 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent)strbuf_reset (&sb);strbuf_addstr (&sb, tag); -write_name (&sb, ent->name); +write_dir_entry (&sb, ent);strbuf_fputs (&sb, stdout); }@@ -146,6 +162,18 @@ static void show_killed_files(struct dir_struct *dir) } } +static void write_ce_name (struct strbuf *sb,const struct cache_entry *ce) +{ +struct strbuf quoted =STRBUF_INIT ; +write_name ("ed, ce->name); +if (want_color (use_color)) +color_filename (sb, ce->name, quoted.buf, ce->ce_mode,1 ); +else +strbuf_addbuf (sb, "ed); +strbuf_addch (sb, line_terminator); +strbuf_release ("ed); +} +static void show_ce_entry (const char *tag,const struct cache_entry *ce) {static struct strbuf sb =STRBUF_INIT ;@@ -186,7 +214,7 @@ static void show_ce_entry(const char *tag, const struct cache_entry *ce)find_unique_abbrev (ce->sha1,abbrev), ce_stage(ce)); } -write_name (&sb, ce->name); +write_ce_name (&sb, ce);strbuf_fputs (&sb, stdout);if (debug_mode) {const struct stat_data *sd = &ce->ce_stat_data;@@ -523,6 +551,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) N_("if any <file> is not in the index, treat this as an error")),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__ABBREV (&abbrev),OPT_BOOL (0 ,"debug" , &debug_mode,N_ ("show debugging data" )),OPT_END ()@@ -570,6 +599,9 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)if (require_work_tree && !is_inside_work_tree ())setup_work_tree (); +if (want_color (use_color)) +parse_ls_color (); + parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD | PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP, --1.9.1.345.ga1a145c
--
To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2 06/17] ls-files: add --color to highlight file names
Quoted 15 lines · Eric Sunshine
Quoted 14 lines · Nguyễn Thái Ngọc Duy
Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>--- Documentation/git-ls-files.txt | 9 +++++++++ builtin/ls-files.c | 38 +++++++++++++++++++++++++++++++++++--- 2 files changed, 44 insertions(+), 3 deletions(-)Documentation/git-ls-files.txt +0
-0@@ -147,6 +147,15 @@ a space) at the start of each line: possible for manual inspection; the exact format may change at any time.
Quoted 5 lines
Documentation/git-ls-files.txt a space) at the start of each line: · line 152
Quoted 3 lines
Documentation/git-ls-files.txt +3
-0+--color[=<when>]:: + Color file names. The value must be always (default), never, + or auto.Here, the default is "always"...
These (.txt changes in other patches as well) are mostly copy and paste from existing .txt files. You may want to grep through and fix other places as well, in a separate series.
Quoted 7 lines
Documentation/git-ls-files.txt a space) at the start of each line: · line 157
Quoted 5 lines
Documentation/git-ls-files.txt +4
-0+--no-color:: + Turn off coloring, even when the configuration file gives the + default to color output, same as `--color=never`. This is the + default.But, here the default is "never".
What I mean is color is turned off by default for ls-files (in contrast, ls has color on by default). The default 'always' means that if you write --color without the <when> part, then it's --color=always. How do I phrase to make it clear?
Signature · 1 line
Duy
Re: [PATCH v2 06/17] ls-files: add --color to highlight file names
Quoted 32 lines · Duy Nguyen
Quoted 15 lines · Eric Sunshine
Quoted 14 lines · Nguyễn Thái Ngọc Duy
Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>--- Documentation/git-ls-files.txt | 9 +++++++++ builtin/ls-files.c | 38 +++++++++++++++++++++++++++++++++++--- 2 files changed, 44 insertions(+), 3 deletions(-)Documentation/git-ls-files.txt +0
-0@@ -147,6 +147,15 @@ a space) at the start of each line: possible for manual inspection; the exact format may change at any time.Quoted 5 lines
Documentation/git-ls-files.txt a space) at the start of each line: · line 152
Quoted 3 lines
Documentation/git-ls-files.txt +3
-0+--color[=<when>]:: + Color file names. The value must be always (default), never, + or auto.Here, the default is "always"...
These (.txt changes in other patches as well) are mostly copy and paste from existing .txt files. You may want to grep through and fix other places as well, in a separate series.
Quoted 6 lines
Quoted 5 lines
Documentation/git-ls-files.txt +4
-0+--no-color:: + Turn off coloring, even when the configuration file gives the + default to color output, same as `--color=never`. This is the + default.
Quoted 6 lines
Quoted 1 line
But, here the default is "never".
What I mean is color is turned off by default for ls-files (in contrast, ls has color on by default). The default 'always' means that if you write --color without the <when> part, then it's --color=always. How do I phrase to make it clear?
Perhaps:
Color file names. The value must be always, never, or auto. --color by itself is the same as --color=always.
Quoted 2 lines
--
Duy
PATCH v2 7/17 ls-files: add --column
In reply to Nguyễn Thái Ngọc Duy--- Documentation/git-ls-files.txt | 6 ++++++ builtin/ls-files.c | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+)
Documentation/git-ls-files.txt +6 -0
@@ -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 + are equivalent to 'always' and 'never' respectively. + \--:: Do not interpret any more arguments as options.
builtin/ls-files.c +25 -0
@@ -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);
Signature · 1 line
1.9.1.345.ga1a145c
Re: [PATCH v2 07/17] ls-files: add --column
Quoted 11 lines · Nguyễn Thái Ngọc Duy
Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>--- Documentation/git-ls-files.txt | 6 ++++++ builtin/ls-files.c | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+)Documentation/git-ls-files.txt +0
-0
Documentation/git-ls-files.txt a space) at the start of each line: · line 162
Quoted 7 lines
Documentation/git-ls-files.txt +4
-0@@ -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 90 lines
Documentation/git-ls-files.txt +2
-0+ are equivalent to 'always' and 'never' respectively. + \--:: Do not interpret any more arguments as options.builtin/ls-files.c +25
-1@@ -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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v2 8/17 ls-files: support --max-depth
In reply to Nguyễn Thái Ngọc Duy--- Documentation/git-ls-files.txt | 7 +++++++ builtin/ls-files.c | 7 +++++++ 2 files changed, 14 insertions(+)
Documentation/git-ls-files.txt +7 -0
@@ -162,6 +162,13 @@ a space) at the start of each line: for option syntax.`--column` and `--no-column` without options are equivalent to 'always' and 'never' respectively. +--max-depth <depth>:: + For each <pathspec> given on command line, descend at most <depth> + levels of directories. A negative value means no limit. + This option is ignored if <pathspec> contains active wildcards. + In other words if "a*" matches a directory named "a*", + "*" is matched literally so --max-depth is still effective. + \--:: Do not interpret any more arguments as options.
builtin/ls-files.c +7 -0
@@ -503,6 +503,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; +int max_depth =-1 ;const char *max_prefix;struct dir_struct dir;struct exclude_list *el;
@@ -560,6 +561,9 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) 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" )), + { OPTION_INTEGER, 0, "max-depth", &max_depth, N_("depth"), +N_ ("descend at most <depth> levels" ),PARSE_OPT_NONEG , + NULL, 1 },OPT__ABBREV (&abbrev),OPT_BOOL (0 ,"debug" , &debug_mode,N_ ("show debugging data" )),OPT_END ()
@@ -624,8 +628,11 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)parse_pathspec (&pathspec,0 ,PATHSPEC_PREFER_CWD | + (max_depth !=-1 ?PATHSPEC_MAXDEPTH_VALID :0 ) |PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP , prefix, argv); + pathspec.max_depth = max_depth; + pathspec.recursive =1 ;/* Find common prefix for all pathspec's */ max_prefix =common_prefix (&pathspec);
Signature · 1 line
1.9.1.345.ga1a145c
Re: [PATCH v2 08/17] ls-files: support --max-depth
Quoted 11 lines · Nguyễn Thái Ngọc Duy
Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>--- Documentation/git-ls-files.txt | 7 +++++++ builtin/ls-files.c | 7 +++++++ 2 files changed, 14 insertions(+)Documentation/git-ls-files.txt +0
-0
Documentation/git-ls-files.txt a space) at the start of each line: · line 165
Quoted 4 lines
Documentation/git-ls-files.txt +1
-0@@ -162,6 +162,13 @@ a space) at the start of each line: for option syntax.`--column` and `--no-column` without options are equivalent to 'always' and 'never' respectively. +--max-depth <depth>::
Other options in this file are documented as:
--max-depth=<depth>::
Documentation/git-ls-files.txt a space) at the start of each line: · line 170
Quoted 5 lines
Documentation/git-ls-files.txt +5
-0+ For each <pathspec> given on command line, descend at most <depth> + levels of directories. A negative value means no limit. + This option is ignored if <pathspec> contains active wildcards. + In other words if "a*" matches a directory named "a*", + "*" is matched literally so --max-depth is still effective.
Would it be worthwhile to mention the default?
Quoted 40 lines
Documentation/git-ls-files.txt +1
-0+ \--:: Do not interpret any more arguments as options.builtin/ls-files.c +7
-1@@ -503,6 +503,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; +int max_depth =-1 ;const char *max_prefix;struct dir_struct dir;struct exclude_list *el;@@ -560,6 +561,9 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) 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" )), + { OPTION_INTEGER, 0, "max-depth", &max_depth, N_("depth"), +N_ ("descend at most <depth> levels" ),PARSE_OPT_NONEG , + NULL, 1 },OPT__ABBREV (&abbrev),OPT_BOOL (0 ,"debug" , &debug_mode,N_ ("show debugging data" )),OPT_END ()@@ -624,8 +628,11 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)parse_pathspec (&pathspec,0 ,PATHSPEC_PREFER_CWD | + (max_depth !=-1 ?PATHSPEC_MAXDEPTH_VALID :0 ) |PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP , prefix, argv); + pathspec.max_depth = max_depth; + pathspec.recursive =1 ;/* Find common prefix for all pathspec's */ max_prefix =common_prefix (&pathspec); --1.9.1.345.ga1a145c
PATCH v2 9/17 ls-files: split main ls-files logic into ls_files() function
In reply to Nguyễn Thái Ngọc DuyThis is a preparation step for the introduction of git-ls. "git ls" has a different set of command line options, but it will eventually call ls_files().
--- builtin/ls-files.c | 164 +++++++++++++++++++++++++++-------------------------- 1 file changed, 85 insertions(+), 79 deletions(-)
builtin/ls-files.c +85 -79
@@ -31,6 +31,8 @@ static int line_terminator = '\n';static int debug_mode;static int use_color;static unsigned int colopts; +static int max_depth =-1 ; +static int show_tag;static const char *prefix;static int max_prefix_len;
@@ -42,6 +44,8 @@ static const char *with_tree;static int exc_given;static int exclude_args;static struct string_list output =STRING_LIST_INIT_NODUP ; +static struct dir_struct dir; +static struct string_list exclude_list =STRING_LIST_INIT_NODUP ;static const char *tag_cached ="" ;static const char *tag_unmerged ="" ;
@@ -500,89 +504,12 @@ static int option_parse_exclude_standard(const struct option *opt,return 0 ; } -int cmd_ls_files (int argc,const char **argv,const char *cmd_prefix) +static int ls_files (const char **argv,const char *prefix) { -int require_work_tree =0 , show_tag =0 , i; -int max_depth =-1 ; +int require_work_tree =0 , i;const char *max_prefix; -struct dir_struct dir;struct exclude_list *el; -struct string_list exclude_list =STRING_LIST_INIT_NODUP ; -struct option builtin_ls_files_options[] = { - {OPTION_CALLBACK ,'z' ,NULL ,NULL ,NULL , -N_ ("paths are separated with NUL character" ), -PARSE_OPT_NOARG , option_parse_z }, -OPT_BOOL ('t' ,NULL , &show_tag, -N_ ("identify the file status with tags" )), -OPT_BOOL ('v' ,NULL , &show_valid_bit, -N_ ("use lowercase letters for 'assume unchanged' files" )), -OPT_BOOL ('c' ,"cached" , &show_cached, -N_ ("show cached files in the output (default)" )), -OPT_BOOL ('d' ,"deleted" , &show_deleted, -N_ ("show deleted files in the output" )), -OPT_BOOL ('m' ,"modified" , &show_modified, -N_ ("show modified files in the output" )), -OPT_BOOL ('o' ,"others" , &show_others, -N_ ("show other files in the output" )), -OPT_BIT ('i' ,"ignored" , &dir.flags, -N_ ("show ignored files in the output" ), -DIR_SHOW_IGNORED ), -OPT_BOOL ('s' ,"stage" , &show_stage, -N_ ("show staged contents' object name in the output" )), -OPT_BOOL ('k' ,"killed" , &show_killed, -N_ ("show files on the filesystem that need to be removed" )), -OPT_BIT (0 ,"directory" , &dir.flags, -N_ ("show 'other' directories' name only" ), -DIR_SHOW_OTHER_DIRECTORIES ), -OPT_NEGBIT (0 ,"empty-directory" , &dir.flags, -N_ ("don't show empty directories" ), -DIR_HIDE_EMPTY_DIRECTORIES ), -OPT_BOOL ('u' ,"unmerged" , &show_unmerged, -N_ ("show unmerged files in the output" )), -OPT_BOOL (0 ,"resolve-undo" , &show_resolve_undo, -N_ ("show resolve-undo information" )), - {OPTION_CALLBACK ,'x' ,"exclude" , &exclude_list,N_ ("pattern" ), -N_ ("skip files matching pattern" ), -0 , option_parse_exclude }, - {OPTION_CALLBACK ,'X' ,"exclude-from" , &dir,N_ ("file" ), -N_ ("exclude patterns are read from <file>" ), -0 , option_parse_exclude_from }, -OPT_STRING (0 ,"exclude-per-directory" , &dir.exclude_per_dir,N_ ("file" ), -N_ ("read additional per-directory exclude patterns in <file>" )), - {OPTION_CALLBACK ,0 ,"exclude-standard" , &dir,NULL , -N_ ("add the standard git exclusions" ), -PARSE_OPT_NOARG , option_parse_exclude_standard }, - {OPTION_SET_INT ,0 ,"full-name" , &prefix_len,NULL , -N_ ("make the output relative to the project top directory" ), -PARSE_OPT_NOARG |PARSE_OPT_NONEG ,NULL }, -OPT_BOOL (0 ,"error-unmatch" , &error_unmatch, -N_ ("if any <file> is not in the index, treat this as an error" )), -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" )), - {OPTION_INTEGER ,0 ,"max-depth" , &max_depth,N_ ("depth" ), -N_ ("descend at most <depth> levels" ),PARSE_OPT_NONEG , -NULL ,1 }, -OPT__ABBREV (&abbrev), -OPT_BOOL (0 ,"debug" , &debug_mode,N_ ("show debugging data" )), -OPT_END () - }; - -if (argc ==2 && !strcmp (argv[1 ],"-h" )) -usage_with_options (ls_files_usage, builtin_ls_files_options); -memset (&dir,0 ,sizeof (dir)); - prefix = cmd_prefix; -if (prefix) - prefix_len =strlen (prefix); -git_config (git_default_config,NULL ); - -if (read_cache () <0 ) -die ("index file corrupt" ); - - argc =parse_options (argc, argv, prefix, builtin_ls_files_options, - ls_files_usage,0 ); el =add_exclude_list (&dir,EXC_CMDL ,"--exclude option" );for (i =0 ; i < exclude_list.nr; i++) {add_exclude (exclude_list.items[i].string,"" ,0 , el, --exclude_args);
@@ -681,3 +608,82 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)return 0 ; } + +int cmd_ls_files (int argc,const char **argv,const char *cmd_prefix) +{ +struct option builtin_ls_files_options[] = { + {OPTION_CALLBACK ,'z' ,NULL ,NULL ,NULL , +N_ ("paths are separated with NUL character" ), +PARSE_OPT_NOARG , option_parse_z }, +OPT_BOOL ('t' ,NULL , &show_tag, +N_ ("identify the file status with tags" )), +OPT_BOOL ('v' ,NULL , &show_valid_bit, +N_ ("use lowercase letters for 'assume unchanged' files" )), +OPT_BOOL ('c' ,"cached" , &show_cached, +N_ ("show cached files in the output (default)" )), +OPT_BOOL ('d' ,"deleted" , &show_deleted, +N_ ("show deleted files in the output" )), +OPT_BOOL ('m' ,"modified" , &show_modified, +N_ ("show modified files in the output" )), +OPT_BOOL ('o' ,"others" , &show_others, +N_ ("show other files in the output" )), +OPT_BIT ('i' ,"ignored" , &dir.flags, +N_ ("show ignored files in the output" ), +DIR_SHOW_IGNORED ), +OPT_BOOL ('s' ,"stage" , &show_stage, +N_ ("show staged contents' object name in the output" )), +OPT_BOOL ('k' ,"killed" , &show_killed, +N_ ("show files on the filesystem that need to be removed" )), +OPT_BIT (0 ,"directory" , &dir.flags, +N_ ("show 'other' directories' name only" ), +DIR_SHOW_OTHER_DIRECTORIES ), +OPT_NEGBIT (0 ,"empty-directory" , &dir.flags, +N_ ("don't show empty directories" ), +DIR_HIDE_EMPTY_DIRECTORIES ), +OPT_BOOL ('u' ,"unmerged" , &show_unmerged, +N_ ("show unmerged files in the output" )), +OPT_BOOL (0 ,"resolve-undo" , &show_resolve_undo, +N_ ("show resolve-undo information" )), + {OPTION_CALLBACK ,'x' ,"exclude" , &exclude_list,N_ ("pattern" ), +N_ ("skip files matching pattern" ), +0 , option_parse_exclude }, + {OPTION_CALLBACK ,'X' ,"exclude-from" , &dir,N_ ("file" ), +N_ ("exclude patterns are read from <file>" ), +0 , option_parse_exclude_from }, +OPT_STRING (0 ,"exclude-per-directory" , &dir.exclude_per_dir,N_ ("file" ), +N_ ("read additional per-directory exclude patterns in <file>" )), + {OPTION_CALLBACK ,0 ,"exclude-standard" , &dir,NULL , +N_ ("add the standard git exclusions" ), +PARSE_OPT_NOARG , option_parse_exclude_standard }, + {OPTION_SET_INT ,0 ,"full-name" , &prefix_len,NULL , +N_ ("make the output relative to the project top directory" ), +PARSE_OPT_NOARG |PARSE_OPT_NONEG ,NULL }, +OPT_BOOL (0 ,"error-unmatch" , &error_unmatch, +N_ ("if any <file> is not in the index, treat this as an error" )), +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" )), + {OPTION_INTEGER ,0 ,"max-depth" , &max_depth,N_ ("depth" ), +N_ ("descend at most <depth> levels" ),PARSE_OPT_NONEG , +NULL ,1 }, +OPT__ABBREV (&abbrev), +OPT_BOOL (0 ,"debug" , &debug_mode,N_ ("show debugging data" )), +OPT_END () + }; + +if (argc ==2 && !strcmp (argv[1 ],"-h" )) +usage_with_options (ls_files_usage, builtin_ls_files_options); + + prefix = cmd_prefix; +if (prefix) + prefix_len =strlen (prefix); +git_config (git_default_config,NULL ); + +if (read_cache () <0 ) +die ("index file corrupt" ); + + argc =parse_options (argc, argv, prefix, builtin_ls_files_options, + ls_files_usage,0 ); +return ls_files (argv, prefix); +}
Signature · 1 line
1.9.1.345.ga1a145c
PATCH v2 10/17 Add git-ls, a user friendly version of ls-files and more
In reply to Nguyễn Thái Ngọc DuyThis is more user friendly version of ls-files:
* it's automatically colored and columnized
* it refreshes the index like all porcelain commands
* it defaults to non-recursive behavior like ls
* :(glob) is on by default so '*.c' means a.c but not a/b.c, use '**/*.c' for that.
* auto pager
--- .gitignore | 1 + Documentation/config.txt | 10 ++++++ Documentation/git-ls.txt (new) | 82 ++++++++++++++++++++++++++++++++++++++++++ Makefile | 1 + builtin.h | 1 + builtin/ls-files.c | 70 ++++++++++++++++++++++++++++++++++++ command-list.txt | 1 + git.c | 1 + 8 files changed, 167 insertions(+) create mode 100644 Documentation/git-ls.txt
.gitignore +1 -0
@@ -76,6 +76,7 @@ /git-init-db /git-instaweb /git-log +/git-ls /git-ls-files /git-ls-remote /git-ls-tree
Documentation/config.txt +10 -0
@@ -909,6 +909,12 @@ color.status.<slot>:: to red). The values of these variables may be specified as in color.branch.<slot>. +color.ls:: + A boolean to enable/disable color in the output of + linkgit:git-ls[1]. May be set to `always`, `false` (or + `never`) or `auto` (or `true`), in which case colors are used + only when the output is to a terminal. Defaults to false. + color.ls.<slot>:: Use customized color for file name colorization. If not set and the environment variable LS_COLORS is set, color settings
@@ -981,6 +987,10 @@ column.clean:: Specify the layout when list items in `git clean -i`, which always shows files and directories in columns. See `column.ui` for details. +column.ls:: + Specify whether to output tag listing in `git ls` in columns. + See `column.ui` for details. + column.status:: Specify whether to output untracked files in `git status` in columns. See `column.ui` for details.
Documentation/git-ls.txt new file +82 -0
82 lines not on this page · raw message
Makefile +1 -0
@@ -584,6 +584,7 @@ BUILT_INS += git-cherry-pick$X BUILT_INS += git-format-patch$X BUILT_INS += git-fsck-objects$X BUILT_INS += git-init$X +BUILT_INS += git-ls$X BUILT_INS += git-merge-subtree$X BUILT_INS += git-show$X BUILT_INS += git-stage$X
builtin.h +1 -0
@@ -75,6 +75,7 @@ extern int cmd_index_pack(int argc, const char **argv, const char *prefix);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 (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_tree (int argc,const char **argv,const char *prefix);extern int cmd_ls_remote (int argc,const char **argv,const char *prefix);
builtin/ls-files.c +70 -0
85 lines not on this page · raw message
command-list.txt +1 -0
@@ -64,6 +64,7 @@ git-init mainporcelain common git-instaweb ancillaryinterrogators gitk mainporcelain git-log mainporcelain common +git-ls mainporcelain git-ls-files plumbinginterrogators git-ls-remote plumbinginterrogators git-ls-tree plumbinginterrogators
git.c +1 -0
@@ -381,6 +381,7 @@ static struct cmd_struct commands[] = { { "init", cmd_init_db }, { "init-db", cmd_init_db }, { "log", cmd_log, RUN_SETUP }, + { "ls", cmd_ls, RUN_SETUP }, { "ls-files", cmd_ls_files, RUN_SETUP }, { "ls-remote", cmd_ls_remote, RUN_SETUP_GENTLY }, { "ls-tree", cmd_ls_tree, RUN_SETUP },
Signature · 1 line
1.9.1.345.ga1a145c
Re: [PATCH v2 10/17] Add git-ls, a user friendly version of ls-files and more
Quoted 70 lines · Nguyễn Thái Ngọc Duy
This is more user friendly version of ls-files:
* it's automatically colored and columnized
* it refreshes the index like all porcelain commands
* it defaults to non-recursive behavior like ls
* :(glob) is on by default so '*.c' meansa.cbut nota/b.c, use '**/*.c' for that.
* auto pagerSigned-off-by Nguyễn Thái Ngọc Duy <[email protected]>--- .gitignore | 1 + Documentation/config.txt | 10 ++++++ Documentation/git-ls.txt (new) | 82 ++++++++++++++++++++++++++++++++++++++++++ Makefile | 1 + builtin.h | 1 + builtin/ls-files.c | 70 ++++++++++++++++++++++++++++++++++++ command-list.txt | 1 + git.c | 1 + 8 files changed, 167 insertions(+) create mode 100644 Documentation/git-ls.txt.gitignore +1
-0@@ -76,6 +76,7 @@ /git-init-db /git-instaweb /git-log +/git-ls /git-ls-files /git-ls-remote /git-ls-treeDocumentation/config.txt +10
-0@@ -909,6 +909,12 @@ color.status.<slot>:: to red). The values of these variables may be specified as in color.branch.<slot>. +color.ls:: + A boolean to enable/disable color in the output of + linkgit:git-ls[1]. May be set to `always`, `false` (or + `never`) or `auto` (or `true`), in which case colors are used + only when the output is to a terminal. Defaults to false. + color.ls.<slot>:: Use customized color for file name colorization. If not set and the environment variable LS_COLORS is set, color settings@@ -981,6 +987,10 @@ column.clean:: Specify the layout when list items in `git clean -i`, which always shows files and directories in columns. See `column.ui` for details. +column.ls:: + Specify whether to output tag listing in `git ls` in columns. + See `column.ui` for details. + column.status:: Specify whether to output untracked files in `git status` in columns. See `column.ui` for details.Documentation/git-ls.txt new file +2
-0@@ -0,0 +1,82 @@ +git-ls(1) +===============
Documentation/git-ls.txt line 12
Quoted 10 lines
Documentation/git-ls.txt new file +10
-0+ +NAME +---- +git-ls - List files + +SYNOPSIS +-------- +[verse] +'git ls' (--[cached|deleted|others|ignored|unmerged|modified])* + (-[c|d|o|i|s|u|m])*
Don't you have [...] and (...) transposed? The way it's written, "-" and "--" are valid optional arguments. You probably meant:
[--(cached|deleted|x|y|z)]...
[-(c|d|x|y|z)]...Documentation/git-ls.txt line 13
Quoted 1 line
Documentation/git-ls.txt new file +1
-0+ [options] [<pathspec>...]
However, you also have the generic [options] here, which covers all of the above. It probably would make sense to just use [options] and drop the enumerated list.
Documentation/git-ls.txt line 25
Quoted 11 lines
Documentation/git-ls.txt new file +11
-0+DESCRIPTION +----------- +List files (by default in current working directory) that are in the +index. Depending on the chosen options, maybe only modified files in +working tree are shown, or untracked files... + +OPTIONS +------- +-c:: +--cached:: + Show cached files in the output (default)
"in the output" is superfluous. Perhaps drop it from each of the descriptions.
Documentation/git-ls.txt line 29
Quoted 3 lines
Documentation/git-ls.txt new file +3
-0+-d:: +--deleted:: + Show deleted files in the output
Is this showing only deleted file or including them in the list of files otherwise displayed? It's not clear from the description. Same question for the other options.
Quoted 8 lines
Documentation/git-ls.txt new file +8
-0+-m:: +--modified:: + Show modified files in the output + +-o:: +--others:: + Show other (i.e. untracked) files in the output +
Documentation/git-ls.txt line 48
Quoted 10 lines
Documentation/git-ls.txt new file +10
-0+-i:: +--ignored:: + Show only ignored files in the output. When showing files in the + index, print only those matched by an exclude pattern. When + showing "other" files, show only those matched by an exclude + pattern. + +-u:: +--unmerged:: + Show unmerged files in the output (forces --stage)
This is the only mention of --stage in this document. Not sure what it's trying to say.
Documentation/git-ls.txt line 52
Quoted 3 lines
Documentation/git-ls.txt new file +3
-0+--color[=<when>]:: + Color file names. The value must be always (default), never, + or auto.
Same problem mentioned in the other patch. Default is "always"...
Documentation/git-ls.txt line 57
Quoted 5 lines
Documentation/git-ls.txt new file +5
-0+ +--no-color:: + Turn off coloring, even when the configuration file gives the + default to color output, same as `--color=never`. This is the + default.
But default is also "never".
Documentation/git-ls.txt line 62
Quoted 5 lines
Documentation/git-ls.txt new file +5
-0+ +--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.
More below.
Quoted 83 lines
Documentation/git-ls.txt new file +20
-0+ are equivalent to 'always' and 'never' respectively. + +--max-depth <depth>:: + For each <pathspec> given on command line, descend at most <depth> + levels of directories. A negative value means no limit. + This option is ignored if <pathspec> contains active wildcards. + In other words if "a*" matches a directory named "a*", + "*" is matched literally so --max-depth is still effective. + +<pathspec>:: + Files to show. :(glob) magic is enabled and recursion disabled + by default. + +SEE ALSO +-------- +linkgit:git-ls-files[1] + +GIT +--- +Part of the linkgit:git[1] suiteMakefile +1
-0@@ -584,6 +584,7 @@ BUILT_INS += git-cherry-pick$X BUILT_INS += git-format-patch$X BUILT_INS += git-fsck-objects$X BUILT_INS += git-init$X +BUILT_INS += git-ls$X BUILT_INS += git-merge-subtree$X BUILT_INS += git-show$X BUILT_INS += git-stage$Xbuiltin.h +1
-0@@ -75,6 +75,7 @@ extern int cmd_index_pack(int argc, const char **argv, const char *prefix);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 (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_tree (int argc,const char **argv,const char *prefix);extern int cmd_ls_remote (int argc,const char **argv,const char *prefix);builtin/ls-files.c +17
-0@@ -33,6 +33,7 @@ static int use_color;static unsigned int colopts;static int max_depth =-1 ;static int show_tag; +static int porcelain;static const char *prefix;static int max_prefix_len;@@ -588,6 +589,10 @@ static int ls_files(const char **argv, const char *prefix)die ("ls-files --with-tree is incompatible with -s or -u" );overlay_tree_on_cache (with_tree, max_prefix); } +if (porcelain) { +refresh_index (&the_index,REFRESH_QUIET , &pathspec,NULL ,NULL ); +setup_pager (); + }show_files (&dir);if (show_resolve_undo)show_ru_info ();@@ -687,3 +692,68 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) ls_files_usage, 0);return ls_files (argv, prefix); } + +static const char *const ls_usage[] = { +N_ ("git ls [options] [<file>...]" ), +NULL +}; + +static int git_ls_config (const char *var,const char *value,void *cb) +{ +if (starts_with (var,"column." )) +return git_column_config (var, value,"ls" , &colopts); +if (!strcmp (var,"color.ls" )) { + use_color =git_config_colorbool (var, value);
builtin/ls-files.c int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) · line 716
Quoted 10 lines
builtin/ls-files.c +10
-0+return 0 ; + } +return git_color_default_config (var, value, cb); +} + +int cmd_ls (int argc,const char **argv,const char *cmd_prefix) +{ +struct option builtin_ls_options[] = { +OPT_BOOL ('c' ,"cached" , &show_cached, +N_ ("show cached files in the output (default)" )),
Ditto regarding the unnecessary and repetitive "in the output".
Quoted 69 lines
builtin/ls-files.c +43
-0+OPT_BOOL ('d' ,"deleted" , &show_deleted, +N_ ("show deleted files in the output" )), +OPT_BOOL ('m' ,"modified" , &show_modified, +N_ ("show modified files in the output" )), +OPT_BOOL ('o' ,"others" , &show_others, +N_ ("show other files in the output" )), +OPT_BIT ('i' ,"ignored" , &dir.flags, +N_ ("show ignored files in the output" ), +DIR_SHOW_IGNORED ), +OPT_BOOL ('u' ,"unmerged" , &show_unmerged, +N_ ("show unmerged files in the output" )), +OPT__COLOR (&use_color,N_ ("show color" )), +OPT_COLUMN (0 ,"column" , &colopts,N_ ("show files in columns" )), + { OPTION_INTEGER, 0, "max-depth", &max_depth, N_("depth"), +N_ ("descend at most <depth> levels" ),PARSE_OPT_NONEG , + NULL, 1 }, +OPT__ABBREV (&abbrev), +OPT_END () + }; + +if (argc ==2 && !strcmp (argv[1 ],"-h" )) +usage_with_options (ls_usage, builtin_ls_options); + + prefix = cmd_prefix; +if (prefix) + prefix_len =strlen (prefix); +git_config (git_ls_config,NULL ); + +if (read_cache () <0 ) +die ("index file corrupt" ); + +/* default setup */ + porcelain =1 ; +setenv (GIT_GLOB_PATHSPECS_ENVIRONMENT ,"1" ,1 ); + exc_given =1 ; +setup_standard_excludes (&dir); + use_color =-1 ; + max_depth =0 ; + + argc =parse_options (argc, argv, prefix, builtin_ls_options, + ls_usage,0 ); +return ls_files (argv, prefix); +}command-list.txt +1
-0@@ -64,6 +64,7 @@ git-init mainporcelain common git-instaweb ancillaryinterrogators gitk mainporcelain git-log mainporcelain common +git-ls mainporcelain git-ls-files plumbinginterrogators git-ls-remote plumbinginterrogators git-ls-tree plumbinginterrogatorsgit.c +1
-1@@ -381,6 +381,7 @@ static struct cmd_struct commands[] = { { "init", cmd_init_db }, { "init-db", cmd_init_db }, { "log", cmd_log, RUN_SETUP }, + { "ls", cmd_ls, RUN_SETUP }, { "ls-files", cmd_ls_files, RUN_SETUP }, { "ls-remote", cmd_ls_remote, RUN_SETUP_GENTLY }, { "ls-tree", cmd_ls_tree, RUN_SETUP }, --1.9.1.345.ga1a145c
PATCH v2 11/17 ls: -u does not imply showing stages
In reply to Nguyễn Thái Ngọc DuyShowing full index entry information is something for ls-files only. The users of "git ls" may just want to know what entries are not unmerged.
--- builtin/ls-files.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/ls-files.c +1 -1
@@ -527,7 +527,7 @@ static int ls_files(const char **argv, const char *prefix) }if (show_modified || show_others || show_deleted || (dir.flags &DIR_SHOW_IGNORED ) || show_killed) require_work_tree =1 ; -if (show_unmerged) +if (show_unmerged && !porcelain)/* * There's no point in showing unmerged unless * you also show the stage information.
Signature · 1 line
1.9.1.345.ga1a145c
PATCH v2 12/17 ls: add -R/--recursive short for --max-depth=-1
In reply to Nguyễn Thái Ngọc Duy--- Documentation/git-ls.txt | 4 ++++ builtin/ls-files.c | 2 ++ 2 files changed, 6 insertions(+)
Documentation/git-ls.txt +4 -0
@@ -47,6 +47,10 @@ OPTIONS --unmerged:: Show unmerged files in the output (forces --stage) +-R:: +--recursive:: + Equivalent of --max-depth=-1 (infinite recursion). + --color[=<when>]:: Color file names. The value must be always (default), never, or auto.
builtin/ls-files.c +2 -0
@@ -725,6 +725,8 @@ int cmd_ls(int argc, const char **argv, const char *cmd_prefix) DIR_SHOW_IGNORED),OPT_BOOL ('u' ,"unmerged" , &show_unmerged,N_ ("show unmerged files in the output" )), +OPT_SET_INT ('R' ,"recursive" , &max_depth, +N_ ("shortcut for --max-depth=-1" ),-1 ),OPT__COLOR (&use_color,N_ ("show color" )),OPT_COLUMN (0 ,"column" , &colopts,N_ ("show files in columns" )), { OPTION_INTEGER, 0, "max-depth", &max_depth, N_("depth"),
Signature · 1 line
1.9.1.345.ga1a145c
PATCH v2 13/17 ls: add -1 short for --no-column in the spirit of GNU ls
In reply to Nguyễn Thái Ngọc Duy--- Documentation/git-ls.txt | 3 +++ builtin/ls-files.c | 2 ++ 2 files changed, 5 insertions(+)
Documentation/git-ls.txt +3 -0
@@ -51,6 +51,9 @@ OPTIONS --recursive:: Equivalent of --max-depth=-1 (infinite recursion). +-1:: + Equivalent of --no-column. + --color[=<when>]:: Color file names. The value must be always (default), never, or auto.
builtin/ls-files.c +2 -0
@@ -729,6 +729,8 @@ int cmd_ls(int argc, const char **argv, const char *cmd_prefix) N_("shortcut for --max-depth=-1"), -1),OPT__COLOR (&use_color,N_ ("show color" )),OPT_COLUMN (0 ,"column" , &colopts,N_ ("show files in columns" )), +OPT_SET_INT ('1' ,NULL , &colopts, +N_ ("shortcut for --no-column" ),COL_PARSEOPT ), { OPTION_INTEGER, 0, "max-depth", &max_depth, N_("depth"),N_ ("descend at most <depth> levels" ),PARSE_OPT_NONEG , NULL, 1 },
Signature · 1 line
1.9.1.345.ga1a145c
Re: [PATCH v2 13/17] ls: add -1 short for --no-column in the spirit of GNU ls
Quoted 1 line · Nguyễn Thái Ngọc Duy
Subject: ls: add -1 short for --no-column in the spirit of GNU ls
The -1 option is POSIX [1]; not a GNU extension.
[1]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ls.html
Quoted 35 lines
Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>--- Documentation/git-ls.txt | 3 +++ builtin/ls-files.c | 2 ++ 2 files changed, 5 insertions(+)Documentation/git-ls.txt +3
-0@@ -51,6 +51,9 @@ OPTIONS --recursive:: Equivalent of --max-depth=-1 (infinite recursion). +-1:: + Equivalent of --no-column. + --color[=<when>]:: Color file names. The value must be always (default), never, or auto.builtin/ls-files.c +2
-1@@ -729,6 +729,8 @@ int cmd_ls(int argc, const char **argv, const char *cmd_prefix) N_("shortcut for --max-depth=-1"), -1),OPT__COLOR (&use_color,N_ ("show color" )),OPT_COLUMN (0 ,"column" , &colopts,N_ ("show files in columns" )), +OPT_SET_INT ('1' ,NULL , &colopts, +N_ ("shortcut for --no-column" ),COL_PARSEOPT ), { OPTION_INTEGER, 0, "max-depth", &max_depth, N_("depth"),N_ ("descend at most <depth> levels" ),PARSE_OPT_NONEG , NULL, 1 }, --1.9.1.345.ga1a145c
PATCH v2 14/17 ls: add -t back
In reply to Nguyễn Thái Ngọc DuyTag "H" (cached) is not shown though because it's usually the majority and becomes noise. Not showing it makes the other tags stand out. -t is on by default if more than one file category is selected.
--- Documentation/git-ls.txt | 6 ++++++ builtin/ls-files.c | 27 +++++++++++++++++---------- 2 files changed, 23 insertions(+), 10 deletions(-)
Documentation/git-ls.txt +6 -0
@@ -47,6 +47,12 @@ OPTIONS --unmerged:: Show unmerged files in the output (forces --stage) +-t:: +--tag:: + Show a tag to indicate file type, helpful when multiple file + selections are used. See linkgit::git-ls-files[1] option `-t` + for more information. + -R:: --recursive:: Equivalent of --max-depth=-1 (infinite recursion).
builtin/ls-files.c +17 -10
@@ -515,16 +515,6 @@ static int ls_files(const char **argv, const char *prefix)for (i =0 ; i < exclude_list.nr; i++) {add_exclude (exclude_list.items[i].string,"" ,0 , el, --exclude_args); } -if (show_tag || show_valid_bit) { - tag_cached ="H " ; - tag_unmerged ="M " ; - tag_removed ="R " ; - tag_modified ="C " ; - tag_other ="? " ; - tag_killed ="K " ; - tag_skip_worktree ="S " ; - tag_resolve_undo ="U " ; - }if (show_modified || show_others || show_deleted || (dir.flags &DIR_SHOW_IGNORED ) || show_killed) require_work_tree =1 ;if (show_unmerged && !porcelain)
@@ -578,6 +568,20 @@ static int ls_files(const char **argv, const char *prefix) show_killed || show_modified || show_resolve_undo)) show_cached =1 ; +if (show_tag ==-1 ) + show_tag = (show_cached + show_deleted + show_others + + show_unmerged + show_killed + show_modified) >1 ; +if (show_tag || show_valid_bit) { + tag_cached = porcelain ?" " :"H " ; + tag_unmerged ="M " ; + tag_removed ="R " ; + tag_modified ="C " ; + tag_other ="? " ; + tag_killed ="K " ; + tag_skip_worktree ="S " ; + tag_resolve_undo ="U " ; + } +if (max_prefix)prune_cache (max_prefix);if (with_tree) {
@@ -727,6 +731,8 @@ int cmd_ls(int argc, const char **argv, const char *cmd_prefix) N_("show unmerged files in the output")),OPT_SET_INT ('R' ,"recursive" , &max_depth,N_ ("shortcut for --max-depth=-1" ),-1 ), +OPT_BOOL ('t' ,"tag" , &show_tag, +N_ ("identify the file status with tags" )),OPT__COLOR (&use_color,N_ ("show color" )),OPT_COLUMN (0 ,"column" , &colopts,N_ ("show files in columns" )), OPT_SET_INT('1', NULL, &colopts,
@@ -756,6 +762,7 @@ int cmd_ls(int argc, const char **argv, const char *cmd_prefix)setup_standard_excludes (&dir); use_color =-1 ; max_depth =0 ; + show_tag =-1 ; argc =parse_options (argc, argv, prefix, builtin_ls_options, ls_usage,0 );
Signature · 1 line
1.9.1.345.ga1a145c
PATCH v2 15/17 ls: sort output and remove duplicates
In reply to Nguyễn Thái Ngọc DuyWhen you mix different file types, with ls-files you may get separate listing. For example, "ls-files -cm" will show file "abc" twice: one as part of cached list, one of modified list. With "ls" (and this patch) they will be in a single sorted list (easier for the eye).
Duplicate entries are also removed. Note that display content is compared, so if you have "-t" on, or you color file types differently, you will get duplicate textual entries. This is good imo.
--- builtin/ls-files.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-)
builtin/ls-files.c +21 -9
@@ -57,6 +57,13 @@ static const char *tag_modified = "";static const char *tag_skip_worktree ="" ;static const char *tag_resolve_undo ="" ; +static int compare_output (const void *a_,const void *b_) +{ +const struct string_list_item *a = a_; +const struct string_list_item *b = b_; +return strcmp (a->util, b->util); +} +static void write_name (struct strbuf *sb,const char *name) {/*
@@ -72,10 +79,12 @@ static void write_name(struct strbuf *sb, const char *name)quote_path_relative (name, real_prefix, sb); } -static void strbuf_fputs (struct strbuf *sb,FILE *fp) +static void strbuf_fputs (struct strbuf *sb,const char *full_name,FILE *fp) { -if (column_active (colopts)) { -string_list_append (&output,strbuf_detach (sb,NULL )); +if (column_active (colopts) || porcelain) { +struct string_list_item *it; + it =string_list_append (&output,strbuf_detach (sb,NULL )); + it->util = (void *)full_name;return ; }fwrite (sb->buf, sb->len,1 , fp);
@@ -110,7 +119,7 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent)strbuf_reset (&sb);strbuf_addstr (&sb, tag);write_dir_entry (&sb, ent); -strbuf_fputs (&sb, stdout); +strbuf_fputs (&sb, ent->name, stdout); }static void show_other_files (struct dir_struct *dir)
@@ -227,7 +236,7 @@ static void show_ce_entry(const char *tag, const struct cache_entry *ce) ce_stage(ce)); }write_ce_name (&sb, ce); -strbuf_fputs (&sb, stdout); +strbuf_fputs (&sb, ce->name, stdout);if (debug_mode) {const struct stat_data *sd = &ce->ce_stat_data;
@@ -535,7 +544,7 @@ static int ls_files(const char **argv, const char *prefix)if (debug_mode)die (_ ("--column and --debug are incompatible" )); } -if (column_active (colopts)) +if (column_active (colopts) || porcelain) line_terminator =0 ;if (require_work_tree && !is_inside_work_tree ())
@@ -601,10 +610,13 @@ static int ls_files(const char **argv, const char *prefix)if (show_resolve_undo)show_ru_info (); -if (column_active (colopts)) { -print_columns (&output, colopts,NULL ); -string_list_clear (&output,0 ); +if (porcelain) { +qsort (output.items, output.nr,sizeof (*output.items), + compare_output); +string_list_remove_duplicates (&output,0 ); } +print_columns (&output, colopts,NULL ); +string_list_clear (&output,0 );if (ps_matched) {int bad;
Signature · 1 line
1.9.1.345.ga1a145c
PATCH v2 16/17 ls: do not show duplicate cached entries
In reply to Nguyễn Thái Ngọc DuyWith the current show_files() "ls -tcm" will show
foo.c
M foo.c
The first item is redundant. If "foo.c" is modified, we know it's in the cache. Introduce show_files_compact to do that because ls-files is plumbing and scripts may already depend on current display behavior.
Another difference in show_files_compact() is it does not show skip-worktree (aka outside sparse checkout) entries anymore, which makes sense in porcelain context.
--- builtin/ls-files.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-)
builtin/ls-files.c +51 -1
@@ -337,6 +337,53 @@ static void show_files(struct dir_struct *dir) } } +static void show_files_compact (struct dir_struct *dir) +{ +int i; + +/* For cached/deleted files we don't need to even do the readdir */ +if (show_others || show_killed) { +if (!show_others) + dir->flags |=DIR_COLLECT_KILLED_ONLY ; +fill_directory (dir, &pathspec); +if (show_others) +show_other_files (dir); +if (show_killed) +show_killed_files (dir); + } +if (!(show_cached || show_stage || show_deleted || show_modified)) +return ; +for (i =0 ; i < active_nr; i++) { +const struct cache_entry *ce = active_cache[i]; +struct stat st; +int err, shown =0 ; +if ((dir->flags &DIR_SHOW_IGNORED ) && + !ce_excluded (dir, ce)) +continue ; +if (show_unmerged && !ce_stage (ce)) +continue ; +if (ce->ce_flags &CE_UPDATE ) +continue ; +if (ce_skip_worktree (ce)) +continue ; + err =lstat (ce->name, &st); +if (show_deleted && err) { +show_ce_entry (tag_removed, ce); + shown =1 ; + } +if (show_modified &&ce_modified (ce, &st,0 )) { +show_ce_entry (tag_modified, ce); + shown =1 ; + } +if (ce_stage (ce)) { +show_ce_entry (tag_unmerged, ce); + shown =1 ; + } +if (!shown && show_cached) +show_ce_entry (tag_cached, ce); + } +} +/* * Prune the index to only contain stuff starting with "prefix" */
@@ -606,7 +653,10 @@ static int ls_files(const char **argv, const char *prefix)refresh_index (&the_index,REFRESH_QUIET , &pathspec,NULL ,NULL );setup_pager (); } -show_files (&dir); +if (porcelain) +show_files_compact (&dir); +else +show_files (&dir);if (show_resolve_undo)show_ru_info ();
Signature · 1 line
1.9.1.345.ga1a145c
Re: [PATCH v2 16/17] ls: do not show duplicate cached entries
Quoted 51 lines · Nguyễn Thái Ngọc Duy
With the current
show_files()"ls -tcm" will show
foo.c
Mfoo.cThe first item is redundant. If "
foo.c" is modified, we know it's in the cache. Introduceshow_files_compactto do that because ls-files is plumbing and scripts may already depend on current display behavior.Another difference in
show_files_compact()is it does not show skip-worktree (aka outside sparse checkout) entries anymore, which makes sense in porcelain context.Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>--- builtin/ls-files.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-)builtin/ls-files.c +25
-0@@ -337,6 +337,53 @@ static void show_files(struct dir_struct *dir) } } +static void show_files_compact (struct dir_struct *dir) +{ +int i; + +/* For cached/deleted files we don't need to even do the readdir */ +if (show_others || show_killed) { +if (!show_others) + dir->flags |=DIR_COLLECT_KILLED_ONLY ; +fill_directory (dir, &pathspec); +if (show_others) +show_other_files (dir); +if (show_killed) +show_killed_files (dir); + } +if (!(show_cached || show_stage || show_deleted || show_modified)) +return ; +for (i =0 ; i < active_nr; i++) { +const struct cache_entry *ce = active_cache[i]; +struct stat st; +int err, shown =0 ; +if ((dir->flags &DIR_SHOW_IGNORED ) && + !ce_excluded (dir, ce)) +continue ; +if (show_unmerged && !ce_stage (ce)) +continue ;
builtin/ls-files.c static void show_files(struct dir_struct *dir) · line 374
Quoted 10 lines
builtin/ls-files.c +10
-0+if (ce->ce_flags &CE_UPDATE ) +continue ; +if (ce_skip_worktree (ce)) +continue ; + err =lstat (ce->name, &st); +if (show_deleted && err) { +show_ce_entry (tag_removed, ce); + shown =1 ; + } +if (show_modified &&ce_modified (ce, &st,0 )) {
Is it possible for the lstat() to have failed for some reason when we get here? If so, relying upon 'st' is unsafe, isn't it?
Quoted 34 lines
builtin/ls-files.c +16
-2+show_ce_entry (tag_modified, ce); + shown =1 ; + } +if (ce_stage (ce)) { +show_ce_entry (tag_unmerged, ce); + shown =1 ; + } +if (!shown && show_cached) +show_ce_entry (tag_cached, ce); + } +} +/* * Prune the index to only contain stuff starting with "prefix" */ @@ -606,7 +653,10 @@ static int ls_files(const char **argv, const char *prefix)refresh_index (&the_index,REFRESH_QUIET , &pathspec,NULL ,NULL );setup_pager (); } -show_files (&dir); +if (porcelain) +show_files_compact (&dir); +else +show_files (&dir);if (show_resolve_undo)show_ru_info (); --1.9.1.345.ga1a145c
--
To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 1/1 ls-files: do not trust stat info if lstat() fails
If 'err' is non-zero, lstat() has failed. Consider the entry modified without passing the (unreliable) stat info to ce_modified() in this case.
---
Quoted 10 lines · Eric Sunshine
Quoted 6 lines · Nguyễn Thái Ngọc Duy
+ err =
lstat(ce->name, &st);
+ if (show_deleted&& err) {
+show_ce_entry(tag_removed, ce);
+ shown = 1;
+ }
+ if (show_modified&&ce_modified(ce, &st, 0)) {Is it possible for the
lstat()to have failed for some reason when we get here? If so, relying upon 'st' is unsafe, isn't it?
The chance of random stat making ce_modified() return false is pretty low, but you're right. This code is a copy from the old show_files(). I'll fix it in the git-ls series. Meanwhile a patch for maint to fix the original function.
builtin/ls-files.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/ls-files.c +1 -1
@@ -260,7 +260,7 @@ static void show_files(struct dir_struct *dir) err =lstat (ce->name, &st);if (show_deleted && err)show_ce_entry (tag_removed, ce); -if (show_modified &&ce_modified (ce, &st,0 )) +if (show_modified && (err ||ce_modified (ce, &st,0 )))show_ce_entry (tag_modified, ce); } }
Signature · 1 line
1.9.1.345.ga1a145c
Re: [PATCH] ls-files: do not trust stat info if lstat() fails
Quoted 32 lines · Nguyễn Thái Ngọc Duy
If 'err' is non-zero,
lstat()has failed. Consider the entry modified without passing the (unreliable) stat info toce_modified()in this case.Noticed-by Eric Sunshine <[email protected]>Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>---
Quoted 10 lines · Eric Sunshine
Quoted 6 lines · Nguyễn Thái Ngọc Duy
+ err =
lstat(ce->name, &st);
+ if (show_deleted&& err) {
+show_ce_entry(tag_removed, ce);
+ shown = 1;
+ }
+ if (show_modified&&ce_modified(ce, &st, 0)) {Is it possible for the
lstat()to have failed for some reason when we get here? If so, relying upon 'st' is unsafe, isn't it?The chance of random stat making
ce_modified()return false is pretty low, but you're right. This code is a copy from the oldshow_files(). I'll fix it in the git-ls series. Meanwhile a patch for maint to fix the original function.builtin/ls-files.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)builtin/ls-files.c +0
-0
builtin/ls-files.c static void show_files(struct dir_struct *dir) · line 266
Quoted 8 lines
builtin/ls-files.c +1
-1@@ -260,7 +260,7 @@ static void show_files(struct dir_struct *dir) err =lstat (ce->name, &st);if (show_deleted && err)show_ce_entry (tag_removed, ce); -if (show_modified &&ce_modified (ce, &st,0 )) +if (show_modified && (err ||ce_modified (ce, &st,0 )))show_ce_entry (tag_modified, ce); } }
I am guessing that, even though this was discovered during the development of list-files, is a fix applicable outside the context of that series.
I do think the patched result is an improvement than the status quo, but at the same time, I find it insufficient in the context of the whole codepath. What if errno were other than ENOENT and we were told to show_deleted (with or without show_modified)? We would end up saying the path was deleted and modified at the same time, when we do not know either is or is not true at all, because of the failure to lstat() the path.
Wouldn't it be saner to add tag_unknown and do something like this instead, I wonder?
builtin/ls-files.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
builtin/ls-files.c +11 -5
@@ -46,6 +46,7 @@ static const char *tag_killed = "";static const char *tag_modified ="" ;static const char *tag_skip_worktree ="" ;static const char *tag_resolve_undo ="" ; +static const char *tag_unknown ="" ;static void write_name (const char *name) {
@@ -249,7 +250,7 @@ static void show_files(struct dir_struct *dir)for (i =0 ; i < active_nr; i++) {const struct cache_entry *ce = active_cache[i];struct stat st; -int err; +if ((dir->flags &DIR_SHOW_IGNORED ) && !ce_excluded (dir, ce))continue ;
@@ -257,11 +258,15 @@ static void show_files(struct dir_struct *dir)continue ;if (ce_skip_worktree (ce))continue ; - err =lstat (ce->name, &st); -if (show_deleted && err) -show_ce_entry (tag_removed, ce); -if (show_modified &&ce_modified (ce, &st,0 )) + errno =0 ; +if (lstat (ce->name, &st)) { +if (errno !=ENOENT && errno !=ENOTDIR ) +show_ce_entry (tag_unknown, ce); +else if (show_deleted) +show_ce_entry (tag_removed, ce); + }else if (show_modified &&ce_modified (ce, &st,0 )) {show_ce_entry (tag_modified, ce); + } } } }
@@ -533,6 +538,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) tag_killed ="K " ; tag_skip_worktree ="S " ; tag_resolve_undo ="U " ; + tag_unknown ="! " ; }if (show_modified || show_others || show_deleted || (dir.flags &DIR_SHOW_IGNORED ) || show_killed) require_work_tree =1 ;
Re: [PATCH] ls-files: do not trust stat info if lstat() fails
Quoted 12 lines · Junio C Hamano
I am guessing that, even though this was discovered during the development of list-files, is a fix applicable outside the context of that series.
I do think the patched result is an improvement than the status quo, but at the same time, I find it insufficient in the context of the whole codepath. What if errno were other than ENOENT and we were told to
show_deleted(with or withoutshow_modified)? We would end up saying the path was deleted and modified at the same time, when we do not know either is or is not true at all, because of the failure tolstat()the path.
Quoted 2 lines
Wouldn't it be saner to add
tag_unknownand do something like this instead, I wonder?
Or even better to show an error message when the error code is unexpected? The unkown tag '!' says "there are problems" but if it shows up sort of permanently, '!' won't help much, I think.
Signature · 1 line
Duy
Re: [PATCH] ls-files: do not trust stat info if lstat() fails
Quoted 13 lines · Duy Nguyen
Quoted 12 lines · Junio C Hamano
I am guessing that, even though this was discovered during the development of list-files, is a fix applicable outside the context of that series.
I do think the patched result is an improvement than the status quo, but at the same time, I find it insufficient in the context of the whole codepath. What if errno were other than ENOENT and we were told to
show_deleted(with or withoutshow_modified)? We would end up saying the path was deleted and modified at the same time, when we do not know either is or is not true at all, because of the failure tolstat()the path.
Quoted 6 lines
Quoted 2 lines
Wouldn't it be saner to add
tag_unknownand do something like this instead, I wonder?Or even better to show an error message when the error code is unexpected? The unkown tag '!' says "there are problems" but if it shows up sort of permanently, '!' won't help much, I think.
I am OK with that approach, but then one question remains: should we say it is deleted, modified, both, or neither?
Re: [PATCH] ls-files: do not trust stat info if lstat() fails
Quoted 18 lines · Junio C Hamano
Quoted 16 lines · Duy Nguyen
Quoted 14 lines · Junio C Hamano
I am guessing that, even though this was discovered during the development of list-files, is a fix applicable outside the context of that series.
I do think the patched result is an improvement than the status quo, but at the same time, I find it insufficient in the context of the whole codepath. What if errno were other than ENOENT and we were told to
show_deleted(with or withoutshow_modified)? We would end up saying the path was deleted and modified at the same time, when we do not know either is or is not true at all, because of the failure tolstat()the path.Wouldn't it be saner to add
tag_unknownand do something like this instead, I wonder?
Quoted 6 lines
Quoted 3 lines
Or even better to show an error message when the error code is unexpected? The unkown tag '!' says "there are problems" but if it shows up sort of permanently, '!' won't help much, I think.
I am OK with that approach, but then one question remains: should we say it is deleted, modified, both, or neither?
The question is moot if the user does not ignore stderr because they should just ignore those error-reported entries. If they do 2>/dev/null, I think we should err on the safe side and say modified. We only say deleted if lstat() returns ENOENT or ENOTDIR like in your patch.
Signature · 1 line
Duy
Re: [PATCH] ls-files: do not trust stat info if lstat() fails
Quoted 4 lines · Duy Nguyen
Quoted 4 lines
Quoted 3 lines
Or even better to show an error message when the error code is unexpected? The unkown tag '!' says "there are problems" but if it shows up sort of permanently, '!' won't help much, I think.
Quoted 8 lines
Quoted 2 lines
I am OK with that approach, but then one question remains: should we say it is deleted, modified, both, or neither?
The question is moot if the user does not ignore stderr because they should just ignore those error-reported entries. If they do 2>/dev/null, I think we should err on the safe side and say modified. We only say deleted if
lstat()returns ENOENT or ENOTDIR like in your patch.
Doesn't the same reasoning behind "when we do not know for sure that a path is not modified, it would be safe if we said the path may be modified" also tell us that it is safer to say a path may be lost if we cannot tell?
One likely case where we cannot tell if it is modified would be when we cannot read the path (perhaps the parent directory accidentally lost its x-bit). Saying "it may be modified" would be one way to have the user take notice, for an interactive user. A script that runs ls-files may be using the paths to drive "git add", "tar cf -", etc. and emitting such an unreadable path is one way to make these downstream commands signal that something fishy is going on by erroring out.
So, I am not sure if we should be silent on an unexpected error when we are asked to report deletes when we would be vocal when we are asked to report modifications.
PATCH v2 17/17 ls: show directories as well as files
In reply to Nguyễn Thái Ngọc DuyThe index does not store directories explicitly (except submodules) so we have to figure them out from file list. The function show_directories() deliberately generates duplicate directories and expects the previous patch to remove duplicates.
--- builtin/ls-files.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
builtin/ls-files.c +41 -0
@@ -27,6 +27,7 @@ static int show_resolve_undo;static int show_modified;static int show_killed;static int show_valid_bit; +static int show_dirs;static int line_terminator ='\n' ;static int debug_mode;static int use_color;
@@ -337,6 +338,43 @@ static void show_files(struct dir_struct *dir) } } +static void show_directories (const struct cache_entry *ce) +{ +static const char *last_directory; +struct strbuf sb =STRBUF_INIT ; +const char *p = ce->name + prefix_len; +const char *sep; + +if (last_directory) { +int len =strlen (last_directory); +if (!strncmp (ce->name, last_directory, len) && + ce->name[len] =='/' ) + p += len +1 ; + } + +while (*p && (sep =strchr (p,'/' ))) { +struct strbuf sb2 =STRBUF_INIT ; +strbuf_reset (&sb); +strbuf_add (&sb, ce->name, sep - ce->name); + p = sep +1 ; +if (!match_pathspec (&pathspec, sb.buf, sb.len, + prefix_len,NULL ,1 )) +continue ; +write_name (&sb2, sb.buf); +if (want_color (use_color)) { +struct strbuf sb3 =STRBUF_INIT ; +color_filename (&sb3, ce->name, sb2.buf,S_IFDIR ,1 ); +strbuf_release (&sb2); + sb2 = sb3; + } +if (show_tag) +strbuf_insert (&sb2,0 , tag_cached,strlen (tag_cached)); + last_directory =strbuf_detach (&sb,NULL ); +strbuf_fputs (&sb2, last_directory,NULL ); +strbuf_release (&sb2); + } +} +static void show_files_compact (struct dir_struct *dir) {int i;
@@ -357,6 +395,8 @@ static void show_files_compact(struct dir_struct *dir)const struct cache_entry *ce = active_cache[i];struct stat st;int err, shown =0 ; +if (show_dirs) +show_directories (ce);if ((dir->flags &DIR_SHOW_IGNORED ) && !ce_excluded (dir, ce))continue ;
@@ -825,6 +865,7 @@ int cmd_ls(int argc, const char **argv, const char *cmd_prefix) use_color =-1 ; max_depth =0 ; show_tag =-1 ; + show_dirs =1 ; argc =parse_options (argc, argv, prefix, builtin_ls_options, ls_usage,0 );
Signature · 1 line
1.9.1.345.ga1a145c
v3 cover git-ls
In reply to Nguyễn Thái Ngọc DuyAll comments by Eric are fixed in v3. -F is added. And the command name is now list-files, not ls. 'ls' is saved for the user to make an alias with better default options.
Nguyễn Thái Ngọc Duy (18):
ls_colors.c: add $LS_COLORS parsing code
ls_colors.c: parse color.ls.* from config file ls_colors.c: add a function to color a file name ls_colors.c: highlight submodules like directories
ls-files: buffer full item in strbuf before printing
ls-files: add --color to highlight file names
ls-files: add --column
ls-files: support --max-depth
Add git-list-files, a user friendly version of ls-files and more
list-files: -u does not imply showing stages
list-files: add -R/--recursive short for --max-depth=-1
list-files: add -1 short for --no-column
list-files: add -t back
list-files: sort output and remove duplicates
list-files: do not show duplicate cached entries
list-files: show directories as well as files
list-files: add -F/--classify
list-files -F: show submodules with the new indicator '&'
.gitignore | 1 + Documentation/config.txt | 22 ++ Documentation/git-list-files.txt (new) | 99 +++++++ Documentation/git-ls-files.txt | 20 ++ Makefile | 2 + builtin/ls-files.c | 358 ++++++++++++++++++++++-- color.h | 10 + command-list.txt | 1 + git.c | 1 + ls_colors.c (new) | 496 +++++++++++++++++++++++++++++++++ 10 files changed, 980 insertions(+), 30 deletions(-) create mode 100644 Documentation/git-list-files.txt create mode 100644 ls_colors.c
Signature · 1 line
1.9.1.345.ga1a145c
PATCH v3 1/18 ls_colors.c: add $LS_COLORS parsing code
Reusing color settings from $LS_COLORS could give a native look and feel on file coloring.
This code is basically from coreutils.git [1], rewritten to fit Git.
As this is from GNU ls, the environment variable CLICOLOR is not tested. It is to be decided later whether we should ignore $LS_COLORS if $CLICOLOR is not set on Mac or FreeBSD.
[1] commit 7326d1f1a67edf21947ae98194f98c38b6e9e527 file src/ls.c. This is the last GPL-2 commit before coreutils turns to GPL-3.
--- Makefile | 1 + color.h | 8 ++ ls_colors.c (new) | 398 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 407 insertions(+) create mode 100644 ls_colors.c
Makefile +1 -0
@@ -819,6 +819,7 @@ LIB_OBJS += list-objects.o LIB_OBJS += ll-merge.o LIB_OBJS += lockfile.o LIB_OBJS += log-tree.o +LIB_OBJS += ls_colors.o LIB_OBJS += mailmap.o LIB_OBJS += match-trees.o LIB_OBJS += merge.o
color.h +8 -0
@@ -45,6 +45,12 @@ struct strbuf;#define GIT_COLOR_BG_MAGENTA "\033[45m"#define GIT_COLOR_BG_CYAN "\033[46m" +#define GIT_COLOR_WHITE_ON_RED "\033[37;41m" +#define GIT_COLOR_WHITE_ON_BLUE "\033[37;44m" +#define GIT_COLOR_BLACK_ON_YELLOW "\033[30;43m" +#define GIT_COLOR_BLUE_ON_GREEN "\033[34;42m" +#define GIT_COLOR_BLACK_ON_GREEN "\033[30;42m" +/* A special value meaning "no color selected" */ #define GIT_COLOR_NIL "NIL"
@@ -87,4 +93,6 @@ void color_print_strbuf(FILE *fp, const char *color, const struct strbuf *sb);int color_is_nil (const char *color); +void parse_ls_color (void ); +#endif /* COLOR_H */
ls_colors.c new file +398 -0
398 lines not on this page · raw message
Signature · 1 line
1.9.1.345.ga1a145c
PATCH v3 2/18 ls_colors.c: parse color.ls.* from config file
In reply to Nguyễn Thái Ngọc DuyThis is the second (and preferred) source for color information. This will override $LS_COLORS.
--- Documentation/config.txt | 11 +++++++++++ ls_colors.c | 26 ++++++++++++++++++++++++++ 2 files changed, 37 insertions(+)
Documentation/config.txt +11 -0
@@ -909,6 +909,17 @@ color.status.<slot>:: to red). The values of these variables may be specified as in color.branch.<slot>. +color.ls.<slot>:: + Use customized color for file name colorization. If not set + and the environment variable LS_COLORS is set, color settings + from $LS_COLORS are used. `<slot>` can be `normal`, `file`, + `directory`, `symlink`, `fifo`, `socket`, `block`, `char`, + `missing`, `orphan`, `executable`, `door`, `setuid`, `setgid`, + `sticky`, `otherwritable`, `stickyotherwritable`, `cap`, + `multihardlink`. The values of these variables may be + specified as in color.branch.<slot>. + + color.ui:: This variable determines the default value for variables such as `color.diff` and `color.grep` that control the use of color
ls_colors.c +26 -0
@@ -68,6 +68,14 @@ static const char *const indicator_name[] = {NULL }; +static const char *const config_name[] = { +"" ,"" ,"" ,"" ,"normal" ,"file" ,"directory" ,"symlink" , +"fifo" ,"socket" ,"block" ,"char" ,"missing" ,"orphan" ,"executable" , +"door" ,"setuid" ,"setgid" ,"sticky" ,"otherwritable" , +"stickyotherwritable" ,"cap" ,"multihardlink" ,"" , +NULL +}; +struct bin_str {size_t len;/* Number of bytes */ const char *string;/* Pointer to the same */
@@ -285,6 +293,23 @@ static int get_funky_string(char **dest, const char **src, int equals_end,return state !=ST_ERROR ; } +static int ls_colors_config (const char *var,const char *value,void *cb) +{ +int slot; +if (!starts_with (var,"color.ls." )) +return 0 ; + var +=9 ; +for (slot =0 ; config_name[slot]; slot++) +if (!strcasecmp (var, config_name[slot])) +break ; +if (!config_name[slot]) +return 0 ; +if (!value) +return config_error_nonbool (var); +color_parse (value, var, ls_colors[slot]); +return 0 ; +} +void parse_ls_color (void ) {const char *p;/* Pointer to character being parsed */
@@ -395,4 +420,5 @@ void parse_ls_color(void)if (!strcmp (ls_colors[LS_LN ],"target" )) color_symlink_as_referent =1 ; +git_config (ls_colors_config,NULL ); }
Signature · 1 line
1.9.1.345.ga1a145c
PATCH v3 3/18 ls_colors.c: add a function to color a file name
In reply to Nguyễn Thái Ngọc DuyThe new function is based on print_color_indicator() from commit 7326d1f1a67edf21947ae98194f98c38b6e9e527 in coreutils.git.
--- color.h | 2 ++ ls_colors.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+)
color.h +2 -0
@@ -94,5 +94,7 @@ void color_print_strbuf(FILE *fp, const char *color, const struct strbuf *sb);int color_is_nil (const char *color);void parse_ls_color (void ); +void color_filename (struct strbuf *sb,const char *name, +const char *display_name,mode_t mode,int linkok);#endif /* COLOR_H */
ls_colors.c +66 -0
69 lines not on this page · raw message
Signature · 1 line
1.9.1.345.ga1a145c
PATCH v3 4/18 ls_colors.c: highlight submodules like directories
In reply to Nguyễn Thái Ngọc Duy--- Documentation/config.txt | 3 ++- ls_colors.c | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-)
Documentation/config.txt +2 -1
@@ -913,7 +913,8 @@ color.ls.<slot>:: Use customized color for file name colorization. If not set and the environment variable LS_COLORS is set, color settings from $LS_COLORS are used. `<slot>` can be `normal`, `file`, - `directory`, `symlink`, `fifo`, `socket`, `block`, `char`, + `directory`, `submodule`, + `symlink`, `fifo`, `socket`, `block`, `char`, `missing`, `orphan`, `executable`, `door`, `setuid`, `setgid`, `sticky`, `otherwritable`, `stickyotherwritable`, `cap`, `multihardlink`. The values of these variables may be
ls_colors.c +7 -1
@@ -29,6 +29,8 @@ enum color_ls {LS_MH ,/* multi hardlink */ LS_CL ,/* clear end of line */ +LS_SUBMODULE , + MAX_LS };
@@ -58,7 +60,8 @@ static char ls_colors[MAX_LS][COLOR_MAXLEN] = {GIT_COLOR_BLACK_ON_GREEN ,"" ,"" , -"" +"" , +GIT_COLOR_BOLD_BLUE }; static const char *const indicator_name[] = {
@@ -73,6 +76,7 @@ static const char* const config_name[] = {"fifo" ,"socket" ,"block" ,"char" ,"missing" ,"orphan" ,"executable" ,"door" ,"setuid" ,"setgid" ,"sticky" ,"otherwritable" ,"stickyotherwritable" ,"cap" ,"multihardlink" ,"" , +"submodule" ,NULL };
@@ -448,6 +452,8 @@ void color_filename(struct strbuf *sb, const char *name, type =LS_DI ; }else if (S_ISLNK (mode)) type = (!linkok && *ls_colors[LS_OR ]) ?LS_OR :LS_LN ; +else if (S_ISGITLINK (mode)) + type =LS_SUBMODULE ;else if (S_ISFIFO (mode)) type =LS_PI ;else if (S_ISSOCK (mode))
Signature · 1 line
1.9.1.345.ga1a145c
PATCH v3 5/18 ls-files: buffer full item in strbuf before printing
In reply to Nguyễn Thái Ngọc DuyBuffering so that we can manipulate the strings (e.g. coloring) further before finally printing them.
--- builtin/ls-files.c | 48 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 13 deletions(-)
builtin/ls-files.c +35 -13
@@ -47,18 +47,30 @@ static const char *tag_modified = "";static const char *tag_skip_worktree ="" ;static const char *tag_resolve_undo ="" ; -static void write_name (const char *name) +static void write_name (struct strbuf *sb,const char *name) {/* * With "--full-name", prefix_len=0; this caller needs to pass * an empty string in that case (a NULL is good for ""). */ -write_name_quoted_relative (name, prefix_len ? prefix :NULL , - stdout, line_terminator); +const char *real_prefix = prefix_len ? prefix :NULL ; +if (!line_terminator) { +struct strbuf sb2 =STRBUF_INIT ; +strbuf_addstr (sb,relative_path (name, real_prefix, &sb2)); +strbuf_release (&sb2); + }else +quote_path_relative (name, real_prefix, sb); +strbuf_addch (sb, line_terminator); +} + +static void strbuf_fputs (struct strbuf *sb,FILE *fp) +{ +fwrite (sb->buf, sb->len,1 , fp); }static void show_dir_entry (const char *tag,struct dir_entry *ent) { +static struct strbuf sb =STRBUF_INIT ;int len = max_prefix_len;if (len >= ent->len)
@@ -67,8 +79,10 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent)if (!dir_path_match (ent, &pathspec, len, ps_matched))return ; -fputs (tag, stdout); -write_name (ent->name); +strbuf_reset (&sb); +strbuf_addstr (&sb, tag); +write_name (&sb, ent->name); +strbuf_fputs (&sb, stdout); }static void show_other_files (struct dir_struct *dir)
@@ -134,6 +148,7 @@ static void show_killed_files(struct dir_struct *dir)static void show_ce_entry (const char *tag,const struct cache_entry *ce) { +static struct strbuf sb =STRBUF_INIT ;int len = max_prefix_len;if (len >=ce_namelen (ce))
@@ -161,16 +176,18 @@ static void show_ce_entry(const char *tag, const struct cache_entry *ce) tag = alttag; } +strbuf_reset (&sb);if (!show_stage) { -fputs (tag, stdout); +strbuf_addstr (&sb, tag); }else { -printf ("%s%06o %s %d\t" , - tag, - ce->ce_mode, -find_unique_abbrev (ce->sha1,abbrev), -ce_stage (ce)); +strbuf_addf (&sb,"%s%06o %s %d\t" , + tag, + ce->ce_mode, +find_unique_abbrev (ce->sha1,abbrev), +ce_stage (ce)); } -write_name (ce->name); +write_name (&sb, ce->name); +strbuf_fputs (&sb, stdout);if (debug_mode) {const struct stat_data *sd = &ce->ce_stat_data;
@@ -206,7 +223,12 @@ static void show_ru_info(void)printf ("%s%06o %s %d\t" , tag_resolve_undo, ui->mode[i],find_unique_abbrev (ui->sha1[i], abbrev), i +1 ); -write_name (path); +/* +* With "--full-name", prefix_len=0; this caller needs to pass +* an empty string in that case (a NULL is good for ""). +*/ +write_name_quoted_relative (path, prefix_len ? prefix :NULL , + stdout, line_terminator); } } }
Signature · 1 line
1.9.1.345.ga1a145c
PATCH v3 6/18 ls-files: add --color to highlight file names
In reply to Nguyễn Thái Ngọc Duy--- Documentation/git-ls-files.txt | 7 +++++++ builtin/ls-files.c | 38 +++++++++++++++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 3 deletions(-)
Documentation/git-ls-files.txt +7 -0
@@ -147,6 +147,13 @@ a space) at the start of each line: possible for manual inspection; the exact format may change at any time. +--color[=<when>]:: +--no-color:: + Color file names. The value must be `always`, `never`, or + `auto`. `--no-color` is equivalent to + `--color=never`. `--color` is equivalent to + `--color=auto`. + \--:: Do not interpret any more arguments as options.
builtin/ls-files.c +35 -3
@@ -14,6 +14,7 @@#include "resolve-undo.h" #include "string-list.h" #include "pathspec.h" +#include "color.h" static int abbrev;static int show_deleted;
@@ -27,6 +28,7 @@ static int show_killed;static int show_valid_bit;static int line_terminator ='\n' ;static int debug_mode; +static int use_color;static const char *prefix;static int max_prefix_len;
@@ -60,7 +62,6 @@ static void write_name(struct strbuf *sb, const char *name)strbuf_release (&sb2); }else quote_path_relative (name, real_prefix, sb); -strbuf_addch (sb, line_terminator); }static void strbuf_fputs (struct strbuf *sb,FILE *fp)
@@ -68,6 +69,21 @@ static void strbuf_fputs(struct strbuf *sb, FILE *fp)fwrite (sb->buf, sb->len,1 , fp); } +static void write_dir_entry (struct strbuf *sb,const struct dir_entry *ent) +{ +struct strbuf quoted =STRBUF_INIT ; +struct stat st; +if (stat (ent->name, &st)) + st.st_mode =0 ; +write_name ("ed, ent->name); +if (want_color (use_color)) +color_filename (sb, ent->name, quoted.buf, st.st_mode,1 ); +else +strbuf_addbuf (sb, "ed); +strbuf_addch (sb, line_terminator); +strbuf_release ("ed); +} +static void show_dir_entry (const char *tag,struct dir_entry *ent) {static struct strbuf sb =STRBUF_INIT ;
@@ -81,7 +97,7 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent)strbuf_reset (&sb);strbuf_addstr (&sb, tag); -write_name (&sb, ent->name); +write_dir_entry (&sb, ent);strbuf_fputs (&sb, stdout); }
@@ -146,6 +162,18 @@ static void show_killed_files(struct dir_struct *dir) } } +static void write_ce_name (struct strbuf *sb,const struct cache_entry *ce) +{ +struct strbuf quoted =STRBUF_INIT ; +write_name ("ed, ce->name); +if (want_color (use_color)) +color_filename (sb, ce->name, quoted.buf, ce->ce_mode,1 ); +else +strbuf_addbuf (sb, "ed); +strbuf_addch (sb, line_terminator); +strbuf_release ("ed); +} +static void show_ce_entry (const char *tag,const struct cache_entry *ce) {static struct strbuf sb =STRBUF_INIT ;
@@ -186,7 +214,7 @@ static void show_ce_entry(const char *tag, const struct cache_entry *ce)find_unique_abbrev (ce->sha1,abbrev), ce_stage(ce)); } -write_name (&sb, ce->name); +write_ce_name (&sb, ce);strbuf_fputs (&sb, stdout);if (debug_mode) {const struct stat_data *sd = &ce->ce_stat_data;
@@ -523,6 +551,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) N_("if any <file> is not in the index, treat this as an error")),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__ABBREV (&abbrev),OPT_BOOL (0 ,"debug" , &debug_mode,N_ ("show debugging data" )),OPT_END ()
@@ -570,6 +599,9 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)if (require_work_tree && !is_inside_work_tree ())setup_work_tree (); +if (want_color (use_color)) +parse_ls_color (); + parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD | PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP,
Signature · 1 line
1.9.1.345.ga1a145c
PATCH v3 7/18 ls-files: add --column
In reply to Nguyễn Thái Ngọc Duy--- Documentation/git-ls-files.txt | 6 ++++++ builtin/ls-files.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+)
Documentation/git-ls-files.txt +6 -0
@@ -154,6 +154,12 @@ a space) at the start of each line: `--color=never`. `--color` is equivalent to `--color=auto`. +--column[=<options>]:: +--no-column:: + Display files in columns. See configuration variable column.ui + for option syntax. `--column` and `--no-column` without options + are equivalent to 'always' and 'never' respectively. + \--:: Do not interpret any more arguments as options.
builtin/ls-files.c +28 -0
@@ -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,14 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)if (show_resolve_undo)show_ru_info (); +if (column_active (colopts)) { +struct column_options copts; +memset (&copts,0 ,sizeof (copts)); + copts.padding =2 ; +print_columns (&output, colopts, &copts); +string_list_clear (&output,0 ); + } +if (ps_matched) {int bad; bad =report_path_error (ps_matched, &pathspec, prefix);
Signature · 1 line
1.9.1.345.ga1a145c
PATCH v3 8/18 ls-files: support --max-depth
In reply to Nguyễn Thái Ngọc Duy--- Documentation/git-ls-files.txt | 7 +++++++ builtin/ls-files.c | 7 +++++++ 2 files changed, 14 insertions(+)
Documentation/git-ls-files.txt +7 -0
@@ -160,6 +160,13 @@ a space) at the start of each line: for option syntax. `--column` and `--no-column` without options are equivalent to 'always' and 'never' respectively. +--max-depth=<depth>:: + For each <pathspec> given on command line, descend at most <depth> + levels of directories. A negative value means no limit (default). + This option is ignored if <pathspec> contains active wildcards. + In other words if "a*" matches a directory named "a*", + "*" is matched literally so --max-depth is still effective. + \--:: Do not interpret any more arguments as options.
builtin/ls-files.c +7 -0
@@ -503,6 +503,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; +int max_depth =-1 ;const char *max_prefix;struct dir_struct dir;struct exclude_list *el;
@@ -560,6 +561,9 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) 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" )), + { OPTION_INTEGER, 0, "max-depth", &max_depth, N_("depth"), +N_ ("descend at most <depth> levels" ),PARSE_OPT_NONEG , + NULL, 1 },OPT__ABBREV (&abbrev),OPT_BOOL (0 ,"debug" , &debug_mode,N_ ("show debugging data" )),OPT_END ()
@@ -624,8 +628,11 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)parse_pathspec (&pathspec,0 ,PATHSPEC_PREFER_CWD | + (max_depth !=-1 ?PATHSPEC_MAXDEPTH_VALID :0 ) |PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP , prefix, argv); + pathspec.max_depth = max_depth; + pathspec.recursive =1 ;/* Find common prefix for all pathspec's */ max_prefix =common_prefix (&pathspec);
Signature · 1 line
1.9.1.345.ga1a145c
PATCH v3 9/18 Add git-list-files, a user friendly version of ls-files and more
In reply to Nguyễn Thái Ngọc DuyThis is more user friendly version of ls-files:
* it's automatically colored and columnized
* it refreshes the index like all porcelain commands
* it defaults to non-recursive behavior like ls
* :(glob) is on by default so '*.c' means a.c but not a/b.c, use '**/*.c' for that.
* auto pager
The name 'ls' is not taken. It is left for the user to make an alias with better default options.
--- .gitignore | 1 + Documentation/config.txt | 10 +++++ Documentation/git-list-files.txt (new) | 80 ++++++++++++++++++++++++++++++++++ Makefile | 1 + builtin/ls-files.c | 69 +++++++++++++++++++++++++++-- command-list.txt | 1 + git.c | 1 + 7 files changed, 159 insertions(+), 4 deletions(-) create mode 100644 Documentation/git-list-files.txt
.gitignore +1 -0
@@ -75,6 +75,7 @@ /git-init /git-init-db /git-instaweb +/git-list-files /git-log /git-ls-files /git-ls-remote
Documentation/config.txt +10 -0
@@ -909,6 +909,12 @@ color.status.<slot>:: to red). The values of these variables may be specified as in color.branch.<slot>. +color.list-files:: + A boolean to enable/disable color in the output of + linkgit:git-list-files[1]. May be set to `always`, `false` (or + `never`) or `auto` (or `true`), in which case colors are used + only when the output is to a terminal. Defaults to false. + color.ls.<slot>:: Use customized color for file name colorization. If not set and the environment variable LS_COLORS is set, color settings
@@ -981,6 +987,10 @@ column.clean:: Specify the layout when list items in `git clean -i`, which always shows files and directories in columns. See `column.ui` for details. +column.list-files:: + Specify whether to output tag listing in `git list-files` in columns. + See `column.ui` for details. + column.status:: Specify whether to output untracked files in `git status` in columns. See `column.ui` for details.
Documentation/git-list-files.txt new file +80 -0
80 lines not on this page · raw message
Makefile +1 -0
@@ -584,6 +584,7 @@ BUILT_INS += git-cherry-pick$X BUILT_INS += git-format-patch$X BUILT_INS += git-fsck-objects$X BUILT_INS += git-init$X +BUILT_INS += git-list-files$X BUILT_INS += git-merge-subtree$X BUILT_INS += git-show$X BUILT_INS += git-stage$X
builtin/ls-files.c +65 -4
110 lines not on this page · raw message
command-list.txt +1 -0
@@ -63,6 +63,7 @@ git-index-pack plumbingmanipulators git-init mainporcelain common git-instaweb ancillaryinterrogators gitk mainporcelain +git-list-files mainporcelain git-log mainporcelain common git-ls-files plumbinginterrogators git-ls-remote plumbinginterrogators
git.c +1 -0
@@ -380,6 +380,7 @@ static struct cmd_struct commands[] = { { "index-pack", cmd_index_pack, RUN_SETUP_GENTLY }, { "init", cmd_init_db }, { "init-db", cmd_init_db }, + { "list-files", cmd_ls_files, RUN_SETUP }, { "log", cmd_log, RUN_SETUP }, { "ls-files", cmd_ls_files, RUN_SETUP }, { "ls-remote", cmd_ls_remote, RUN_SETUP_GENTLY },
Signature · 1 line
1.9.1.345.ga1a145c
PATCH v3 10/18 list-files: -u does not imply showing stages
In reply to Nguyễn Thái Ngọc DuyShowing full index entry information is something for ls-files only. The users of "git list-files" may just want to know what entries are not unmerged.
--- builtin/ls-files.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/ls-files.c +1 -1
@@ -656,7 +656,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) }if (show_modified || show_others || show_deleted || (dir.flags &DIR_SHOW_IGNORED ) || show_killed) require_work_tree =1 ; -if (show_unmerged) +if (show_unmerged && !porcelain)/* * There's no point in showing unmerged unless * you also show the stage information.
Signature · 1 line
1.9.1.345.ga1a145c
PATCH v3 11/18 list-files: add -R/--recursive short for --max-depth=-1
In reply to Nguyễn Thái Ngọc Duy--- Documentation/git-list-files.txt | 4 ++++ builtin/ls-files.c | 2 ++ 2 files changed, 6 insertions(+)
Documentation/git-list-files.txt +4 -0
@@ -45,6 +45,10 @@ OPTIONS --unmerged:: Show unmerged files +-R:: +--recursive:: + Equivalent of `--max-depth=-1` (infinite recursion). + --color[=<when>]:: --no-color:: Color file names. The value must be `always`, `never`, or
builtin/ls-files.c +2 -0
@@ -594,6 +594,8 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) N_("show cached files that have modification on working directory")),OPT_BOOL ('o' ,"others" , &show_others,N_ ("show untracked files" )), +OPT_SET_INT ('R' ,"recursive" , &max_depth, +N_ ("shortcut for --max-depth=-1" ),-1 ),OPT_BIT ('i' ,"ignored" , &dir.flags,N_ ("show ignored files" ), DIR_SHOW_IGNORED),
Signature · 1 line
1.9.1.345.ga1a145c
PATCH v3 12/18 list-files: add -1 short for --no-column
In reply to Nguyễn Thái Ngọc Duy--- Documentation/git-list-files.txt | 3 +++ builtin/ls-files.c | 2 ++ 2 files changed, 5 insertions(+)
Documentation/git-list-files.txt +3 -0
@@ -49,6 +49,9 @@ OPTIONS --recursive:: Equivalent of `--max-depth=-1` (infinite recursion). +-1:: + Equivalent of --no-column. + --color[=<when>]:: --no-color:: Color file names. The value must be `always`, `never`, or
builtin/ls-files.c +2 -0
@@ -603,6 +603,8 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) N_("show unmerged files")),OPT__COLOR (&use_color,N_ ("show color" )),OPT_COLUMN (0 ,"column" , &colopts,N_ ("show files in columns" )), +OPT_SET_INT ('1' ,NULL , &colopts, +N_ ("shortcut for --no-column" ),COL_PARSEOPT ), { OPTION_INTEGER, 0, "max-depth", &max_depth, N_("depth"),N_ ("descend at most <depth> levels" ),PARSE_OPT_NONEG , NULL, 1 },
Signature · 1 line
1.9.1.345.ga1a145c
PATCH v3 13/18 list-files: add -t back
In reply to Nguyễn Thái Ngọc DuyTag "H" (cached) is not shown though because it's usually the majority and becomes noise. Not showing it makes the other tags stand out. -t is on by default if more than one file category is selected.
--- Documentation/git-list-files.txt | 6 ++++++ builtin/ls-files.c | 27 +++++++++++++++++---------- 2 files changed, 23 insertions(+), 10 deletions(-)
Documentation/git-list-files.txt +6 -0
@@ -45,6 +45,12 @@ OPTIONS --unmerged:: Show unmerged files +-t:: +--[no-]tag:: + Show a tag to indicate file type. Automatically turned on with + multiple file selections. See linkgit::git-ls-files[1] option + `-t` for more information. + -R:: --recursive:: Equivalent of `--max-depth=-1` (infinite recursion).
builtin/ls-files.c +17 -10
@@ -596,6 +596,8 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) N_("show untracked files")),OPT_SET_INT ('R' ,"recursive" , &max_depth,N_ ("shortcut for --max-depth=-1" ),-1 ), +OPT_BOOL ('t' ,"tag" , &show_tag, +N_ ("identify the file status with tags" )),OPT_BIT ('i' ,"ignored" , &dir.flags,N_ ("show ignored files" ), DIR_SHOW_IGNORED),
@@ -636,6 +638,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)setup_standard_excludes (&dir); use_color =-1 ; max_depth =0 ; + show_tag =-1 ;git_config (git_ls_config,NULL ); }else git_config (git_default_config,NULL );
@@ -648,16 +651,6 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)for (i =0 ; i < exclude_list.nr; i++) {add_exclude (exclude_list.items[i].string,"" ,0 , el, --exclude_args); } -if (show_tag || show_valid_bit) { - tag_cached ="H " ; - tag_unmerged ="M " ; - tag_removed ="R " ; - tag_modified ="C " ; - tag_other ="? " ; - tag_killed ="K " ; - tag_skip_worktree ="S " ; - tag_resolve_undo ="U " ; - }if (show_modified || show_others || show_deleted || (dir.flags &DIR_SHOW_IGNORED ) || show_killed) require_work_tree =1 ;if (show_unmerged && !porcelain)
@@ -711,6 +704,20 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) show_killed || show_modified || show_resolve_undo)) show_cached =1 ; +if (show_tag ==-1 ) + show_tag = (show_cached + show_deleted + show_others + + show_unmerged + show_killed + show_modified) >1 ; +if (show_tag || show_valid_bit) { + tag_cached = porcelain ?" " :"H " ; + tag_unmerged ="M " ; + tag_removed ="R " ; + tag_modified ="C " ; + tag_other ="? " ; + tag_killed ="K " ; + tag_skip_worktree ="S " ; + tag_resolve_undo ="U " ; + } +if (max_prefix)prune_cache (max_prefix);if (with_tree) {
Signature · 1 line
1.9.1.345.ga1a145c
PATCH v3 14/18 list-files: sort output and remove duplicates
In reply to Nguyễn Thái Ngọc DuyWhen you mix different file types, with ls-files you may get separate listing. For example, "ls-files -cm" will show file "abc" twice: one as part of cached list, one of modified list. With "ls" (and this patch) they will be in a single sorted list (easier for the eye).
Duplicate entries are also removed. Note that display content is compared, so if you have "-t" on, or you color file types differently, you will get duplicate textual entries. This is good imo.
--- builtin/ls-files.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-)
builtin/ls-files.c +24 -12
@@ -53,6 +53,13 @@ static const char *tag_modified = "";static const char *tag_skip_worktree ="" ;static const char *tag_resolve_undo ="" ; +static int compare_output (const void *a_,const void *b_) +{ +const struct string_list_item *a = a_; +const struct string_list_item *b = b_; +return strcmp (a->util, b->util); +} +static void write_name (struct strbuf *sb,const char *name) {/*
@@ -68,10 +75,12 @@ static void write_name(struct strbuf *sb, const char *name)quote_path_relative (name, real_prefix, sb); } -static void strbuf_fputs (struct strbuf *sb,FILE *fp) +static void strbuf_fputs (struct strbuf *sb,const char *full_name,FILE *fp) { -if (column_active (colopts)) { -string_list_append (&output,strbuf_detach (sb,NULL )); +if (column_active (colopts) || porcelain) { +struct string_list_item *it; + it =string_list_append (&output,strbuf_detach (sb,NULL )); + it->util = (void *)full_name;return ; }fwrite (sb->buf, sb->len,1 , fp);
@@ -106,7 +115,7 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent)strbuf_reset (&sb);strbuf_addstr (&sb, tag);write_dir_entry (&sb, ent); -strbuf_fputs (&sb, stdout); +strbuf_fputs (&sb, ent->name, stdout); }static void show_other_files (struct dir_struct *dir)
@@ -223,7 +232,7 @@ static void show_ce_entry(const char *tag, const struct cache_entry *ce) ce_stage(ce)); }write_ce_name (&sb, ce); -strbuf_fputs (&sb, stdout); +strbuf_fputs (&sb, ce->name, stdout);if (debug_mode) {const struct stat_data *sd = &ce->ce_stat_data;
@@ -524,6 +533,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)const char *max_prefix;struct dir_struct dir;struct exclude_list *el; +struct column_options copts;struct string_list exclude_list =STRING_LIST_INIT_NODUP ;struct option builtin_ls_files_options[] = { {OPTION_CALLBACK ,'z' ,NULL ,NULL ,NULL ,
@@ -671,7 +681,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)if (debug_mode)die (_ ("--column and --debug are incompatible" )); } -if (column_active (colopts)) +if (column_active (colopts) || porcelain) line_terminator =0 ;if (require_work_tree && !is_inside_work_tree ())
@@ -737,13 +747,15 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)if (show_resolve_undo)show_ru_info (); -if (column_active (colopts)) { -struct column_options copts; -memset (&copts,0 ,sizeof (copts)); - copts.padding =2 ; -print_columns (&output, colopts, &copts); -string_list_clear (&output,0 ); +memset (&copts,0 ,sizeof (copts)); + copts.padding =2 ; +if (porcelain) { +qsort (output.items, output.nr,sizeof (*output.items), + compare_output); +string_list_remove_duplicates (&output,0 ); } +print_columns (&output, colopts, &copts); +string_list_clear (&output,0 );if (ps_matched) {int bad;
Signature · 1 line
1.9.1.345.ga1a145c
PATCH v3 15/18 list-files: do not show duplicate cached entries
In reply to Nguyễn Thái Ngọc DuyWith the current show_files() "list-files -tcm" will show
foo.c
M foo.c
The first item is redundant. If "foo.c" is modified, we know it's in the cache. Introduce show_files_compact to do that because ls-files is plumbing and scripts may already depend on current display behavior.
Another difference in show_files_compact() is it does not show skip-worktree (aka outside sparse checkout) entries anymore, which makes sense in porcelain context.
--- builtin/ls-files.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-)
builtin/ls-files.c +51 -1
@@ -333,6 +333,53 @@ static void show_files(struct dir_struct *dir) } } +static void show_files_compact (struct dir_struct *dir) +{ +int i; + +/* For cached/deleted files we don't need to even do the readdir */ +if (show_others || show_killed) { +if (!show_others) + dir->flags |=DIR_COLLECT_KILLED_ONLY ; +fill_directory (dir, &pathspec); +if (show_others) +show_other_files (dir); +if (show_killed) +show_killed_files (dir); + } +if (!(show_cached || show_stage || show_deleted || show_modified)) +return ; +for (i =0 ; i < active_nr; i++) { +const struct cache_entry *ce = active_cache[i]; +struct stat st; +int err, shown =0 ; +if ((dir->flags &DIR_SHOW_IGNORED ) && + !ce_excluded (dir, ce)) +continue ; +if (show_unmerged && !ce_stage (ce)) +continue ; +if (ce->ce_flags &CE_UPDATE ) +continue ; +if (ce_skip_worktree (ce)) +continue ; + err =lstat (ce->name, &st); +if (show_deleted && err) { +show_ce_entry (tag_removed, ce); + shown =1 ; + } +if (show_modified && (err ||ce_modified (ce, &st,0 ))) { +show_ce_entry (tag_modified, ce); + shown =1 ; + } +if (ce_stage (ce)) { +show_ce_entry (tag_unmerged, ce); + shown =1 ; + } +if (!shown && show_cached) +show_ce_entry (tag_cached, ce); + } +} +/* * Prune the index to only contain stuff starting with "prefix" */
@@ -743,7 +790,10 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)refresh_index (&the_index,REFRESH_QUIET , &pathspec,NULL ,NULL );setup_pager (); } -show_files (&dir); +if (porcelain) +show_files_compact (&dir); +else +show_files (&dir);if (show_resolve_undo)show_ru_info ();
Signature · 1 line
1.9.1.345.ga1a145c
PATCH v3 16/18 list-files: show directories as well as files
In reply to Nguyễn Thái Ngọc DuyThe index does not store directories explicitly (except submodules) so we have to figure them out from file list. The function show_directories() deliberately generates duplicate directories and expects the previous patch to remove duplicates.
--- builtin/ls-files.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-)
builtin/ls-files.c +43 -1
@@ -27,6 +27,8 @@ static int show_resolve_undo;static int show_modified;static int show_killed;static int show_valid_bit; +static int show_tag; +static int show_dirs;static int line_terminator ='\n' ;static int debug_mode;static int use_color;
@@ -333,6 +335,43 @@ static void show_files(struct dir_struct *dir) } } +static void show_directories (const struct cache_entry *ce) +{ +static const char *last_directory; +struct strbuf sb =STRBUF_INIT ; +const char *p = ce->name + prefix_len; +const char *sep; + +if (last_directory) { +int len =strlen (last_directory); +if (!strncmp (ce->name, last_directory, len) && + ce->name[len] =='/' ) + p += len +1 ; + } + +while (*p && (sep =strchr (p,'/' ))) { +struct strbuf sb2 =STRBUF_INIT ; +strbuf_reset (&sb); +strbuf_add (&sb, ce->name, sep - ce->name); + p = sep +1 ; +if (!match_pathspec (&pathspec, sb.buf, sb.len, + prefix_len,NULL ,1 )) +continue ; +write_name (&sb2, sb.buf); +if (want_color (use_color)) { +struct strbuf sb3 =STRBUF_INIT ; +color_filename (&sb3, ce->name, sb2.buf,S_IFDIR ,1 ); +strbuf_release (&sb2); + sb2 = sb3; + } +if (show_tag) +strbuf_insert (&sb2,0 , tag_cached,strlen (tag_cached)); + last_directory =strbuf_detach (&sb,NULL ); +strbuf_fputs (&sb2, last_directory,NULL ); +strbuf_release (&sb2); + } +} +static void show_files_compact (struct dir_struct *dir) {int i;
@@ -353,6 +392,8 @@ static void show_files_compact(struct dir_struct *dir)const struct cache_entry *ce = active_cache[i];struct stat st;int err, shown =0 ; +if (show_dirs) +show_directories (ce);if ((dir->flags &DIR_SHOW_IGNORED ) && !ce_excluded (dir, ce))continue ;
@@ -575,7 +616,7 @@ static int git_ls_config(const char *var, const char *value, void *cb)int cmd_ls_files (int argc,const char **argv,const char *cmd_prefix) { -int require_work_tree =0 , show_tag =0 , i; +int require_work_tree =0 , i;int max_depth =-1 ;const char *max_prefix;struct dir_struct dir;
@@ -696,6 +737,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) use_color =-1 ; max_depth =0 ; show_tag =-1 ; + show_dirs =1 ;git_config (git_ls_config,NULL ); }else git_config (git_default_config,NULL );
Signature · 1 line
1.9.1.345.ga1a145c
PATCH v3 17/18 list-files: add -F/--classify
In reply to Nguyễn Thái Ngọc DuyThis appends an indicator after the file name if it's executable, a directory and so on, like in GNU ls. In fact append_indicator() is a rewrite from get_type_indicator() in coreutils.git commit 7326d1f1a67edf21947ae98194f98c38b6e9e527.
--- Documentation/git-list-files.txt | 6 ++++++ builtin/ls-files.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+)
Documentation/git-list-files.txt +6 -0
@@ -51,6 +51,12 @@ OPTIONS multiple file selections. See linkgit::git-ls-files[1] option `-t` for more information. +-F:: +--classify:: + Append indicator (one of `*/=>@|`, which is executable, + directory, socket, Solaris door, symlink, or fifo + respectively) to entries. + -R:: --recursive:: Equivalent of `--max-depth=-1` (infinite recursion).
builtin/ls-files.c +31 -0
@@ -29,6 +29,7 @@ static int show_killed;static int show_valid_bit;static int show_tag;static int show_dirs; +static int show_indicator;static int line_terminator ='\n' ;static int debug_mode;static int use_color;
@@ -77,6 +78,28 @@ static void write_name(struct strbuf *sb, const char *name)quote_path_relative (name, real_prefix, sb); } +static void append_indicator (struct strbuf *sb,mode_t mode) +{ +char c =0 ; +if (S_ISREG (mode)) { +if (mode & (S_IXUSR |S_IXGRP |S_IXOTH )) + c ='*' ; + }else if (S_ISDIR (mode)) + c ='/' ; +else if (S_ISLNK (mode)) + c ='@' ; +else if (S_ISFIFO (mode)) + c ='|' ; +else if (S_ISSOCK (mode)) + c ='=' ; +#ifdef S_ISDOOR + else if (S_ISDOOR(mode)) + c ='>' ; +#endif +if (c) +strbuf_addch (sb, c); +} +static void strbuf_fputs (struct strbuf *sb,const char *full_name,FILE *fp) {if (column_active (colopts) || porcelain) {
@@ -99,6 +122,8 @@ static void write_dir_entry(struct strbuf *sb, const struct dir_entry *ent)color_filename (sb, ent->name, quoted.buf, st.st_mode,1 ); else strbuf_addbuf(sb, "ed); +if (show_indicator && st.st_mode) +append_indicator (sb, st.st_mode);strbuf_addch (sb, line_terminator);strbuf_release ("ed); }
@@ -189,6 +214,8 @@ static void write_ce_name(struct strbuf *sb, const struct cache_entry *ce)color_filename (sb, ce->name, quoted.buf, ce->ce_mode,1 ); else strbuf_addbuf(sb, "ed); +if (show_indicator) +append_indicator (sb, ce->ce_mode);strbuf_addch (sb, line_terminator);strbuf_release ("ed); }
@@ -366,6 +393,8 @@ static void show_directories(const struct cache_entry *ce) }if (show_tag)strbuf_insert (&sb2,0 , tag_cached,strlen (tag_cached)); +if (show_indicator) +append_indicator (&sb2,S_IFDIR ); last_directory =strbuf_detach (&sb,NULL );strbuf_fputs (&sb2, last_directory,NULL );strbuf_release (&sb2);
@@ -701,6 +730,8 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) DIR_SHOW_IGNORED),OPT_BOOL ('u' ,"unmerged" , &show_unmerged,N_ ("show unmerged files" )), +OPT_BOOL ('F' ,"classify" , &show_indicator, +N_ ("append indicator (one of */=>@|) to entries" )),OPT__COLOR (&use_color,N_ ("show color" )),OPT_COLUMN (0 ,"column" , &colopts,N_ ("show files in columns" )), OPT_SET_INT('1', NULL, &colopts,
Signature · 1 line
1.9.1.345.ga1a145c
PATCH v3 18/18 list-files -F: show submodules with the new indicator '&'
In reply to Nguyễn Thái Ngọc Duy--- Documentation/git-list-files.txt | 4 ++-- builtin/ls-files.c | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-)
Documentation/git-list-files.txt +2 -2
@@ -53,8 +53,8 @@ OPTIONS -F:: --classify:: - Append indicator (one of `*/=>@|`, which is executable, - directory, socket, Solaris door, symlink, or fifo + Append indicator (one of `*/=>@|&`, which is executable, + directory, socket, Solaris door, symlink, fifo, or submodule respectively) to entries. -R::
builtin/ls-files.c +2 -0
@@ -92,6 +92,8 @@ static void append_indicator(struct strbuf *sb, mode_t mode) c ='|' ; else if (S_ISSOCK(mode)) c ='=' ; + else if (S_ISGITLINK(mode)) + c ='&' ;#ifdef S_ISDOOR else if (S_ISDOOR(mode)) c ='>' ;
Signature · 1 line
1.9.1.345.ga1a145c