Use the index api to read only part of the index, if the on-disk version of the index is index-v5. Signed-off-by: Thomas Gummerer <t.gummerer@xxxxxxxxx> --- builtin/ls-files.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/builtin/ls-files.c b/builtin/ls-files.c index 08d9786..80cc398 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -31,6 +31,7 @@ static const char *prefix; static int max_prefix_len; static int prefix_len; static const char **pathspec; +static struct pathspec pathspec_struct; static int error_unmatch; static char *ps_matched; static const char *with_tree; @@ -457,6 +458,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"), @@ -522,9 +524,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"); @@ -556,14 +555,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) setup_work_tree(); pathspec = get_pathspec(prefix, argv); - - /* be nice with submodule paths ending in a slash */ - if (pathspec) - strip_trailing_slash_from_submodules(); - - /* Find common prefix for all pathspec's */ - max_prefix = common_prefix(pathspec); - max_prefix_len = max_prefix ? strlen(max_prefix) : 0; + init_pathspec(&pathspec_struct, pathspec); /* Treat unmatching pathspec elements as errors */ if (pathspec && error_unmatch) { @@ -573,6 +565,23 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) ps_matched = xcalloc(1, num); } + if (!with_tree) { + memset(opts, 0, sizeof(*opts)); + opts->pathspec = &pathspec_struct; + opts->read_staged = 1; + if (show_resolve_undo) + opts->read_resolve_undo = 1; + read_cache_filtered(opts); + } else { + read_cache(); + } + /* be nice with submodule paths ending in a slash */ + if (pathspec) + strip_trailing_slash_from_submodules(); + + max_prefix = common_prefix(pathspec); + max_prefix_len = max_prefix ? strlen(max_prefix) : 0; + if ((dir.flags & DIR_SHOW_IGNORED) && !exc_given) die("ls-files --ignored needs some exclude pattern"); -- 1.8.3.453.g1dfc63d -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html