{"thread":{"id":"46163","subject":"[PATCH 00/17] convert ls-files internals to pass around an index","startedAt":"2017-06-12T22:14:27Z","lastAt":"2017-06-12T22:15:29Z","messageCount":18,"participants":["Brandon Williams"],"isPatch":true,"patchVersion":1,"patchTotal":17},"messages":[{"id":"322012","messageId":"20170612221408.173876-1-bmwill@google.com","threadId":"46163","inReplyTo":null,"subject":"[PATCH 00/17] convert ls-files internals to pass around an index","fromName":"Brandon Williams","fromEmail":"bmwill@google.com","sentAt":"2017-06-12T22:13:51Z","receivedAt":"2017-06-12T22:14:27Z","isPatch":true,"sender":{"key":"bwilliams.eng@gmail.com","avatar":null},"body":"This is the second chunk of patches I want to carve off of my 'repository\nobject' series.  As you can see its 17 patches long so by eliminating this the\nrepository series shrinks by a considerable amount.\n\nThe point of this series is to stop having some of the internals of ls-files\n(and subsequent library routines) from implicitly referencing 'the_index'.\nInstead a pointer to an 'index_state' struct is passed around and operated on.\nThis is a preparatory step to enabling ls-files to able to recurse submodule\nin-process.  They other step being the actual introduction of a repository object.\n\nBrandon Williams (17):\n  convert: convert get_cached_convert_stats_ascii to take an index\n  convert: convert crlf_to_git to take an index\n  convert: convert convert_to_git_filter_fd to take an index\n  convert: convert convert_to_git to take an index\n  convert: convert renormalize_buffer to take an index\n  tree: convert read_tree to take an index parameter\n  ls-files: convert overlay_tree_on_cache to take an index\n  ls-files: convert write_eolinfo to take an index\n  ls-files: convert show_killed_files to take an index\n  ls-files: convert show_other_files to take an index\n  ls-files: convert show_ru_info to take an index\n  ls-files: convert ce_excluded to take an index\n  ls-files: convert prune_cache to take an index\n  ls-files: convert show_ce_entry to take an index\n  ls-files: convert show_files to take an index\n  ls-files: factor out debug info into a function\n  ls-files: factor out tag calculation\n\n apply.c            |   2 +-\n blame.c            |   2 +-\n builtin/commit.c   |   3 +-\n builtin/ls-files.c | 178 +++++++++++++++++++++++++++++------------------------\n cache.h            |   3 +-\n combine-diff.c     |   2 +-\n convert.c          |  31 ++++++----\n convert.h          |  19 ++++--\n diff.c             |   6 +-\n dir.c              |   2 +-\n ll-merge.c         |   2 +-\n merge-recursive.c  |   4 +-\n sha1_file.c        |   6 +-\n tree.c             |  28 ++++++---\n tree.h             |   3 +-\n 15 files changed, 168 insertions(+), 123 deletions(-)\n\n-- \n2.13.1.518.g3df882009-goog\n\n"},{"id":"322013","messageId":"20170612221408.173876-2-bmwill@google.com","threadId":"46163","inReplyTo":"20170612221408.173876-1-bmwill@google.com","subject":"[PATCH 01/17] convert: convert get_cached_convert_stats_ascii to take an index","fromName":"Brandon Williams","fromEmail":"bmwill@google.com","sentAt":"2017-06-12T22:13:52Z","receivedAt":"2017-06-12T22:14:29Z","isPatch":true,"sender":{"key":"bwilliams.eng@gmail.com","avatar":null},"body":"Signed-off-by: Brandon Williams <bmwill@google.com>\n---\n builtin/ls-files.c | 3 ++-\n convert.c          | 5 +++--\n convert.h          | 5 ++++-\n 3 files changed, 9 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/ls-files.c b/builtin/ls-files.c\nindex b376afc31..0044abf66 100644\n--- a/builtin/ls-files.c\n+++ b/builtin/ls-files.c\n@@ -63,7 +63,8 @@ static void write_eolinfo(const struct cache_entry *ce, const char *path)\n \t\tconst char *w_txt = \"\";\n \t\tconst char *a_txt = get_convert_attr_ascii(path);\n \t\tif (ce && S_ISREG(ce->ce_mode))\n-\t\t\ti_txt = get_cached_convert_stats_ascii(ce->name);\n+\t\t\ti_txt = get_cached_convert_stats_ascii(&the_index,\n+\t\t\t\t\t\t\t       ce->name);\n \t\tif (!lstat(path, &st) && S_ISREG(st.st_mode))\n \t\t\tw_txt = get_wt_convert_stats_ascii(path);\n \t\tprintf(\"i/%-5s w/%-5s attr/%-17s\\t\", i_txt, w_txt, a_txt);\ndiff --git a/convert.c b/convert.c\nindex f1e168bc3..03160b376 100644\n--- a/convert.c\n+++ b/convert.c\n@@ -134,11 +134,12 @@ static const char *gather_convert_stats_ascii(const char *data, unsigned long si\n \t}\n }\n \n-const char *get_cached_convert_stats_ascii(const char *path)\n+const char *get_cached_convert_stats_ascii(const struct index_state *istate,\n+\t\t\t\t\t   const char *path)\n {\n \tconst char *ret;\n \tunsigned long sz;\n-\tvoid *data = read_blob_data_from_cache(path, &sz);\n+\tvoid *data = read_blob_data_from_index(istate, path, &sz);\n \tret = gather_convert_stats_ascii(data, sz);\n \tfree(data);\n \treturn ret;\ndiff --git a/convert.h b/convert.h\nindex 82871a11d..667b7dfe0 100644\n--- a/convert.h\n+++ b/convert.h\n@@ -4,6 +4,8 @@\n #ifndef CONVERT_H\n #define CONVERT_H\n \n+struct index_state;\n+\n enum safe_crlf {\n \tSAFE_CRLF_FALSE = 0,\n \tSAFE_CRLF_FAIL = 1,\n@@ -33,7 +35,8 @@ enum eol {\n };\n \n extern enum eol core_eol;\n-extern const char *get_cached_convert_stats_ascii(const char *path);\n+extern const char *get_cached_convert_stats_ascii(const struct index_state *istate,\n+\t\t\t\t\t\t  const char *path);\n extern const char *get_wt_convert_stats_ascii(const char *path);\n extern const char *get_convert_attr_ascii(const char *path);\n \n-- \n2.13.1.518.g3df882009-goog\n\n"},{"id":"322014","messageId":"20170612221408.173876-3-bmwill@google.com","threadId":"46163","inReplyTo":"20170612221408.173876-1-bmwill@google.com","subject":"[PATCH 02/17] convert: convert crlf_to_git to take an index","fromName":"Brandon Williams","fromEmail":"bmwill@google.com","sentAt":"2017-06-12T22:13:53Z","receivedAt":"2017-06-12T22:14:30Z","isPatch":true,"sender":{"key":"bwilliams.eng@gmail.com","avatar":null},"body":"Signed-off-by: Brandon Williams <bmwill@google.com>\n---\n convert.c | 14 ++++++++------\n 1 file changed, 8 insertions(+), 6 deletions(-)\n\ndiff --git a/convert.c b/convert.c\nindex 03160b376..0cafb06f5 100644\n--- a/convert.c\n+++ b/convert.c\n@@ -218,13 +218,13 @@ static void check_safe_crlf(const char *path, enum crlf_action crlf_action,\n \t}\n }\n \n-static int has_cr_in_index(const char *path)\n+static int has_cr_in_index(const struct index_state *istate, const char *path)\n {\n \tunsigned long sz;\n \tvoid *data;\n \tint has_cr;\n \n-\tdata = read_blob_data_from_cache(path, &sz);\n+\tdata = read_blob_data_from_index(istate, path, &sz);\n \tif (!data)\n \t\treturn 0;\n \thas_cr = memchr(data, '\\r', sz) != NULL;\n@@ -254,7 +254,8 @@ static int will_convert_lf_to_crlf(size_t len, struct text_stat *stats,\n \n }\n \n-static int crlf_to_git(const char *path, const char *src, size_t len,\n+static int crlf_to_git(const struct index_state *istate,\n+\t\t       const char *path, const char *src, size_t len,\n \t\t       struct strbuf *buf,\n \t\t       enum crlf_action crlf_action, enum safe_crlf checksafe)\n {\n@@ -286,7 +287,8 @@ static int crlf_to_git(const char *path, const char *src, size_t len,\n \t\t * unless we want to renormalize in a merge or\n \t\t * cherry-pick.\n \t\t */\n-\t\tif ((checksafe != SAFE_CRLF_RENORMALIZE) && has_cr_in_index(path))\n+\t\tif ((checksafe != SAFE_CRLF_RENORMALIZE) &&\n+\t\t    has_cr_in_index(istate, path))\n \t\t\tconvert_crlf_into_lf = 0;\n \t}\n \tif ((checksafe == SAFE_CRLF_WARN ||\n@@ -1098,7 +1100,7 @@ int convert_to_git(const char *path, const char *src, size_t len,\n \t\tsrc = dst->buf;\n \t\tlen = dst->len;\n \t}\n-\tret |= crlf_to_git(path, src, len, dst, ca.crlf_action, checksafe);\n+\tret |= crlf_to_git(&the_index, path, src, len, dst, ca.crlf_action, checksafe);\n \tif (ret && dst) {\n \t\tsrc = dst->buf;\n \t\tlen = dst->len;\n@@ -1118,7 +1120,7 @@ void convert_to_git_filter_fd(const char *path, int fd, struct strbuf *dst,\n \tif (!apply_filter(path, NULL, 0, fd, dst, ca.drv, CAP_CLEAN))\n \t\tdie(\"%s: clean filter '%s' failed\", path, ca.drv->name);\n \n-\tcrlf_to_git(path, dst->buf, dst->len, dst, ca.crlf_action, checksafe);\n+\tcrlf_to_git(&the_index, path, dst->buf, dst->len, dst, ca.crlf_action, checksafe);\n \tident_to_git(path, dst->buf, dst->len, dst, ca.ident);\n }\n \n-- \n2.13.1.518.g3df882009-goog\n\n"},{"id":"322015","messageId":"20170612221408.173876-4-bmwill@google.com","threadId":"46163","inReplyTo":"20170612221408.173876-1-bmwill@google.com","subject":"[PATCH 03/17] convert: convert convert_to_git_filter_fd to take an index","fromName":"Brandon Williams","fromEmail":"bmwill@google.com","sentAt":"2017-06-12T22:13:54Z","receivedAt":"2017-06-12T22:14:32Z","isPatch":true,"sender":{"key":"bwilliams.eng@gmail.com","avatar":null},"body":"Signed-off-by: Brandon Williams <bmwill@google.com>\n---\n convert.c   | 5 +++--\n convert.h   | 3 ++-\n sha1_file.c | 2 +-\n 3 files changed, 6 insertions(+), 4 deletions(-)\n\ndiff --git a/convert.c b/convert.c\nindex 0cafb06f5..c09242cec 100644\n--- a/convert.c\n+++ b/convert.c\n@@ -1108,7 +1108,8 @@ int convert_to_git(const char *path, const char *src, size_t len,\n \treturn ret | ident_to_git(path, src, len, dst, ca.ident);\n }\n \n-void convert_to_git_filter_fd(const char *path, int fd, struct strbuf *dst,\n+void convert_to_git_filter_fd(const struct index_state *istate,\n+\t\t\t      const char *path, int fd, struct strbuf *dst,\n \t\t\t      enum safe_crlf checksafe)\n {\n \tstruct conv_attrs ca;\n@@ -1120,7 +1121,7 @@ void convert_to_git_filter_fd(const char *path, int fd, struct strbuf *dst,\n \tif (!apply_filter(path, NULL, 0, fd, dst, ca.drv, CAP_CLEAN))\n \t\tdie(\"%s: clean filter '%s' failed\", path, ca.drv->name);\n \n-\tcrlf_to_git(&the_index, path, dst->buf, dst->len, dst, ca.crlf_action, checksafe);\n+\tcrlf_to_git(istate, path, dst->buf, dst->len, dst, ca.crlf_action, checksafe);\n \tident_to_git(path, dst->buf, dst->len, dst, ca.ident);\n }\n \ndiff --git a/convert.h b/convert.h\nindex 667b7dfe0..3a813a797 100644\n--- a/convert.h\n+++ b/convert.h\n@@ -52,7 +52,8 @@ static inline int would_convert_to_git(const char *path)\n \treturn convert_to_git(path, NULL, 0, NULL, 0);\n }\n /* Precondition: would_convert_to_git_filter_fd(path) == true */\n-extern void convert_to_git_filter_fd(const char *path, int fd,\n+extern void convert_to_git_filter_fd(const struct index_state *istate,\n+\t\t\t\t     const char *path, int fd,\n \t\t\t\t     struct strbuf *dst,\n \t\t\t\t     enum safe_crlf checksafe);\n extern int would_convert_to_git_filter_fd(const char *path);\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 59a4ed2ed..ab09241d2 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -3580,7 +3580,7 @@ static int index_stream_convert_blob(unsigned char *sha1, int fd,\n \tassert(path);\n \tassert(would_convert_to_git_filter_fd(path));\n \n-\tconvert_to_git_filter_fd(path, fd, &sbuf,\n+\tconvert_to_git_filter_fd(&the_index, path, fd, &sbuf,\n \t\t\t\t write_object ? safe_crlf : SAFE_CRLF_FALSE);\n \n \tif (write_object)\n-- \n2.13.1.518.g3df882009-goog\n\n"},{"id":"322016","messageId":"20170612221408.173876-5-bmwill@google.com","threadId":"46163","inReplyTo":"20170612221408.173876-1-bmwill@google.com","subject":"[PATCH 04/17] convert: convert convert_to_git to take an index","fromName":"Brandon Williams","fromEmail":"bmwill@google.com","sentAt":"2017-06-12T22:13:55Z","receivedAt":"2017-06-12T22:14:34Z","isPatch":true,"sender":{"key":"bwilliams.eng@gmail.com","avatar":null},"body":"Signed-off-by: Brandon Williams <bmwill@google.com>\n---\n apply.c        | 2 +-\n blame.c        | 2 +-\n combine-diff.c | 2 +-\n convert.c      | 7 ++++---\n convert.h      | 8 +++++---\n diff.c         | 6 +++---\n dir.c          | 2 +-\n sha1_file.c    | 4 ++--\n 8 files changed, 18 insertions(+), 15 deletions(-)\n\ndiff --git a/apply.c b/apply.c\nindex c49cef063..97afb6f60 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -2267,7 +2267,7 @@ static int read_old_data(struct stat *st, const char *path, struct strbuf *buf)\n \tcase S_IFREG:\n \t\tif (strbuf_read_file(buf, path, st->st_size) != st->st_size)\n \t\t\treturn error(_(\"unable to open or read %s\"), path);\n-\t\tconvert_to_git(path, buf->buf, buf->len, buf, 0);\n+\t\tconvert_to_git(&the_index, path, buf->buf, buf->len, buf, 0);\n \t\treturn 0;\n \tdefault:\n \t\treturn -1;\ndiff --git a/blame.c b/blame.c\nindex 843c845cb..a6f3d72df 100644\n--- a/blame.c\n+++ b/blame.c\n@@ -229,7 +229,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,\n \t\tif (strbuf_read(&buf, 0, 0) < 0)\n \t\t\tdie_errno(\"failed to read from stdin\");\n \t}\n-\tconvert_to_git(path, buf.buf, buf.len, &buf, 0);\n+\tconvert_to_git(&the_index, path, buf.buf, buf.len, &buf, 0);\n \torigin->file.ptr = buf.buf;\n \torigin->file.size = buf.len;\n \tpretend_sha1_file(buf.buf, buf.len, OBJ_BLOB, origin->blob_oid.hash);\ndiff --git a/combine-diff.c b/combine-diff.c\nindex 2848034fe..74f723af3 100644\n--- a/combine-diff.c\n+++ b/combine-diff.c\n@@ -1053,7 +1053,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,\n \t\t\tif (is_file) {\n \t\t\t\tstruct strbuf buf = STRBUF_INIT;\n \n-\t\t\t\tif (convert_to_git(elem->path, result, len, &buf, safe_crlf)) {\n+\t\t\t\tif (convert_to_git(&the_index, elem->path, result, len, &buf, safe_crlf)) {\n \t\t\t\t\tfree(result);\n \t\t\t\t\tresult = strbuf_detach(&buf, &len);\n \t\t\t\t\tresult_size = len;\ndiff --git a/convert.c b/convert.c\nindex c09242cec..600d11e73 100644\n--- a/convert.c\n+++ b/convert.c\n@@ -1084,7 +1084,8 @@ const char *get_convert_attr_ascii(const char *path)\n \treturn \"\";\n }\n \n-int convert_to_git(const char *path, const char *src, size_t len,\n+int convert_to_git(const struct index_state *istate,\n+\t\t   const char *path, const char *src, size_t len,\n                    struct strbuf *dst, enum safe_crlf checksafe)\n {\n \tint ret = 0;\n@@ -1100,7 +1101,7 @@ int convert_to_git(const char *path, const char *src, size_t len,\n \t\tsrc = dst->buf;\n \t\tlen = dst->len;\n \t}\n-\tret |= crlf_to_git(&the_index, path, src, len, dst, ca.crlf_action, checksafe);\n+\tret |= crlf_to_git(istate, path, src, len, dst, ca.crlf_action, checksafe);\n \tif (ret && dst) {\n \t\tsrc = dst->buf;\n \t\tlen = dst->len;\n@@ -1171,7 +1172,7 @@ int renormalize_buffer(const char *path, const char *src, size_t len, struct str\n \t\tsrc = dst->buf;\n \t\tlen = dst->len;\n \t}\n-\treturn ret | convert_to_git(path, src, len, dst, SAFE_CRLF_RENORMALIZE);\n+\treturn ret | convert_to_git(&the_index, path, src, len, dst, SAFE_CRLF_RENORMALIZE);\n }\n \n /*****************************************************************\ndiff --git a/convert.h b/convert.h\nindex 3a813a797..60cb41d6a 100644\n--- a/convert.h\n+++ b/convert.h\n@@ -41,15 +41,17 @@ extern const char *get_wt_convert_stats_ascii(const char *path);\n extern const char *get_convert_attr_ascii(const char *path);\n \n /* returns 1 if *dst was used */\n-extern int convert_to_git(const char *path, const char *src, size_t len,\n+extern int convert_to_git(const struct index_state *istate,\n+\t\t\t  const char *path, const char *src, size_t len,\n \t\t\t  struct strbuf *dst, enum safe_crlf checksafe);\n extern int convert_to_working_tree(const char *path, const char *src,\n \t\t\t\t   size_t len, struct strbuf *dst);\n extern int renormalize_buffer(const char *path, const char *src, size_t len,\n \t\t\t      struct strbuf *dst);\n-static inline int would_convert_to_git(const char *path)\n+static inline int would_convert_to_git(const struct index_state *istate,\n+\t\t\t\t       const char *path)\n {\n-\treturn convert_to_git(path, NULL, 0, NULL, 0);\n+\treturn convert_to_git(istate, path, NULL, 0, NULL, 0);\n }\n /* Precondition: would_convert_to_git_filter_fd(path) == true */\n extern void convert_to_git_filter_fd(const struct index_state *istate,\ndiff --git a/diff.c b/diff.c\nindex 5275c4b78..976a6f91b 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -2755,7 +2755,7 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int\n \t * Similarly, if we'd have to convert the file contents anyway, that\n \t * makes the optimization not worthwhile.\n \t */\n-\tif (!want_file && would_convert_to_git(name))\n+\tif (!want_file && would_convert_to_git(&the_index, name))\n \t\treturn 0;\n \n \tlen = strlen(name);\n@@ -2877,7 +2877,7 @@ int diff_populate_filespec(struct diff_filespec *s, unsigned int flags)\n \t\t * point if the path requires us to run the content\n \t\t * conversion.\n \t\t */\n-\t\tif (size_only && !would_convert_to_git(s->path))\n+\t\tif (size_only && !would_convert_to_git(&the_index, s->path))\n \t\t\treturn 0;\n \n \t\t/*\n@@ -2904,7 +2904,7 @@ int diff_populate_filespec(struct diff_filespec *s, unsigned int flags)\n \t\t/*\n \t\t * Convert from working tree format to canonical git format\n \t\t */\n-\t\tif (convert_to_git(s->path, s->data, s->size, &buf, crlf_warn)) {\n+\t\tif (convert_to_git(&the_index, s->path, s->data, s->size, &buf, crlf_warn)) {\n \t\t\tsize_t size = 0;\n \t\t\tmunmap(s->data, s->size);\n \t\t\ts->should_munmap = 0;\ndiff --git a/dir.c b/dir.c\nindex 9efcf1eab..f673b86f3 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -795,7 +795,7 @@ static int add_excludes(const char *fname, const char *base, int baselen,\n \t\t\t\t (pos = index_name_pos(istate, fname, strlen(fname))) >= 0 &&\n \t\t\t\t !ce_stage(istate->cache[pos]) &&\n \t\t\t\t ce_uptodate(istate->cache[pos]) &&\n-\t\t\t\t !would_convert_to_git(fname))\n+\t\t\t\t !would_convert_to_git(istate, fname))\n \t\t\t\thashcpy(sha1_stat->sha1,\n \t\t\t\t\tistate->cache[pos]->oid.hash);\n \t\t\telse\ndiff --git a/sha1_file.c b/sha1_file.c\nindex ab09241d2..feb227a83 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -3546,7 +3546,7 @@ static int index_mem(unsigned char *sha1, void *buf, size_t size,\n \t */\n \tif ((type == OBJ_BLOB) && path) {\n \t\tstruct strbuf nbuf = STRBUF_INIT;\n-\t\tif (convert_to_git(path, buf, size, &nbuf,\n+\t\tif (convert_to_git(&the_index, path, buf, size, &nbuf,\n \t\t\t\t   write_object ? safe_crlf : SAFE_CRLF_FALSE)) {\n \t\t\tbuf = strbuf_detach(&nbuf, &size);\n \t\t\tre_allocated = 1;\n@@ -3668,7 +3668,7 @@ int index_fd(unsigned char *sha1, int fd, struct stat *st,\n \telse if (!S_ISREG(st->st_mode))\n \t\tret = index_pipe(sha1, fd, type, path, flags);\n \telse if (st->st_size <= big_file_threshold || type != OBJ_BLOB ||\n-\t\t (path && would_convert_to_git(path)))\n+\t\t (path && would_convert_to_git(&the_index, path)))\n \t\tret = index_core(sha1, fd, xsize_t(st->st_size), type, path,\n \t\t\t\t flags);\n \telse\n-- \n2.13.1.518.g3df882009-goog\n\n"},{"id":"322017","messageId":"20170612221408.173876-8-bmwill@google.com","threadId":"46163","inReplyTo":"20170612221408.173876-1-bmwill@google.com","subject":"[PATCH 07/17] ls-files: convert overlay_tree_on_cache to take an index","fromName":"Brandon Williams","fromEmail":"bmwill@google.com","sentAt":"2017-06-12T22:13:58Z","receivedAt":"2017-06-12T22:14:35Z","isPatch":true,"sender":{"key":"bwilliams.eng@gmail.com","avatar":null},"body":"Signed-off-by: Brandon Williams <bmwill@google.com>\n---\n builtin/commit.c   |  3 ++-\n builtin/ls-files.c | 15 ++++++++-------\n cache.h            |  3 ++-\n 3 files changed, 12 insertions(+), 9 deletions(-)\n\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex da1ba4c86..78ef319a2 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -253,7 +253,8 @@ static int list_paths(struct string_list *list, const char *with_tree,\n \n \tif (with_tree) {\n \t\tchar *max_prefix = common_prefix(pattern);\n-\t\toverlay_tree_on_cache(with_tree, max_prefix ? max_prefix : prefix);\n+\t\toverlay_tree_on_index(&the_index, with_tree,\n+\t\t\t\t      max_prefix ? max_prefix : prefix);\n \t\tfree(max_prefix);\n \t}\n \ndiff --git a/builtin/ls-files.c b/builtin/ls-files.c\nindex 93e46ab5f..a78b291ab 100644\n--- a/builtin/ls-files.c\n+++ b/builtin/ls-files.c\n@@ -431,7 +431,8 @@ static int get_common_prefix_len(const char *common_prefix)\n  * that were given from the command line.  We are not\n  * going to write this index out.\n  */\n-void overlay_tree_on_cache(const char *tree_name, const char *prefix)\n+void overlay_tree_on_index(struct index_state *istate,\n+\t\t\t   const char *tree_name, const char *prefix)\n {\n \tstruct tree *tree;\n \tstruct object_id oid;\n@@ -446,8 +447,8 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix)\n \t\tdie(\"bad tree-ish %s\", tree_name);\n \n \t/* Hoist the unmerged entries up to stage #3 to make room */\n-\tfor (i = 0; i < active_nr; i++) {\n-\t\tstruct cache_entry *ce = active_cache[i];\n+\tfor (i = 0; i < istate->cache_nr; i++) {\n+\t\tstruct cache_entry *ce = istate->cache[i];\n \t\tif (!ce_stage(ce))\n \t\t\tcontinue;\n \t\tce->ce_flags |= CE_STAGEMASK;\n@@ -460,11 +461,11 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix)\n \t\t\t       PATHSPEC_PREFER_CWD, prefix, matchbuf);\n \t} else\n \t\tmemset(&pathspec, 0, sizeof(pathspec));\n-\tif (read_tree(tree, 1, &pathspec, &the_index))\n+\tif (read_tree(tree, 1, &pathspec, istate))\n \t\tdie(\"unable to read tree entries %s\", tree_name);\n \n-\tfor (i = 0; i < active_nr; i++) {\n-\t\tstruct cache_entry *ce = active_cache[i];\n+\tfor (i = 0; i < istate->cache_nr; i++) {\n+\t\tstruct cache_entry *ce = istate->cache[i];\n \t\tswitch (ce_stage(ce)) {\n \t\tcase 0:\n \t\t\tlast_stage0 = ce;\n@@ -679,7 +680,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)\n \t\t */\n \t\tif (show_stage || show_unmerged)\n \t\t\tdie(\"ls-files --with-tree is incompatible with -s or -u\");\n-\t\toverlay_tree_on_cache(with_tree, max_prefix);\n+\t\toverlay_tree_on_index(&the_index, with_tree, max_prefix);\n \t}\n \tshow_files(&dir);\n \tif (show_resolve_undo)\ndiff --git a/cache.h b/cache.h\nindex 4d92aae0e..5a0e0a9e5 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -2186,7 +2186,8 @@ extern int ws_blank_line(const char *line, int len, unsigned ws_rule);\n #define ws_tab_width(rule)     ((rule) & WS_TAB_WIDTH_MASK)\n \n /* ls-files */\n-void overlay_tree_on_cache(const char *tree_name, const char *prefix);\n+void overlay_tree_on_index(struct index_state *istate,\n+\t\t\t   const char *tree_name, const char *prefix);\n \n char *alias_lookup(const char *alias);\n int split_cmdline(char *cmdline, const char ***argv);\n-- \n2.13.1.518.g3df882009-goog\n\n"},{"id":"322018","messageId":"20170612221408.173876-15-bmwill@google.com","threadId":"46163","inReplyTo":"20170612221408.173876-1-bmwill@google.com","subject":"[PATCH 14/17] ls-files: convert show_ce_entry to take an index","fromName":"Brandon Williams","fromEmail":"bmwill@google.com","sentAt":"2017-06-12T22:14:05Z","receivedAt":"2017-06-12T22:14:53Z","isPatch":true,"sender":{"key":"bwilliams.eng@gmail.com","avatar":null},"body":"Signed-off-by: Brandon Williams <bmwill@google.com>\n---\n builtin/ls-files.c | 11 ++++++-----\n 1 file changed, 6 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin/ls-files.c b/builtin/ls-files.c\nindex b1626b13b..927aa6746 100644\n--- a/builtin/ls-files.c\n+++ b/builtin/ls-files.c\n@@ -232,7 +232,8 @@ static void show_gitlink(const struct cache_entry *ce)\n \t\texit(status);\n }\n \n-static void show_ce_entry(const char *tag, const struct cache_entry *ce)\n+static void show_ce_entry(const struct index_state *istate,\n+\t\t\t  const char *tag, const struct cache_entry *ce)\n {\n \tstruct strbuf name = STRBUF_INIT;\n \tint len = max_prefix_len;\n@@ -276,7 +277,7 @@ static void show_ce_entry(const char *tag, const struct cache_entry *ce)\n \t\t\t       find_unique_abbrev(ce->oid.hash, abbrev),\n \t\t\t       ce_stage(ce));\n \t\t}\n-\t\twrite_eolinfo(&the_index, ce, ce->name);\n+\t\twrite_eolinfo(istate, ce, ce->name);\n \t\twrite_name(ce->name);\n \t\tif (debug_mode) {\n \t\t\tconst struct stat_data *sd = &ce->ce_stat_data;\n@@ -352,7 +353,7 @@ static void show_files(struct dir_struct *dir)\n \t\t\t\tcontinue;\n \t\t\tif (ce->ce_flags & CE_UPDATE)\n \t\t\t\tcontinue;\n-\t\t\tshow_ce_entry(ce_stage(ce) ? tag_unmerged :\n+\t\t\tshow_ce_entry(&the_index, ce_stage(ce) ? tag_unmerged :\n \t\t\t\t(ce_skip_worktree(ce) ? tag_skip_worktree : tag_cached), ce);\n \t\t}\n \t}\n@@ -370,9 +371,9 @@ static void show_files(struct dir_struct *dir)\n \t\t\t\tcontinue;\n \t\t\terr = lstat(ce->name, &st);\n \t\t\tif (show_deleted && err)\n-\t\t\t\tshow_ce_entry(tag_removed, ce);\n+\t\t\t\tshow_ce_entry(&the_index, tag_removed, ce);\n \t\t\tif (show_modified && ce_modified(ce, &st, 0))\n-\t\t\t\tshow_ce_entry(tag_modified, ce);\n+\t\t\t\tshow_ce_entry(&the_index, tag_modified, ce);\n \t\t}\n \t}\n }\n-- \n2.13.1.518.g3df882009-goog\n\n"},{"id":"322019","messageId":"20170612221408.173876-14-bmwill@google.com","threadId":"46163","inReplyTo":"20170612221408.173876-1-bmwill@google.com","subject":"[PATCH 13/17] ls-files: convert prune_cache to take an index","fromName":"Brandon Williams","fromEmail":"bmwill@google.com","sentAt":"2017-06-12T22:14:04Z","receivedAt":"2017-06-12T22:14:55Z","isPatch":true,"sender":{"key":"bwilliams.eng@gmail.com","avatar":null},"body":"Signed-off-by: Brandon Williams <bmwill@google.com>\n---\n builtin/ls-files.c | 15 ++++++++-------\n 1 file changed, 8 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin/ls-files.c b/builtin/ls-files.c\nindex 762257f39..b1626b13b 100644\n--- a/builtin/ls-files.c\n+++ b/builtin/ls-files.c\n@@ -380,30 +380,31 @@ static void show_files(struct dir_struct *dir)\n /*\n  * Prune the index to only contain stuff starting with \"prefix\"\n  */\n-static void prune_cache(const char *prefix, size_t prefixlen)\n+static void prune_index(struct index_state *istate,\n+\t\t\tconst char *prefix, size_t prefixlen)\n {\n \tint pos;\n \tunsigned int first, last;\n \n \tif (!prefix)\n \t\treturn;\n-\tpos = cache_name_pos(prefix, prefixlen);\n+\tpos = index_name_pos(istate, prefix, prefixlen);\n \tif (pos < 0)\n \t\tpos = -pos-1;\n \tfirst = pos;\n-\tlast = active_nr;\n+\tlast = istate->cache_nr;\n \twhile (last > first) {\n \t\tint next = (last + first) >> 1;\n-\t\tconst struct cache_entry *ce = active_cache[next];\n+\t\tconst struct cache_entry *ce = istate->cache[next];\n \t\tif (!strncmp(ce->name, prefix, prefixlen)) {\n \t\t\tfirst = next+1;\n \t\t\tcontinue;\n \t\t}\n \t\tlast = next;\n \t}\n-\tmemmove(active_cache, active_cache + pos,\n+\tmemmove(istate->cache, istate->cache + pos,\n \t\t(last - pos) * sizeof(struct cache_entry *));\n-\tactive_nr = last - pos;\n+\tistate->cache_nr = last - pos;\n }\n \n static int get_common_prefix_len(const char *common_prefix)\n@@ -661,7 +662,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)\n \t\tmax_prefix = common_prefix(&pathspec);\n \tmax_prefix_len = get_common_prefix_len(max_prefix);\n \n-\tprune_cache(max_prefix, max_prefix_len);\n+\tprune_index(&the_index, max_prefix, max_prefix_len);\n \n \t/* Treat unmatching pathspec elements as errors */\n \tif (pathspec.nr && error_unmatch)\n-- \n2.13.1.518.g3df882009-goog\n\n"},{"id":"322020","messageId":"20170612221408.173876-18-bmwill@google.com","threadId":"46163","inReplyTo":"20170612221408.173876-1-bmwill@google.com","subject":"[PATCH 17/17] ls-files: factor out tag calculation","fromName":"Brandon Williams","fromEmail":"bmwill@google.com","sentAt":"2017-06-12T22:14:08Z","receivedAt":"2017-06-12T22:14:56Z","isPatch":true,"sender":{"key":"bwilliams.eng@gmail.com","avatar":null},"body":"Signed-off-by: Brandon Williams <bmwill@google.com>\n---\n builtin/ls-files.c | 41 +++++++++++++++++++++++++----------------\n 1 file changed, 25 insertions(+), 16 deletions(-)\n\ndiff --git a/builtin/ls-files.c b/builtin/ls-files.c\nindex c9307f9ef..cdc1cfdd2 100644\n--- a/builtin/ls-files.c\n+++ b/builtin/ls-files.c\n@@ -93,6 +93,30 @@ static void write_name(const char *name)\n \tstrbuf_release(&full_name);\n }\n \n+static const char *get_tag(const struct cache_entry *ce, const char *tag)\n+{\n+\tstatic char alttag[4];\n+\n+\tif (tag && *tag && show_valid_bit && (ce->ce_flags & CE_VALID)) {\n+\t\tmemcpy(alttag, tag, 3);\n+\n+\t\tif (isalpha(tag[0])) {\n+\t\t\talttag[0] = tolower(tag[0]);\n+\t\t} else if (tag[0] == '?') {\n+\t\t\talttag[0] = '!';\n+\t\t} else {\n+\t\t\talttag[0] = 'v';\n+\t\t\talttag[1] = tag[0];\n+\t\t\talttag[2] = ' ';\n+\t\t\talttag[3] = 0;\n+\t\t}\n+\n+\t\ttag = alttag;\n+\t}\n+\n+\treturn tag;\n+}\n+\n static void print_debug(const struct cache_entry *ce)\n {\n \tif (debug_mode) {\n@@ -264,22 +288,7 @@ static void show_ce_entry(const struct index_state *istate,\n \t\t\t\t  len, ps_matched,\n \t\t\t\t  S_ISDIR(ce->ce_mode) ||\n \t\t\t\t  S_ISGITLINK(ce->ce_mode))) {\n-\t\tif (tag && *tag && show_valid_bit &&\n-\t\t    (ce->ce_flags & CE_VALID)) {\n-\t\t\tstatic char alttag[4];\n-\t\t\tmemcpy(alttag, tag, 3);\n-\t\t\tif (isalpha(tag[0]))\n-\t\t\t\talttag[0] = tolower(tag[0]);\n-\t\t\telse if (tag[0] == '?')\n-\t\t\t\talttag[0] = '!';\n-\t\t\telse {\n-\t\t\t\talttag[0] = 'v';\n-\t\t\t\talttag[1] = tag[0];\n-\t\t\t\talttag[2] = ' ';\n-\t\t\t\talttag[3] = 0;\n-\t\t\t}\n-\t\t\ttag = alttag;\n-\t\t}\n+\t\ttag = get_tag(ce, tag);\n \n \t\tif (!show_stage) {\n \t\t\tfputs(tag, stdout);\n-- \n2.13.1.518.g3df882009-goog\n\n"},{"id":"322021","messageId":"20170612221408.173876-13-bmwill@google.com","threadId":"46163","inReplyTo":"20170612221408.173876-1-bmwill@google.com","subject":"[PATCH 12/17] ls-files: convert ce_excluded to take an index","fromName":"Brandon Williams","fromEmail":"bmwill@google.com","sentAt":"2017-06-12T22:14:03Z","receivedAt":"2017-06-12T22:15:01Z","isPatch":true,"sender":{"key":"bwilliams.eng@gmail.com","avatar":null},"body":"Signed-off-by: Brandon Williams <bmwill@google.com>\n---\n builtin/ls-files.c | 9 +++++----\n 1 file changed, 5 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/ls-files.c b/builtin/ls-files.c\nindex 375fe09d1..762257f39 100644\n--- a/builtin/ls-files.c\n+++ b/builtin/ls-files.c\n@@ -321,10 +321,11 @@ static void show_ru_info(const struct index_state *istate)\n \t}\n }\n \n-static int ce_excluded(struct dir_struct *dir, const struct cache_entry *ce)\n+static int ce_excluded(struct dir_struct *dir, struct index_state *istate,\n+\t\t       const struct cache_entry *ce)\n {\n \tint dtype = ce_to_dtype(ce);\n-\treturn is_excluded(dir, &the_index, ce->name, &dtype);\n+\treturn is_excluded(dir, istate, ce->name, &dtype);\n }\n \n static void show_files(struct dir_struct *dir)\n@@ -345,7 +346,7 @@ static void show_files(struct dir_struct *dir)\n \t\tfor (i = 0; i < active_nr; i++) {\n \t\t\tconst struct cache_entry *ce = active_cache[i];\n \t\t\tif ((dir->flags & DIR_SHOW_IGNORED) &&\n-\t\t\t    !ce_excluded(dir, ce))\n+\t\t\t    !ce_excluded(dir, &the_index, ce))\n \t\t\t\tcontinue;\n \t\t\tif (show_unmerged && !ce_stage(ce))\n \t\t\t\tcontinue;\n@@ -361,7 +362,7 @@ static void show_files(struct dir_struct *dir)\n \t\t\tstruct stat st;\n \t\t\tint err;\n \t\t\tif ((dir->flags & DIR_SHOW_IGNORED) &&\n-\t\t\t    !ce_excluded(dir, ce))\n+\t\t\t    !ce_excluded(dir, &the_index, ce))\n \t\t\t\tcontinue;\n \t\t\tif (ce->ce_flags & CE_UPDATE)\n \t\t\t\tcontinue;\n-- \n2.13.1.518.g3df882009-goog\n\n"},{"id":"322022","messageId":"20170612221408.173876-16-bmwill@google.com","threadId":"46163","inReplyTo":"20170612221408.173876-1-bmwill@google.com","subject":"[PATCH 15/17] ls-files: convert show_files to take an index","fromName":"Brandon Williams","fromEmail":"bmwill@google.com","sentAt":"2017-06-12T22:14:06Z","receivedAt":"2017-06-12T22:15:02Z","isPatch":true,"sender":{"key":"bwilliams.eng@gmail.com","avatar":null},"body":"Signed-off-by: Brandon Williams <bmwill@google.com>\n---\n builtin/ls-files.c | 30 +++++++++++++++---------------\n 1 file changed, 15 insertions(+), 15 deletions(-)\n\ndiff --git a/builtin/ls-files.c b/builtin/ls-files.c\nindex 927aa6746..55d6f54fd 100644\n--- a/builtin/ls-files.c\n+++ b/builtin/ls-files.c\n@@ -329,7 +329,7 @@ static int ce_excluded(struct dir_struct *dir, struct index_state *istate,\n \treturn is_excluded(dir, istate, ce->name, &dtype);\n }\n \n-static void show_files(struct dir_struct *dir)\n+static void show_files(struct index_state *istate, struct dir_struct *dir)\n {\n \tint i;\n \n@@ -337,33 +337,33 @@ static void show_files(struct dir_struct *dir)\n \tif (show_others || show_killed) {\n \t\tif (!show_others)\n \t\t\tdir->flags |= DIR_COLLECT_KILLED_ONLY;\n-\t\tfill_directory(dir, &the_index, &pathspec);\n+\t\tfill_directory(dir, istate, &pathspec);\n \t\tif (show_others)\n-\t\t\tshow_other_files(&the_index, dir);\n+\t\t\tshow_other_files(istate, dir);\n \t\tif (show_killed)\n-\t\t\tshow_killed_files(&the_index, dir);\n+\t\t\tshow_killed_files(istate, dir);\n \t}\n \tif (show_cached || show_stage) {\n-\t\tfor (i = 0; i < active_nr; i++) {\n-\t\t\tconst struct cache_entry *ce = active_cache[i];\n+\t\tfor (i = 0; i < istate->cache_nr; i++) {\n+\t\t\tconst struct cache_entry *ce = istate->cache[i];\n \t\t\tif ((dir->flags & DIR_SHOW_IGNORED) &&\n-\t\t\t    !ce_excluded(dir, &the_index, ce))\n+\t\t\t    !ce_excluded(dir, istate, ce))\n \t\t\t\tcontinue;\n \t\t\tif (show_unmerged && !ce_stage(ce))\n \t\t\t\tcontinue;\n \t\t\tif (ce->ce_flags & CE_UPDATE)\n \t\t\t\tcontinue;\n-\t\t\tshow_ce_entry(&the_index, ce_stage(ce) ? tag_unmerged :\n+\t\t\tshow_ce_entry(istate, ce_stage(ce) ? tag_unmerged :\n \t\t\t\t(ce_skip_worktree(ce) ? tag_skip_worktree : tag_cached), ce);\n \t\t}\n \t}\n \tif (show_deleted || show_modified) {\n-\t\tfor (i = 0; i < active_nr; i++) {\n-\t\t\tconst struct cache_entry *ce = active_cache[i];\n+\t\tfor (i = 0; i < istate->cache_nr; i++) {\n+\t\t\tconst struct cache_entry *ce = istate->cache[i];\n \t\t\tstruct stat st;\n \t\t\tint err;\n \t\t\tif ((dir->flags & DIR_SHOW_IGNORED) &&\n-\t\t\t    !ce_excluded(dir, &the_index, ce))\n+\t\t\t    !ce_excluded(dir, istate, ce))\n \t\t\t\tcontinue;\n \t\t\tif (ce->ce_flags & CE_UPDATE)\n \t\t\t\tcontinue;\n@@ -371,9 +371,9 @@ static void show_files(struct dir_struct *dir)\n \t\t\t\tcontinue;\n \t\t\terr = lstat(ce->name, &st);\n \t\t\tif (show_deleted && err)\n-\t\t\t\tshow_ce_entry(&the_index, tag_removed, ce);\n-\t\t\tif (show_modified && ce_modified(ce, &st, 0))\n-\t\t\t\tshow_ce_entry(&the_index, tag_modified, ce);\n+\t\t\t\tshow_ce_entry(istate, tag_removed, ce);\n+\t\t\tif (show_modified && ie_modified(istate, ce, &st, 0))\n+\t\t\t\tshow_ce_entry(istate, tag_modified, ce);\n \t\t}\n \t}\n }\n@@ -686,7 +686,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)\n \t\t\tdie(\"ls-files --with-tree is incompatible with -s or -u\");\n \t\toverlay_tree_on_index(&the_index, with_tree, max_prefix);\n \t}\n-\tshow_files(&dir);\n+\tshow_files(&the_index, &dir);\n \tif (show_resolve_undo)\n \t\tshow_ru_info(&the_index);\n \n-- \n2.13.1.518.g3df882009-goog\n\n"},{"id":"322023","messageId":"20170612221408.173876-10-bmwill@google.com","threadId":"46163","inReplyTo":"20170612221408.173876-1-bmwill@google.com","subject":"[PATCH 09/17] ls-files: convert show_killed_files to take an index","fromName":"Brandon Williams","fromEmail":"bmwill@google.com","sentAt":"2017-06-12T22:14:00Z","receivedAt":"2017-06-12T22:15:04Z","isPatch":true,"sender":{"key":"bwilliams.eng@gmail.com","avatar":null},"body":"Signed-off-by: Brandon Williams <bmwill@google.com>\n---\n builtin/ls-files.c | 21 +++++++++++----------\n 1 file changed, 11 insertions(+), 10 deletions(-)\n\ndiff --git a/builtin/ls-files.c b/builtin/ls-files.c\nindex 8c3f3d8ca..b82b78036 100644\n--- a/builtin/ls-files.c\n+++ b/builtin/ls-files.c\n@@ -120,7 +120,8 @@ static void show_other_files(struct dir_struct *dir)\n \t}\n }\n \n-static void show_killed_files(struct dir_struct *dir)\n+static void show_killed_files(const struct index_state *istate,\n+\t\t\t      const struct dir_struct *dir)\n {\n \tint i;\n \tfor (i = 0; i < dir->nr; i++) {\n@@ -134,29 +135,29 @@ static void show_killed_files(struct dir_struct *dir)\n \t\t\t\t/* If ent->name is prefix of an entry in the\n \t\t\t\t * cache, it will be killed.\n \t\t\t\t */\n-\t\t\t\tpos = cache_name_pos(ent->name, ent->len);\n+\t\t\t\tpos = index_name_pos(istate, ent->name, ent->len);\n \t\t\t\tif (0 <= pos)\n \t\t\t\t\tdie(\"BUG: killed-file %.*s not found\",\n \t\t\t\t\t\tent->len, ent->name);\n \t\t\t\tpos = -pos - 1;\n-\t\t\t\twhile (pos < active_nr &&\n-\t\t\t\t       ce_stage(active_cache[pos]))\n+\t\t\t\twhile (pos < istate->cache_nr &&\n+\t\t\t\t       ce_stage(istate->cache[pos]))\n \t\t\t\t\tpos++; /* skip unmerged */\n-\t\t\t\tif (active_nr <= pos)\n+\t\t\t\tif (istate->cache_nr <= pos)\n \t\t\t\t\tbreak;\n \t\t\t\t/* pos points at a name immediately after\n \t\t\t\t * ent->name in the cache.  Does it expect\n \t\t\t\t * ent->name to be a directory?\n \t\t\t\t */\n-\t\t\t\tlen = ce_namelen(active_cache[pos]);\n+\t\t\t\tlen = ce_namelen(istate->cache[pos]);\n \t\t\t\tif ((ent->len < len) &&\n-\t\t\t\t    !strncmp(active_cache[pos]->name,\n+\t\t\t\t    !strncmp(istate->cache[pos]->name,\n \t\t\t\t\t     ent->name, ent->len) &&\n-\t\t\t\t    active_cache[pos]->name[ent->len] == '/')\n+\t\t\t\t    istate->cache[pos]->name[ent->len] == '/')\n \t\t\t\t\tkilled = 1;\n \t\t\t\tbreak;\n \t\t\t}\n-\t\t\tif (0 <= cache_name_pos(ent->name, sp - ent->name)) {\n+\t\t\tif (0 <= index_name_pos(istate, ent->name, sp - ent->name)) {\n \t\t\t\t/* If any of the leading directories in\n \t\t\t\t * ent->name is registered in the cache,\n \t\t\t\t * ent->name will be killed.\n@@ -337,7 +338,7 @@ static void show_files(struct dir_struct *dir)\n \t\tif (show_others)\n \t\t\tshow_other_files(dir);\n \t\tif (show_killed)\n-\t\t\tshow_killed_files(dir);\n+\t\t\tshow_killed_files(&the_index, dir);\n \t}\n \tif (show_cached || show_stage) {\n \t\tfor (i = 0; i < active_nr; i++) {\n-- \n2.13.1.518.g3df882009-goog\n\n"},{"id":"322024","messageId":"20170612221408.173876-17-bmwill@google.com","threadId":"46163","inReplyTo":"20170612221408.173876-1-bmwill@google.com","subject":"[PATCH 16/17] ls-files: factor out debug info into a function","fromName":"Brandon Williams","fromEmail":"bmwill@google.com","sentAt":"2017-06-12T22:14:07Z","receivedAt":"2017-06-12T22:15:05Z","isPatch":true,"sender":{"key":"bwilliams.eng@gmail.com","avatar":null},"body":"Signed-off-by: Brandon Williams <bmwill@google.com>\n---\n builtin/ls-files.c | 23 ++++++++++++++---------\n 1 file changed, 14 insertions(+), 9 deletions(-)\n\ndiff --git a/builtin/ls-files.c b/builtin/ls-files.c\nindex 55d6f54fd..c9307f9ef 100644\n--- a/builtin/ls-files.c\n+++ b/builtin/ls-files.c\n@@ -93,6 +93,19 @@ static void write_name(const char *name)\n \tstrbuf_release(&full_name);\n }\n \n+static void print_debug(const struct cache_entry *ce)\n+{\n+\tif (debug_mode) {\n+\t\tconst struct stat_data *sd = &ce->ce_stat_data;\n+\n+\t\tprintf(\"  ctime: %d:%d\\n\", sd->sd_ctime.sec, sd->sd_ctime.nsec);\n+\t\tprintf(\"  mtime: %d:%d\\n\", sd->sd_mtime.sec, sd->sd_mtime.nsec);\n+\t\tprintf(\"  dev: %d\\tino: %d\\n\", sd->sd_dev, sd->sd_ino);\n+\t\tprintf(\"  uid: %d\\tgid: %d\\n\", sd->sd_uid, sd->sd_gid);\n+\t\tprintf(\"  size: %d\\tflags: %x\\n\", sd->sd_size, ce->ce_flags);\n+\t}\n+}\n+\n static void show_dir_entry(const char *tag, struct dir_entry *ent)\n {\n \tint len = max_prefix_len;\n@@ -279,15 +292,7 @@ static void show_ce_entry(const struct index_state *istate,\n \t\t}\n \t\twrite_eolinfo(istate, ce, ce->name);\n \t\twrite_name(ce->name);\n-\t\tif (debug_mode) {\n-\t\t\tconst struct stat_data *sd = &ce->ce_stat_data;\n-\n-\t\t\tprintf(\"  ctime: %d:%d\\n\", sd->sd_ctime.sec, sd->sd_ctime.nsec);\n-\t\t\tprintf(\"  mtime: %d:%d\\n\", sd->sd_mtime.sec, sd->sd_mtime.nsec);\n-\t\t\tprintf(\"  dev: %d\\tino: %d\\n\", sd->sd_dev, sd->sd_ino);\n-\t\t\tprintf(\"  uid: %d\\tgid: %d\\n\", sd->sd_uid, sd->sd_gid);\n-\t\t\tprintf(\"  size: %d\\tflags: %x\\n\", sd->sd_size, ce->ce_flags);\n-\t\t}\n+\t\tprint_debug(ce);\n \t}\n \n \tstrbuf_release(&name);\n-- \n2.13.1.518.g3df882009-goog\n\n"},{"id":"322025","messageId":"20170612221408.173876-11-bmwill@google.com","threadId":"46163","inReplyTo":"20170612221408.173876-1-bmwill@google.com","subject":"[PATCH 10/17] ls-files: convert show_other_files to take an index","fromName":"Brandon Williams","fromEmail":"bmwill@google.com","sentAt":"2017-06-12T22:14:01Z","receivedAt":"2017-06-12T22:15:06Z","isPatch":true,"sender":{"key":"bwilliams.eng@gmail.com","avatar":null},"body":"Signed-off-by: Brandon Williams <bmwill@google.com>\n---\n builtin/ls-files.c | 7 ++++---\n 1 file changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/ls-files.c b/builtin/ls-files.c\nindex b82b78036..5dbff9496 100644\n--- a/builtin/ls-files.c\n+++ b/builtin/ls-files.c\n@@ -108,13 +108,14 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent)\n \twrite_name(ent->name);\n }\n \n-static void show_other_files(struct dir_struct *dir)\n+static void show_other_files(const struct index_state *istate,\n+\t\t\t     const struct dir_struct *dir)\n {\n \tint i;\n \n \tfor (i = 0; i < dir->nr; i++) {\n \t\tstruct dir_entry *ent = dir->entries[i];\n-\t\tif (!cache_name_is_other(ent->name, ent->len))\n+\t\tif (!index_name_is_other(istate, ent->name, ent->len))\n \t\t\tcontinue;\n \t\tshow_dir_entry(tag_other, ent);\n \t}\n@@ -336,7 +337,7 @@ static void show_files(struct dir_struct *dir)\n \t\t\tdir->flags |= DIR_COLLECT_KILLED_ONLY;\n \t\tfill_directory(dir, &the_index, &pathspec);\n \t\tif (show_others)\n-\t\t\tshow_other_files(dir);\n+\t\t\tshow_other_files(&the_index, dir);\n \t\tif (show_killed)\n \t\t\tshow_killed_files(&the_index, dir);\n \t}\n-- \n2.13.1.518.g3df882009-goog\n\n"},{"id":"322026","messageId":"20170612221408.173876-6-bmwill@google.com","threadId":"46163","inReplyTo":"20170612221408.173876-1-bmwill@google.com","subject":"[PATCH 05/17] convert: convert renormalize_buffer to take an index","fromName":"Brandon Williams","fromEmail":"bmwill@google.com","sentAt":"2017-06-12T22:13:56Z","receivedAt":"2017-06-12T22:15:25Z","isPatch":true,"sender":{"key":"bwilliams.eng@gmail.com","avatar":null},"body":"Signed-off-by: Brandon Williams <bmwill@google.com>\n---\n convert.c         | 6 ++++--\n convert.h         | 3 ++-\n ll-merge.c        | 2 +-\n merge-recursive.c | 4 ++--\n 4 files changed, 9 insertions(+), 6 deletions(-)\n\ndiff --git a/convert.c b/convert.c\nindex 600d11e73..4097f521f 100644\n--- a/convert.c\n+++ b/convert.c\n@@ -1,3 +1,4 @@\n+#define NO_THE_INDEX_COMPATIBILITY_MACROS\n #include \"cache.h\"\n #include \"attr.h\"\n #include \"run-command.h\"\n@@ -1165,14 +1166,15 @@ int convert_to_working_tree(const char *path, const char *src, size_t len, struc\n \treturn convert_to_working_tree_internal(path, src, len, dst, 0);\n }\n \n-int renormalize_buffer(const char *path, const char *src, size_t len, struct strbuf *dst)\n+int renormalize_buffer(const struct index_state *istate, const char *path,\n+\t\t       const char *src, size_t len, struct strbuf *dst)\n {\n \tint ret = convert_to_working_tree_internal(path, src, len, dst, 1);\n \tif (ret) {\n \t\tsrc = dst->buf;\n \t\tlen = dst->len;\n \t}\n-\treturn ret | convert_to_git(&the_index, path, src, len, dst, SAFE_CRLF_RENORMALIZE);\n+\treturn ret | convert_to_git(istate, path, src, len, dst, SAFE_CRLF_RENORMALIZE);\n }\n \n /*****************************************************************\ndiff --git a/convert.h b/convert.h\nindex 60cb41d6a..cecf59d1a 100644\n--- a/convert.h\n+++ b/convert.h\n@@ -46,7 +46,8 @@ extern int convert_to_git(const struct index_state *istate,\n \t\t\t  struct strbuf *dst, enum safe_crlf checksafe);\n extern int convert_to_working_tree(const char *path, const char *src,\n \t\t\t\t   size_t len, struct strbuf *dst);\n-extern int renormalize_buffer(const char *path, const char *src, size_t len,\n+extern int renormalize_buffer(const struct index_state *istate,\n+\t\t\t      const char *path, const char *src, size_t len,\n \t\t\t      struct strbuf *dst);\n static inline int would_convert_to_git(const struct index_state *istate,\n \t\t\t\t       const char *path)\ndiff --git a/ll-merge.c b/ll-merge.c\nindex ac0d4a5d7..d7eafb61a 100644\n--- a/ll-merge.c\n+++ b/ll-merge.c\n@@ -339,7 +339,7 @@ static const struct ll_merge_driver *find_ll_merge_driver(const char *merge_attr\n static void normalize_file(mmfile_t *mm, const char *path)\n {\n \tstruct strbuf strbuf = STRBUF_INIT;\n-\tif (renormalize_buffer(path, mm->ptr, mm->size, &strbuf)) {\n+\tif (renormalize_buffer(&the_index, path, mm->ptr, mm->size, &strbuf)) {\n \t\tfree(mm->ptr);\n \t\tmm->size = strbuf.len;\n \t\tmm->ptr = strbuf_detach(&strbuf, NULL);\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex ae5238d82..eac12d488 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -1639,8 +1639,8 @@ static int blob_unchanged(struct merge_options *opt,\n \t * performed.  Comparison can be skipped if both files are\n \t * unchanged since their sha1s have already been compared.\n \t */\n-\tif (renormalize_buffer(path, o.buf, o.len, &o) |\n-\t    renormalize_buffer(path, a.buf, a.len, &a))\n+\tif (renormalize_buffer(&the_index, path, o.buf, o.len, &o) |\n+\t    renormalize_buffer(&the_index, path, a.buf, a.len, &a))\n \t\tret = (o.len == a.len && !memcmp(o.buf, a.buf, o.len));\n \n error_return:\n-- \n2.13.1.518.g3df882009-goog\n\n"},{"id":"322027","messageId":"20170612221408.173876-9-bmwill@google.com","threadId":"46163","inReplyTo":"20170612221408.173876-1-bmwill@google.com","subject":"[PATCH 08/17] ls-files: convert write_eolinfo to take an index","fromName":"Brandon Williams","fromEmail":"bmwill@google.com","sentAt":"2017-06-12T22:13:59Z","receivedAt":"2017-06-12T22:15:26Z","isPatch":true,"sender":{"key":"bwilliams.eng@gmail.com","avatar":null},"body":"Signed-off-by: Brandon Williams <bmwill@google.com>\n---\n builtin/ls-files.c | 13 ++++++-------\n 1 file changed, 6 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin/ls-files.c b/builtin/ls-files.c\nindex a78b291ab..8c3f3d8ca 100644\n--- a/builtin/ls-files.c\n+++ b/builtin/ls-files.c\n@@ -53,17 +53,16 @@ static const char *tag_modified = \"\";\n static const char *tag_skip_worktree = \"\";\n static const char *tag_resolve_undo = \"\";\n \n-static void write_eolinfo(const struct cache_entry *ce, const char *path)\n+static void write_eolinfo(const struct index_state *istate,\n+\t\t\t  const struct cache_entry *ce, const char *path)\n {\n-\tif (!show_eol)\n-\t\treturn;\n-\telse {\n+\tif (show_eol) {\n \t\tstruct stat st;\n \t\tconst char *i_txt = \"\";\n \t\tconst char *w_txt = \"\";\n \t\tconst char *a_txt = get_convert_attr_ascii(path);\n \t\tif (ce && S_ISREG(ce->ce_mode))\n-\t\t\ti_txt = get_cached_convert_stats_ascii(&the_index,\n+\t\t\ti_txt = get_cached_convert_stats_ascii(istate,\n \t\t\t\t\t\t\t       ce->name);\n \t\tif (!lstat(path, &st) && S_ISREG(st.st_mode))\n \t\t\tw_txt = get_wt_convert_stats_ascii(path);\n@@ -105,7 +104,7 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent)\n \t\treturn;\n \n \tfputs(tag, stdout);\n-\twrite_eolinfo(NULL, ent->name);\n+\twrite_eolinfo(NULL, NULL, ent->name);\n \twrite_name(ent->name);\n }\n \n@@ -275,7 +274,7 @@ static void show_ce_entry(const char *tag, const struct cache_entry *ce)\n \t\t\t       find_unique_abbrev(ce->oid.hash, abbrev),\n \t\t\t       ce_stage(ce));\n \t\t}\n-\t\twrite_eolinfo(ce, ce->name);\n+\t\twrite_eolinfo(&the_index, ce, ce->name);\n \t\twrite_name(ce->name);\n \t\tif (debug_mode) {\n \t\t\tconst struct stat_data *sd = &ce->ce_stat_data;\n-- \n2.13.1.518.g3df882009-goog\n\n"},{"id":"322028","messageId":"20170612221408.173876-7-bmwill@google.com","threadId":"46163","inReplyTo":"20170612221408.173876-1-bmwill@google.com","subject":"[PATCH 06/17] tree: convert read_tree to take an index parameter","fromName":"Brandon Williams","fromEmail":"bmwill@google.com","sentAt":"2017-06-12T22:13:57Z","receivedAt":"2017-06-12T22:15:28Z","isPatch":true,"sender":{"key":"bwilliams.eng@gmail.com","avatar":null},"body":"Signed-off-by: Brandon Williams <bmwill@google.com>\n---\n builtin/ls-files.c |  2 +-\n tree.c             | 28 ++++++++++++++++++----------\n tree.h             |  3 ++-\n 3 files changed, 21 insertions(+), 12 deletions(-)\n\ndiff --git a/builtin/ls-files.c b/builtin/ls-files.c\nindex 0044abf66..93e46ab5f 100644\n--- a/builtin/ls-files.c\n+++ b/builtin/ls-files.c\n@@ -460,7 +460,7 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix)\n \t\t\t       PATHSPEC_PREFER_CWD, prefix, matchbuf);\n \t} else\n \t\tmemset(&pathspec, 0, sizeof(pathspec));\n-\tif (read_tree(tree, 1, &pathspec))\n+\tif (read_tree(tree, 1, &pathspec, &the_index))\n \t\tdie(\"unable to read tree entries %s\", tree_name);\n \n \tfor (i = 0; i < active_nr; i++) {\ndiff --git a/tree.c b/tree.c\nindex 603b29ee8..dd69423d9 100644\n--- a/tree.c\n+++ b/tree.c\n@@ -1,3 +1,4 @@\n+#define NO_THE_INDEX_COMPATIBILITY_MACROS\n #include \"cache.h\"\n #include \"cache-tree.h\"\n #include \"tree.h\"\n@@ -8,7 +9,11 @@\n \n const char *tree_type = \"tree\";\n \n-static int read_one_entry_opt(const unsigned char *sha1, const char *base, int baselen, const char *pathname, unsigned mode, int stage, int opt)\n+static int read_one_entry_opt(struct index_state *istate,\n+\t\t\t      const unsigned char *sha1,\n+\t\t\t      const char *base, int baselen,\n+\t\t\t      const char *pathname,\n+\t\t\t      unsigned mode, int stage, int opt)\n {\n \tint len;\n \tunsigned int size;\n@@ -27,14 +32,15 @@ static int read_one_entry_opt(const unsigned char *sha1, const char *base, int b\n \tmemcpy(ce->name, base, baselen);\n \tmemcpy(ce->name + baselen, pathname, len+1);\n \thashcpy(ce->oid.hash, sha1);\n-\treturn add_cache_entry(ce, opt);\n+\treturn add_index_entry(istate, ce, opt);\n }\n \n static int read_one_entry(const unsigned char *sha1, struct strbuf *base,\n \t\t\t  const char *pathname, unsigned mode, int stage,\n \t\t\t  void *context)\n {\n-\treturn read_one_entry_opt(sha1, base->buf, base->len, pathname,\n+\tstruct index_state *istate = context;\n+\treturn read_one_entry_opt(istate, sha1, base->buf, base->len, pathname,\n \t\t\t\t  mode, stage,\n \t\t\t\t  ADD_CACHE_OK_TO_ADD|ADD_CACHE_SKIP_DFCHECK);\n }\n@@ -47,7 +53,8 @@ static int read_one_entry_quick(const unsigned char *sha1, struct strbuf *base,\n \t\t\t\tconst char *pathname, unsigned mode, int stage,\n \t\t\t\tvoid *context)\n {\n-\treturn read_one_entry_opt(sha1, base->buf, base->len, pathname,\n+\tstruct index_state *istate = context;\n+\treturn read_one_entry_opt(istate, sha1, base->buf, base->len, pathname,\n \t\t\t\t  mode, stage,\n \t\t\t\t  ADD_CACHE_JUST_APPEND);\n }\n@@ -144,7 +151,8 @@ static int cmp_cache_name_compare(const void *a_, const void *b_)\n \t\t\t\t  ce2->name, ce2->ce_namelen, ce_stage(ce2));\n }\n \n-int read_tree(struct tree *tree, int stage, struct pathspec *match)\n+int read_tree(struct tree *tree, int stage, struct pathspec *match,\n+\t      struct index_state *istate)\n {\n \tread_tree_fn_t fn = NULL;\n \tint i, err;\n@@ -164,23 +172,23 @@ int read_tree(struct tree *tree, int stage, struct pathspec *match)\n \t * do it the original slow way, otherwise, append and then\n \t * sort at the end.\n \t */\n-\tfor (i = 0; !fn && i < active_nr; i++) {\n-\t\tconst struct cache_entry *ce = active_cache[i];\n+\tfor (i = 0; !fn && i < istate->cache_nr; i++) {\n+\t\tconst struct cache_entry *ce = istate->cache[i];\n \t\tif (ce_stage(ce) == stage)\n \t\t\tfn = read_one_entry;\n \t}\n \n \tif (!fn)\n \t\tfn = read_one_entry_quick;\n-\terr = read_tree_recursive(tree, \"\", 0, stage, match, fn, NULL);\n+\terr = read_tree_recursive(tree, \"\", 0, stage, match, fn, istate);\n \tif (fn == read_one_entry || err)\n \t\treturn err;\n \n \t/*\n \t * Sort the cache entry -- we need to nuke the cache tree, though.\n \t */\n-\tcache_tree_free(&active_cache_tree);\n-\tQSORT(active_cache, active_nr, cmp_cache_name_compare);\n+\tcache_tree_free(&istate->cache_tree);\n+\tQSORT(istate->cache, istate->cache_nr, cmp_cache_name_compare);\n \treturn 0;\n }\n \ndiff --git a/tree.h b/tree.h\nindex 0d4734b94..744e6dc2a 100644\n--- a/tree.h\n+++ b/tree.h\n@@ -34,6 +34,7 @@ extern int read_tree_recursive(struct tree *tree,\n \t\t\t       int stage, const struct pathspec *pathspec,\n \t\t\t       read_tree_fn_t fn, void *context);\n \n-extern int read_tree(struct tree *tree, int stage, struct pathspec *pathspec);\n+extern int read_tree(struct tree *tree, int stage, struct pathspec *pathspec,\n+\t\t     struct index_state *istate);\n \n #endif /* TREE_H */\n-- \n2.13.1.518.g3df882009-goog\n\n"},{"id":"322029","messageId":"20170612221408.173876-12-bmwill@google.com","threadId":"46163","inReplyTo":"20170612221408.173876-1-bmwill@google.com","subject":"[PATCH 11/17] ls-files: convert show_ru_info to take an index","fromName":"Brandon Williams","fromEmail":"bmwill@google.com","sentAt":"2017-06-12T22:14:02Z","receivedAt":"2017-06-12T22:15:29Z","isPatch":true,"sender":{"key":"bwilliams.eng@gmail.com","avatar":null},"body":"Signed-off-by: Brandon Williams <bmwill@google.com>\n---\n builtin/ls-files.c | 8 ++++----\n 1 file changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/ls-files.c b/builtin/ls-files.c\nindex 5dbff9496..375fe09d1 100644\n--- a/builtin/ls-files.c\n+++ b/builtin/ls-files.c\n@@ -292,14 +292,14 @@ static void show_ce_entry(const char *tag, const struct cache_entry *ce)\n \tstrbuf_release(&name);\n }\n \n-static void show_ru_info(void)\n+static void show_ru_info(const struct index_state *istate)\n {\n \tstruct string_list_item *item;\n \n-\tif (!the_index.resolve_undo)\n+\tif (!istate->resolve_undo)\n \t\treturn;\n \n-\tfor_each_string_list_item(item, the_index.resolve_undo) {\n+\tfor_each_string_list_item(item, istate->resolve_undo) {\n \t\tconst char *path = item->string;\n \t\tstruct resolve_undo_info *ui = item->util;\n \t\tint i, len;\n@@ -685,7 +685,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)\n \t}\n \tshow_files(&dir);\n \tif (show_resolve_undo)\n-\t\tshow_ru_info();\n+\t\tshow_ru_info(&the_index);\n \n \tif (ps_matched) {\n \t\tint bad;\n-- \n2.13.1.518.g3df882009-goog\n\n"}]}