Re: [PATCH v2 09/19] ls-files.c: use index api

2013-07-17 Thread Thomas Gummerer
Duy Nguyen pclo...@gmail.com writes:

 On Sat, Jul 13, 2013 at 12:26 AM, Thomas Gummerer t.gumme...@gmail.com 
 wrote:
 +   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);

 So you load partial index here.

 +   } else {
 +   read_cache();
 +   }
 +   /* be nice with submodule paths ending in a slash */
 +   if (pathspec)
 +   strip_trailing_slash_from_submodules();

 Then strip_trailing_slash_from_submodules will attempt to convert
 pathspec foo/ to foo if foo exists in the index and is a
 gitlink. But becaues foo/ is used to load the partial index, foo
 is not loaded (is it?) and this could become incorrect no-op. I
 suggest you go through the pathspec once checking for ones ending with
 '/'. If so strip_trailing_... may potentially update pathspec, just
 load full index. If no pathspec ends with '/', strip_trail... is no-op
 and we can do partial loading safely.

It was loaded, because the adjusted_pathspec algorithm stripped the
trailing slash and then everything until the next slash.  That's
overkill except when the trailing slash had to be stripped.

I'll make the adjusted_pathspec algorithm more restrictive, so the last
trailing slash is no longer stripped.  If a pathspec contains a trailing
slash I'll load the whole index, as you suggested.
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 09/19] ls-files.c: use index api

2013-07-13 Thread Duy Nguyen
On Sat, Jul 13, 2013 at 12:26 AM, Thomas Gummerer t.gumme...@gmail.com wrote:
 +   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);

So you load partial index here.

 +   } else {
 +   read_cache();
 +   }
 +   /* be nice with submodule paths ending in a slash */
 +   if (pathspec)
 +   strip_trailing_slash_from_submodules();

Then strip_trailing_slash_from_submodules will attempt to convert
pathspec foo/ to foo if foo exists in the index and is a
gitlink. But becaues foo/ is used to load the partial index, foo
is not loaded (is it?) and this could become incorrect no-op. I
suggest you go through the pathspec once checking for ones ending with
'/'. If so strip_trailing_... may potentially update pathspec, just
load full index. If no pathspec ends with '/', strip_trail... is no-op
and we can do partial loading safely.
-- 
Duy
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 09/19] ls-files.c: use index api

2013-07-12 Thread Thomas Gummerer
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.gumme...@gmail.com
---
 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 majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html