From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 00/21] nd/list-files updates
Date: Sun, 8 Feb 2015 16:01:18 +0700 [thread overview]
Message-ID: <1423386099-19994-1-git-send-email-pclouds@gmail.com> (raw)
- 02/21: fix a bug that ignores config keys if $LS_COLORS is not defined
- 09/21: use listFiles instead of list-files in config keys
- 17/21: incorporate match_pathspec changes from Junio,
use strbuf_swap in show_as_directory()
- 21/21: use test_decode_color and test_when_finished in t3080
Full diff of changes is
-- 8< --
diff --git a/Documentation/config.txt b/Documentation/config.txt
index 74da715..2dc4788 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -940,7 +940,7 @@ color.status.<slot>::
to red). The values of these variables may be specified as in
color.branch.<slot>.
-color.list-files::
+color.listFiles::
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
@@ -1018,7 +1018,7 @@ 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::
+column.listFiles::
Specify whether to output tag listing in `git list-files` in columns.
See `column.ui` for details.
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index b04c712..b5e1a59 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -229,8 +229,8 @@ static int show_as_directory(const struct cache_entry *ce)
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;
+ strbuf_swap(&sb2, &sb3);
+ strbuf_release(&sb3);
}
if (show_tag)
strbuf_insert(&sb2, 0, tag_cached, strlen(tag_cached));
@@ -258,33 +258,41 @@ static void write_ce_name(struct strbuf *sb, const struct cache_entry *ce)
strbuf_release("ed);
}
+static int match_pathspec_with_depth(struct pathspec *ps,
+ const char *name, int namelen,
+ int prefix, char *seen, int is_dir,
+ const int *custom_depth)
+{
+ int saved_depth = ps->max_depth;
+ int result;
+
+ if (custom_depth)
+ ps->max_depth = *custom_depth;
+ result = match_pathspec(ps, name, namelen, prefix, seen, is_dir);
+ if (custom_depth)
+ ps->max_depth = saved_depth;
+ return result;
+}
+
static void show_ce_entry(const char *tag, const struct cache_entry *ce)
{
static struct strbuf sb = STRBUF_INIT;
- int len = max_prefix_len, saved_max_depth;
+ static const int infinite_depth = -1;
+ int len = max_prefix_len;
if (len >= ce_namelen(ce))
die("git ls-files: internal error - cache entry not superset of prefix");
- if (show_dirs) {
- /* ignore depth to catch dirs that contain matched entries */
- saved_max_depth = pathspec.max_depth;
- pathspec.max_depth = -1;
- }
-
- if (!match_pathspec(&pathspec, ce->name, ce_namelen(ce),
- len, ps_matched,
- S_ISDIR(ce->ce_mode) || S_ISGITLINK(ce->ce_mode)))
+ if (!match_pathspec_with_depth(&pathspec, ce->name, ce_namelen(ce),
+ len, ps_matched,
+ S_ISDIR(ce->ce_mode) || S_ISGITLINK(ce->ce_mode),
+ show_dirs ? &infinite_depth : NULL))
return;
- if (show_dirs) {
- pathspec.max_depth = saved_max_depth;
- if (strchr(ce->name, '/') &&
- !match_pathspec(&pathspec, ce->name, ce_namelen(ce),
- prefix_len, NULL, 1) &&
- show_as_directory(ce))
- return;
- }
+ if (show_dirs &&strchr(ce->name, '/') &&
+ !match_pathspec(&pathspec, ce->name, ce_namelen(ce), prefix_len, NULL, 1) &&
+ show_as_directory(ce))
+ return;
if (tag && *tag && show_valid_bit &&
(ce->ce_flags & CE_VALID)) {
@@ -697,8 +705,8 @@ static int option_parse_exclude_standard(const struct option *opt,
static int git_ls_config(const char *var, const char *value, void *cb)
{
if (starts_with(var, "column."))
- return git_column_config(var, value, "list-files", &colopts);
- if (!strcmp(var, "color.list-files")) {
+ return git_column_config(var, value, "listfiles", &colopts);
+ if (!strcmp(var, "color.listfiles")) {
use_color = git_config_colorbool(var, value);
return 0;
}
diff --git a/ls_colors.c b/ls_colors.c
index 9259ad3..011a8b9 100644
--- a/ls_colors.c
+++ b/ls_colors.c
@@ -326,8 +326,10 @@ void parse_ls_color(void)
char *start;
size_t len;
- if ((p = getenv("LS_COLORS")) == NULL || *p == '\0')
+ if ((p = getenv("LS_COLORS")) == NULL || *p == '\0') {
+ git_config(ls_colors_config, NULL);
return;
+ }
ext = NULL;
strcpy(label, "??");
diff --git a/t/t3080-list-files.sh b/t/t3080-list-files.sh
index 6313dd9..01b9662 100755
--- a/t/t3080-list-files.sh
+++ b/t/t3080-list-files.sh
@@ -15,16 +15,26 @@ test_expect_success 'setup' '
test_expect_success 'LS_COLORS env variable' '
LS_COLORS="rs=0:fi=31:di=32" \
- git list-files --color=always | grep -v gitlink >actual &&
- test_cmp "$TEST_DIRECTORY"/t3080/ls_colors actual
+ git list-files --color=always | test_decode_color | \
+ grep -v gitlink >actual &&
+ cat >expected <<-\EOF &&
+ <GREEN>dir<RESET>
+ <RED>file<RESET>
+ EOF
+ test_cmp expected actual
'
test_expect_success 'color.ls.*' '
test_config color.ls.file red &&
test_config color.ls.directory green &&
test_config color.ls.submodule yellow &&
- git list-files --color=always >actual &&
- test_cmp "$TEST_DIRECTORY"/t3080/color_ls actual
+ git list-files --color=always | test_decode_color >actual &&
+ cat >expected <<-\EOF &&
+ <GREEN>dir<RESET>
+ <RED>file<RESET>
+ <YELLOW>gitlink<RESET>
+ EOF
+ test_cmp expected actual
'
test_expect_success 'column output' '
@@ -78,6 +88,7 @@ test_expect_success 'globbing' '
'
test_expect_success 'no dups' '
+ test_when_finished "git checkout file" &&
echo dirty >>file &&
git list-files -m file >actual &&
echo "file" >expected &&
@@ -100,6 +111,7 @@ test_expect_success '--classify' '
'
test_expect_success 'diff-cached' '
+ test_when_finished "git checkout file" &&
echo dirty >>file &&
git add file &&
git list-files -M >actual &&
diff --git a/t/t3080/color_ls b/t/t3080/color_ls
deleted file mode 100644
index 47f77ad..0000000
--- a/t/t3080/color_ls
+++ /dev/null
@@ -1,3 +0,0 @@
-^[[32mdir^[[m
-^[[31mfile^[[m
-^[[33mgitlink^[[m
diff --git a/t/t3080/ls_colors b/t/t3080/ls_colors
deleted file mode 100644
index 423c016..0000000
--- a/t/t3080/ls_colors
+++ /dev/null
@@ -1,2 +0,0 @@
-^[[32mdir^[[m
-^[[31mfile^[[m
-- 8< --
--
2.3.0.rc1.137.g477eb31
next reply other threads:[~2015-02-08 9:02 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-08 9:01 Nguyễn Thái Ngọc Duy [this message]
2015-02-08 9:01 ` [PATCH 01/21] ls_colors.c: add $LS_COLORS parsing code Nguyễn Thái Ngọc Duy
2015-02-08 9:01 ` [PATCH 02/21] ls_colors.c: parse color.ls.* from config file Nguyễn Thái Ngọc Duy
2015-02-08 9:01 ` [PATCH 03/21] ls_colors.c: add a function to color a file name Nguyễn Thái Ngọc Duy
2015-02-08 9:01 ` [PATCH 04/21] ls_colors.c: highlight submodules like directories Nguyễn Thái Ngọc Duy
2015-02-08 9:01 ` [PATCH 05/21] ls-files: buffer full item in strbuf before printing Nguyễn Thái Ngọc Duy
2015-02-08 9:01 ` [PATCH 06/21] ls-files: add --color to highlight file names Nguyễn Thái Ngọc Duy
2015-02-08 9:01 ` [PATCH 07/21] ls-files: add --column Nguyễn Thái Ngọc Duy
2015-02-08 9:01 ` [PATCH 08/21] ls-files: support --max-depth Nguyễn Thái Ngọc Duy
2015-02-08 9:01 ` [PATCH 09/21] list-files: a user friendly version of ls-files and more Nguyễn Thái Ngọc Duy
2015-02-08 9:01 ` [PATCH 10/21] list-files: make alias 'ls' default to 'list-files' Nguyễn Thái Ngọc Duy
2015-02-08 9:01 ` [PATCH 11/21] list-files: -u does not imply showing stages Nguyễn Thái Ngọc Duy
2015-02-08 9:01 ` [PATCH 12/21] list-files: add -R/--recursive short for --max-depth=-1 Nguyễn Thái Ngọc Duy
2015-02-08 9:01 ` [PATCH 13/21] list-files: add -1 short for --no-column Nguyễn Thái Ngọc Duy
2015-02-08 9:01 ` [PATCH 14/21] list-files: add -t back Nguyễn Thái Ngọc Duy
2015-02-08 9:01 ` [PATCH 15/21] list-files: sort output and remove duplicates Nguyễn Thái Ngọc Duy
2015-02-08 9:01 ` [PATCH 16/21] list-files: do not show duplicate cached entries Nguyễn Thái Ngọc Duy
2015-02-08 9:01 ` [PATCH 17/21] list-files: show directories as well as files Nguyễn Thái Ngọc Duy
2015-02-09 22:28 ` Junio C Hamano
2015-02-08 9:01 ` [PATCH 18/21] list-files: add -F/--classify Nguyễn Thái Ngọc Duy
2015-02-08 9:01 ` [PATCH 19/21] list-files -F: show submodules with the new indicator '&' Nguyễn Thái Ngọc Duy
2015-02-08 9:01 ` [PATCH 20/21] list-files: -M aka diff-cached Nguyễn Thái Ngọc Duy
2015-02-08 9:01 ` [PATCH 21/21] t3080: tests for git-list-files Nguyễn Thái Ngọc Duy
-- strict thread matches above, loose matches on Subject: below --
2015-01-25 12:37 [PATCH 00/21] nd/list-files updates Nguyễn Thái Ngọc Duy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1423386099-19994-1-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).