Signed-off-by: Thomas Gummerer <[email protected]>
---
builtin/ls-files.c | 38 +++++++++++++++++++++++++++++++++++---
1 file changed, 35 insertions(+), 3 deletions(-)
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index e1cf6d8..22fb012 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -290,6 +290,22 @@ static void prune_cache(const char *prefix)
active_nr = last;
}
+static int needs_trailing_slash_stripped(void)
+{
+ int i;
+
+ if (!pathspec.nr)
+ return 0;
+
+ for (i = 0; i < pathspec.nr; i++) {
+ int len = strlen(pathspec.items[i].original);
+
+ if (len > 1 && (pathspec.items[i].original)[len - 1] == '/')
+ return 1;
+ }
+ return 0;
+}
+
/*
* Read the tree specified with --with-tree option
* (typically, HEAD) into stage #1 and then
@@ -447,6 +463,7 @@ int cmd_ls_files(int argc, const char **argv, const char
*cmd_prefix)
struct dir_struct dir;
struct exclude_list *el;
struct string_list exclude_list = STRING_LIST_INIT_NODUP;
+ struct filter_opts *opts = xmalloc(sizeof(*opts));
struct option builtin_ls_files_options[] = {
{ OPTION_CALLBACK, 'z', NULL, NULL, NULL,
N_("paths are separated with NUL character"),
@@ -512,9 +529,6 @@ int cmd_ls_files(int argc, const char **argv, const char
*cmd_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");
@@ -550,6 +564,24 @@ int cmd_ls_files(int argc, const char **argv, const char
*cmd_prefix)
PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP,
prefix, argv);
+ if (!with_tree && !needs_trailing_slash_stripped()) {
+ memset(opts, 0, sizeof(*opts));
+ opts->pathspec = &pathspec;
+ opts->read_staged = 1;
+ if (show_resolve_undo)
+ opts->read_resolve_undo = 1;
+ if (read_cache_filtered(opts) < 0)
+ die("index file corrupt");
+ } else {
+ if (read_cache() < 0)
+ die("index file corrupt");
+ parse_pathspec(&pathspec, 0,
+ PATHSPEC_PREFER_CWD |
+ PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP,
+ prefix, argv);
+
+ }
+
/* Find common prefix for all pathspec's */
max_prefix = common_prefix(&pathspec);
max_prefix_len = max_prefix ? strlen(max_prefix) : 0;
--
1.8.4.2
--
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