From a7609c54b399219bae5b8b94b305cf8e18bf20f8 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 12 Jun 2017 15:13:52 -0700 Subject: convert: convert get_cached_convert_stats_ascii to take an index Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano diff --git a/builtin/ls-files.c b/builtin/ls-files.c index b376afc..0044abf 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -63,7 +63,8 @@ static void write_eolinfo(const struct cache_entry *ce, const char *path) const char *w_txt = ""; const char *a_txt = get_convert_attr_ascii(path); if (ce && S_ISREG(ce->ce_mode)) - i_txt = get_cached_convert_stats_ascii(ce->name); + i_txt = get_cached_convert_stats_ascii(&the_index, + ce->name); if (!lstat(path, &st) && S_ISREG(st.st_mode)) w_txt = get_wt_convert_stats_ascii(path); printf("i/%-5s w/%-5s attr/%-17s\t", i_txt, w_txt, a_txt); diff --git a/convert.c b/convert.c index f1e168b..03160b3 100644 --- a/convert.c +++ b/convert.c @@ -134,11 +134,12 @@ static const char *gather_convert_stats_ascii(const char *data, unsigned long si } } -const char *get_cached_convert_stats_ascii(const char *path) +const char *get_cached_convert_stats_ascii(const struct index_state *istate, + const char *path) { const char *ret; unsigned long sz; - void *data = read_blob_data_from_cache(path, &sz); + void *data = read_blob_data_from_index(istate, path, &sz); ret = gather_convert_stats_ascii(data, sz); free(data); return ret; diff --git a/convert.h b/convert.h index 82871a1..667b7df 100644 --- a/convert.h +++ b/convert.h @@ -4,6 +4,8 @@ #ifndef CONVERT_H #define CONVERT_H +struct index_state; + enum safe_crlf { SAFE_CRLF_FALSE = 0, SAFE_CRLF_FAIL = 1, @@ -33,7 +35,8 @@ enum eol { }; extern enum eol core_eol; -extern const char *get_cached_convert_stats_ascii(const char *path); +extern const char *get_cached_convert_stats_ascii(const struct index_state *istate, + const char *path); extern const char *get_wt_convert_stats_ascii(const char *path); extern const char *get_convert_attr_ascii(const char *path); -- cgit v0.10.2-6-g49f6 From 49a6d31fc8c4277b1c5f5b82331e7190afa1d4ce Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 12 Jun 2017 15:13:53 -0700 Subject: convert: convert crlf_to_git to take an index Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano diff --git a/convert.c b/convert.c index 03160b3..0cafb06 100644 --- a/convert.c +++ b/convert.c @@ -218,13 +218,13 @@ static void check_safe_crlf(const char *path, enum crlf_action crlf_action, } } -static int has_cr_in_index(const char *path) +static int has_cr_in_index(const struct index_state *istate, const char *path) { unsigned long sz; void *data; int has_cr; - data = read_blob_data_from_cache(path, &sz); + data = read_blob_data_from_index(istate, path, &sz); if (!data) return 0; has_cr = memchr(data, '\r', sz) != NULL; @@ -254,7 +254,8 @@ static int will_convert_lf_to_crlf(size_t len, struct text_stat *stats, } -static int crlf_to_git(const char *path, const char *src, size_t len, +static int crlf_to_git(const struct index_state *istate, + const char *path, const char *src, size_t len, struct strbuf *buf, enum crlf_action crlf_action, enum safe_crlf checksafe) { @@ -286,7 +287,8 @@ static int crlf_to_git(const char *path, const char *src, size_t len, * unless we want to renormalize in a merge or * cherry-pick. */ - if ((checksafe != SAFE_CRLF_RENORMALIZE) && has_cr_in_index(path)) + if ((checksafe != SAFE_CRLF_RENORMALIZE) && + has_cr_in_index(istate, path)) convert_crlf_into_lf = 0; } if ((checksafe == SAFE_CRLF_WARN || @@ -1098,7 +1100,7 @@ int convert_to_git(const char *path, const char *src, size_t len, src = dst->buf; len = dst->len; } - ret |= crlf_to_git(path, src, len, dst, ca.crlf_action, checksafe); + ret |= crlf_to_git(&the_index, path, src, len, dst, ca.crlf_action, checksafe); if (ret && dst) { src = dst->buf; len = dst->len; @@ -1118,7 +1120,7 @@ void convert_to_git_filter_fd(const char *path, int fd, struct strbuf *dst, if (!apply_filter(path, NULL, 0, fd, dst, ca.drv, CAP_CLEAN)) die("%s: clean filter '%s' failed", path, ca.drv->name); - crlf_to_git(path, dst->buf, dst->len, dst, ca.crlf_action, checksafe); + crlf_to_git(&the_index, path, dst->buf, dst->len, dst, ca.crlf_action, checksafe); ident_to_git(path, dst->buf, dst->len, dst, ca.ident); } -- cgit v0.10.2-6-g49f6 From d6c41c20e688a1b284b92d92320ba56f639688de Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 12 Jun 2017 15:13:54 -0700 Subject: convert: convert convert_to_git_filter_fd to take an index Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano diff --git a/convert.c b/convert.c index 0cafb06..c09242c 100644 --- a/convert.c +++ b/convert.c @@ -1108,7 +1108,8 @@ int convert_to_git(const char *path, const char *src, size_t len, return ret | ident_to_git(path, src, len, dst, ca.ident); } -void convert_to_git_filter_fd(const char *path, int fd, struct strbuf *dst, +void convert_to_git_filter_fd(const struct index_state *istate, + const char *path, int fd, struct strbuf *dst, enum safe_crlf checksafe) { struct conv_attrs ca; @@ -1120,7 +1121,7 @@ void convert_to_git_filter_fd(const char *path, int fd, struct strbuf *dst, if (!apply_filter(path, NULL, 0, fd, dst, ca.drv, CAP_CLEAN)) die("%s: clean filter '%s' failed", path, ca.drv->name); - crlf_to_git(&the_index, path, dst->buf, dst->len, dst, ca.crlf_action, checksafe); + crlf_to_git(istate, path, dst->buf, dst->len, dst, ca.crlf_action, checksafe); ident_to_git(path, dst->buf, dst->len, dst, ca.ident); } diff --git a/convert.h b/convert.h index 667b7df..3a813a7 100644 --- a/convert.h +++ b/convert.h @@ -52,7 +52,8 @@ static inline int would_convert_to_git(const char *path) return convert_to_git(path, NULL, 0, NULL, 0); } /* Precondition: would_convert_to_git_filter_fd(path) == true */ -extern void convert_to_git_filter_fd(const char *path, int fd, +extern void convert_to_git_filter_fd(const struct index_state *istate, + const char *path, int fd, struct strbuf *dst, enum safe_crlf checksafe); extern int would_convert_to_git_filter_fd(const char *path); diff --git a/sha1_file.c b/sha1_file.c index 59a4ed2..ab09241 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -3580,7 +3580,7 @@ static int index_stream_convert_blob(unsigned char *sha1, int fd, assert(path); assert(would_convert_to_git_filter_fd(path)); - convert_to_git_filter_fd(path, fd, &sbuf, + convert_to_git_filter_fd(&the_index, path, fd, &sbuf, write_object ? safe_crlf : SAFE_CRLF_FALSE); if (write_object) -- cgit v0.10.2-6-g49f6 From 82b474e025e89cfa294e81611c81355a73dc23a2 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 12 Jun 2017 15:13:55 -0700 Subject: convert: convert convert_to_git to take an index Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano diff --git a/apply.c b/apply.c index c49cef0..97afb6f 100644 --- a/apply.c +++ b/apply.c @@ -2267,7 +2267,7 @@ static int read_old_data(struct stat *st, const char *path, struct strbuf *buf) case S_IFREG: if (strbuf_read_file(buf, path, st->st_size) != st->st_size) return error(_("unable to open or read %s"), path); - convert_to_git(path, buf->buf, buf->len, buf, 0); + convert_to_git(&the_index, path, buf->buf, buf->len, buf, 0); return 0; default: return -1; diff --git a/blame.c b/blame.c index 843c845..a6f3d72 100644 --- a/blame.c +++ b/blame.c @@ -229,7 +229,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt, if (strbuf_read(&buf, 0, 0) < 0) die_errno("failed to read from stdin"); } - convert_to_git(path, buf.buf, buf.len, &buf, 0); + convert_to_git(&the_index, path, buf.buf, buf.len, &buf, 0); origin->file.ptr = buf.buf; origin->file.size = buf.len; pretend_sha1_file(buf.buf, buf.len, OBJ_BLOB, origin->blob_oid.hash); diff --git a/combine-diff.c b/combine-diff.c index 2848034..74f723a 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -1053,7 +1053,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent, if (is_file) { struct strbuf buf = STRBUF_INIT; - if (convert_to_git(elem->path, result, len, &buf, safe_crlf)) { + if (convert_to_git(&the_index, elem->path, result, len, &buf, safe_crlf)) { free(result); result = strbuf_detach(&buf, &len); result_size = len; diff --git a/convert.c b/convert.c index c09242c..600d11e 100644 --- a/convert.c +++ b/convert.c @@ -1084,7 +1084,8 @@ const char *get_convert_attr_ascii(const char *path) return ""; } -int convert_to_git(const char *path, const char *src, size_t len, +int convert_to_git(const struct index_state *istate, + const char *path, const char *src, size_t len, struct strbuf *dst, enum safe_crlf checksafe) { int ret = 0; @@ -1100,7 +1101,7 @@ int convert_to_git(const char *path, const char *src, size_t len, src = dst->buf; len = dst->len; } - ret |= crlf_to_git(&the_index, path, src, len, dst, ca.crlf_action, checksafe); + ret |= crlf_to_git(istate, path, src, len, dst, ca.crlf_action, checksafe); if (ret && dst) { src = dst->buf; len = dst->len; @@ -1171,7 +1172,7 @@ int renormalize_buffer(const char *path, const char *src, size_t len, struct str src = dst->buf; len = dst->len; } - return ret | convert_to_git(path, src, len, dst, SAFE_CRLF_RENORMALIZE); + return ret | convert_to_git(&the_index, path, src, len, dst, SAFE_CRLF_RENORMALIZE); } /***************************************************************** diff --git a/convert.h b/convert.h index 3a813a7..60cb41d 100644 --- a/convert.h +++ b/convert.h @@ -41,15 +41,17 @@ extern const char *get_wt_convert_stats_ascii(const char *path); extern const char *get_convert_attr_ascii(const char *path); /* returns 1 if *dst was used */ -extern int convert_to_git(const char *path, const char *src, size_t len, +extern int convert_to_git(const struct index_state *istate, + const char *path, const char *src, size_t len, struct strbuf *dst, enum safe_crlf checksafe); extern int convert_to_working_tree(const char *path, const char *src, size_t len, struct strbuf *dst); extern int renormalize_buffer(const char *path, const char *src, size_t len, struct strbuf *dst); -static inline int would_convert_to_git(const char *path) +static inline int would_convert_to_git(const struct index_state *istate, + const char *path) { - return convert_to_git(path, NULL, 0, NULL, 0); + return convert_to_git(istate, path, NULL, 0, NULL, 0); } /* Precondition: would_convert_to_git_filter_fd(path) == true */ extern void convert_to_git_filter_fd(const struct index_state *istate, diff --git a/diff.c b/diff.c index 5275c4b..976a6f9 100644 --- a/diff.c +++ b/diff.c @@ -2755,7 +2755,7 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int * Similarly, if we'd have to convert the file contents anyway, that * makes the optimization not worthwhile. */ - if (!want_file && would_convert_to_git(name)) + if (!want_file && would_convert_to_git(&the_index, name)) return 0; len = strlen(name); @@ -2877,7 +2877,7 @@ int diff_populate_filespec(struct diff_filespec *s, unsigned int flags) * point if the path requires us to run the content * conversion. */ - if (size_only && !would_convert_to_git(s->path)) + if (size_only && !would_convert_to_git(&the_index, s->path)) return 0; /* @@ -2904,7 +2904,7 @@ int diff_populate_filespec(struct diff_filespec *s, unsigned int flags) /* * Convert from working tree format to canonical git format */ - if (convert_to_git(s->path, s->data, s->size, &buf, crlf_warn)) { + if (convert_to_git(&the_index, s->path, s->data, s->size, &buf, crlf_warn)) { size_t size = 0; munmap(s->data, s->size); s->should_munmap = 0; diff --git a/dir.c b/dir.c index 9efcf1e..f673b86 100644 --- a/dir.c +++ b/dir.c @@ -795,7 +795,7 @@ static int add_excludes(const char *fname, const char *base, int baselen, (pos = index_name_pos(istate, fname, strlen(fname))) >= 0 && !ce_stage(istate->cache[pos]) && ce_uptodate(istate->cache[pos]) && - !would_convert_to_git(fname)) + !would_convert_to_git(istate, fname)) hashcpy(sha1_stat->sha1, istate->cache[pos]->oid.hash); else diff --git a/sha1_file.c b/sha1_file.c index ab09241..feb227a 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -3546,7 +3546,7 @@ static int index_mem(unsigned char *sha1, void *buf, size_t size, */ if ((type == OBJ_BLOB) && path) { struct strbuf nbuf = STRBUF_INIT; - if (convert_to_git(path, buf, size, &nbuf, + if (convert_to_git(&the_index, path, buf, size, &nbuf, write_object ? safe_crlf : SAFE_CRLF_FALSE)) { buf = strbuf_detach(&nbuf, &size); re_allocated = 1; @@ -3668,7 +3668,7 @@ int index_fd(unsigned char *sha1, int fd, struct stat *st, else if (!S_ISREG(st->st_mode)) ret = index_pipe(sha1, fd, type, path, flags); else if (st->st_size <= big_file_threshold || type != OBJ_BLOB || - (path && would_convert_to_git(path))) + (path && would_convert_to_git(&the_index, path))) ret = index_core(sha1, fd, xsize_t(st->st_size), type, path, flags); else -- cgit v0.10.2-6-g49f6 From a33e0b2a77d7010ba8bf0e025fffaf98f464a938 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 12 Jun 2017 15:13:56 -0700 Subject: convert: convert renormalize_buffer to take an index Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano diff --git a/convert.c b/convert.c index 600d11e..4097f52 100644 --- a/convert.c +++ b/convert.c @@ -1,3 +1,4 @@ +#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "attr.h" #include "run-command.h" @@ -1165,14 +1166,15 @@ int convert_to_working_tree(const char *path, const char *src, size_t len, struc return convert_to_working_tree_internal(path, src, len, dst, 0); } -int renormalize_buffer(const char *path, const char *src, size_t len, struct strbuf *dst) +int renormalize_buffer(const struct index_state *istate, const char *path, + const char *src, size_t len, struct strbuf *dst) { int ret = convert_to_working_tree_internal(path, src, len, dst, 1); if (ret) { src = dst->buf; len = dst->len; } - return ret | convert_to_git(&the_index, path, src, len, dst, SAFE_CRLF_RENORMALIZE); + return ret | convert_to_git(istate, path, src, len, dst, SAFE_CRLF_RENORMALIZE); } /***************************************************************** diff --git a/convert.h b/convert.h index 60cb41d..cecf59d 100644 --- a/convert.h +++ b/convert.h @@ -46,7 +46,8 @@ extern int convert_to_git(const struct index_state *istate, struct strbuf *dst, enum safe_crlf checksafe); extern int convert_to_working_tree(const char *path, const char *src, size_t len, struct strbuf *dst); -extern int renormalize_buffer(const char *path, const char *src, size_t len, +extern int renormalize_buffer(const struct index_state *istate, + const char *path, const char *src, size_t len, struct strbuf *dst); static inline int would_convert_to_git(const struct index_state *istate, const char *path) diff --git a/ll-merge.c b/ll-merge.c index ac0d4a5..d7eafb6 100644 --- a/ll-merge.c +++ b/ll-merge.c @@ -339,7 +339,7 @@ static const struct ll_merge_driver *find_ll_merge_driver(const char *merge_attr static void normalize_file(mmfile_t *mm, const char *path) { struct strbuf strbuf = STRBUF_INIT; - if (renormalize_buffer(path, mm->ptr, mm->size, &strbuf)) { + if (renormalize_buffer(&the_index, path, mm->ptr, mm->size, &strbuf)) { free(mm->ptr); mm->size = strbuf.len; mm->ptr = strbuf_detach(&strbuf, NULL); diff --git a/merge-recursive.c b/merge-recursive.c index ae5238d..eac12d4 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -1639,8 +1639,8 @@ static int blob_unchanged(struct merge_options *opt, * performed. Comparison can be skipped if both files are * unchanged since their sha1s have already been compared. */ - if (renormalize_buffer(path, o.buf, o.len, &o) | - renormalize_buffer(path, a.buf, a.len, &a)) + if (renormalize_buffer(&the_index, path, o.buf, o.len, &o) | + renormalize_buffer(&the_index, path, a.buf, a.len, &a)) ret = (o.len == a.len && !memcmp(o.buf, a.buf, o.len)); error_return: -- cgit v0.10.2-6-g49f6 From 85ab50f938601cf874c841cee4c56f1d1dc8199e Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 12 Jun 2017 15:13:57 -0700 Subject: tree: convert read_tree to take an index parameter Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano diff --git a/builtin/ls-files.c b/builtin/ls-files.c index 0044abf..93e46ab 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -460,7 +460,7 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix) PATHSPEC_PREFER_CWD, prefix, matchbuf); } else memset(&pathspec, 0, sizeof(pathspec)); - if (read_tree(tree, 1, &pathspec)) + if (read_tree(tree, 1, &pathspec, &the_index)) die("unable to read tree entries %s", tree_name); for (i = 0; i < active_nr; i++) { diff --git a/tree.c b/tree.c index 603b29e..dd69423 100644 --- a/tree.c +++ b/tree.c @@ -1,3 +1,4 @@ +#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "cache-tree.h" #include "tree.h" @@ -8,7 +9,11 @@ const char *tree_type = "tree"; -static int read_one_entry_opt(const unsigned char *sha1, const char *base, int baselen, const char *pathname, unsigned mode, int stage, int opt) +static int read_one_entry_opt(struct index_state *istate, + const unsigned char *sha1, + const char *base, int baselen, + const char *pathname, + unsigned mode, int stage, int opt) { int len; unsigned int size; @@ -27,14 +32,15 @@ static int read_one_entry_opt(const unsigned char *sha1, const char *base, int b memcpy(ce->name, base, baselen); memcpy(ce->name + baselen, pathname, len+1); hashcpy(ce->oid.hash, sha1); - return add_cache_entry(ce, opt); + return add_index_entry(istate, ce, opt); } static int read_one_entry(const unsigned char *sha1, struct strbuf *base, const char *pathname, unsigned mode, int stage, void *context) { - return read_one_entry_opt(sha1, base->buf, base->len, pathname, + struct index_state *istate = context; + return read_one_entry_opt(istate, sha1, base->buf, base->len, pathname, mode, stage, ADD_CACHE_OK_TO_ADD|ADD_CACHE_SKIP_DFCHECK); } @@ -47,7 +53,8 @@ static int read_one_entry_quick(const unsigned char *sha1, struct strbuf *base, const char *pathname, unsigned mode, int stage, void *context) { - return read_one_entry_opt(sha1, base->buf, base->len, pathname, + struct index_state *istate = context; + return read_one_entry_opt(istate, sha1, base->buf, base->len, pathname, mode, stage, ADD_CACHE_JUST_APPEND); } @@ -144,7 +151,8 @@ static int cmp_cache_name_compare(const void *a_, const void *b_) ce2->name, ce2->ce_namelen, ce_stage(ce2)); } -int read_tree(struct tree *tree, int stage, struct pathspec *match) +int read_tree(struct tree *tree, int stage, struct pathspec *match, + struct index_state *istate) { read_tree_fn_t fn = NULL; int i, err; @@ -164,23 +172,23 @@ int read_tree(struct tree *tree, int stage, struct pathspec *match) * do it the original slow way, otherwise, append and then * sort at the end. */ - for (i = 0; !fn && i < active_nr; i++) { - const struct cache_entry *ce = active_cache[i]; + for (i = 0; !fn && i < istate->cache_nr; i++) { + const struct cache_entry *ce = istate->cache[i]; if (ce_stage(ce) == stage) fn = read_one_entry; } if (!fn) fn = read_one_entry_quick; - err = read_tree_recursive(tree, "", 0, stage, match, fn, NULL); + err = read_tree_recursive(tree, "", 0, stage, match, fn, istate); if (fn == read_one_entry || err) return err; /* * Sort the cache entry -- we need to nuke the cache tree, though. */ - cache_tree_free(&active_cache_tree); - QSORT(active_cache, active_nr, cmp_cache_name_compare); + cache_tree_free(&istate->cache_tree); + QSORT(istate->cache, istate->cache_nr, cmp_cache_name_compare); return 0; } diff --git a/tree.h b/tree.h index 0d4734b..744e6dc 100644 --- a/tree.h +++ b/tree.h @@ -34,6 +34,7 @@ extern int read_tree_recursive(struct tree *tree, int stage, const struct pathspec *pathspec, read_tree_fn_t fn, void *context); -extern int read_tree(struct tree *tree, int stage, struct pathspec *pathspec); +extern int read_tree(struct tree *tree, int stage, struct pathspec *pathspec, + struct index_state *istate); #endif /* TREE_H */ -- cgit v0.10.2-6-g49f6 From 312c984a027f50247501d002fbd228a982f4f096 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 12 Jun 2017 15:13:58 -0700 Subject: ls-files: convert overlay_tree_on_cache to take an index Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano diff --git a/builtin/commit.c b/builtin/commit.c index da1ba4c..78ef319 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -253,7 +253,8 @@ static int list_paths(struct string_list *list, const char *with_tree, if (with_tree) { char *max_prefix = common_prefix(pattern); - overlay_tree_on_cache(with_tree, max_prefix ? max_prefix : prefix); + overlay_tree_on_index(&the_index, with_tree, + max_prefix ? max_prefix : prefix); free(max_prefix); } diff --git a/builtin/ls-files.c b/builtin/ls-files.c index 93e46ab..a78b291 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -431,7 +431,8 @@ static int get_common_prefix_len(const char *common_prefix) * that were given from the command line. We are not * going to write this index out. */ -void overlay_tree_on_cache(const char *tree_name, const char *prefix) +void overlay_tree_on_index(struct index_state *istate, + const char *tree_name, const char *prefix) { struct tree *tree; struct object_id oid; @@ -446,8 +447,8 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix) die("bad tree-ish %s", tree_name); /* Hoist the unmerged entries up to stage #3 to make room */ - for (i = 0; i < active_nr; i++) { - struct cache_entry *ce = active_cache[i]; + for (i = 0; i < istate->cache_nr; i++) { + struct cache_entry *ce = istate->cache[i]; if (!ce_stage(ce)) continue; ce->ce_flags |= CE_STAGEMASK; @@ -460,11 +461,11 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix) PATHSPEC_PREFER_CWD, prefix, matchbuf); } else memset(&pathspec, 0, sizeof(pathspec)); - if (read_tree(tree, 1, &pathspec, &the_index)) + if (read_tree(tree, 1, &pathspec, istate)) die("unable to read tree entries %s", tree_name); - for (i = 0; i < active_nr; i++) { - struct cache_entry *ce = active_cache[i]; + for (i = 0; i < istate->cache_nr; i++) { + struct cache_entry *ce = istate->cache[i]; switch (ce_stage(ce)) { case 0: last_stage0 = ce; @@ -679,7 +680,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) */ if (show_stage || show_unmerged) die("ls-files --with-tree is incompatible with -s or -u"); - overlay_tree_on_cache(with_tree, max_prefix); + overlay_tree_on_index(&the_index, with_tree, max_prefix); } show_files(&dir); if (show_resolve_undo) diff --git a/cache.h b/cache.h index 4d92aae..5a0e0a9 100644 --- a/cache.h +++ b/cache.h @@ -2186,7 +2186,8 @@ extern int ws_blank_line(const char *line, int len, unsigned ws_rule); #define ws_tab_width(rule) ((rule) & WS_TAB_WIDTH_MASK) /* ls-files */ -void overlay_tree_on_cache(const char *tree_name, const char *prefix); +void overlay_tree_on_index(struct index_state *istate, + const char *tree_name, const char *prefix); char *alias_lookup(const char *alias); int split_cmdline(char *cmdline, const char ***argv); -- cgit v0.10.2-6-g49f6 From 1985fd68c65f2989033924416367a683b1d8ca67 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 12 Jun 2017 15:13:59 -0700 Subject: ls-files: convert write_eolinfo to take an index Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano diff --git a/builtin/ls-files.c b/builtin/ls-files.c index a78b291..8c3f3d8 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -53,17 +53,16 @@ static const char *tag_modified = ""; static const char *tag_skip_worktree = ""; static const char *tag_resolve_undo = ""; -static void write_eolinfo(const struct cache_entry *ce, const char *path) +static void write_eolinfo(const struct index_state *istate, + const struct cache_entry *ce, const char *path) { - if (!show_eol) - return; - else { + if (show_eol) { struct stat st; const char *i_txt = ""; const char *w_txt = ""; const char *a_txt = get_convert_attr_ascii(path); if (ce && S_ISREG(ce->ce_mode)) - i_txt = get_cached_convert_stats_ascii(&the_index, + i_txt = get_cached_convert_stats_ascii(istate, ce->name); if (!lstat(path, &st) && S_ISREG(st.st_mode)) w_txt = get_wt_convert_stats_ascii(path); @@ -105,7 +104,7 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent) return; fputs(tag, stdout); - write_eolinfo(NULL, ent->name); + write_eolinfo(NULL, NULL, ent->name); write_name(ent->name); } @@ -275,7 +274,7 @@ static void show_ce_entry(const char *tag, const struct cache_entry *ce) find_unique_abbrev(ce->oid.hash, abbrev), ce_stage(ce)); } - write_eolinfo(ce, ce->name); + write_eolinfo(&the_index, ce, ce->name); write_name(ce->name); if (debug_mode) { const struct stat_data *sd = &ce->ce_stat_data; -- cgit v0.10.2-6-g49f6 From 23d6236a07be1434479a5d2f1f82cd8dda4818f9 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 12 Jun 2017 15:14:00 -0700 Subject: ls-files: convert show_killed_files to take an index Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano diff --git a/builtin/ls-files.c b/builtin/ls-files.c index 8c3f3d8..b82b780 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -120,7 +120,8 @@ static void show_other_files(struct dir_struct *dir) } } -static void show_killed_files(struct dir_struct *dir) +static void show_killed_files(const struct index_state *istate, + const struct dir_struct *dir) { int i; for (i = 0; i < dir->nr; i++) { @@ -134,29 +135,29 @@ static void show_killed_files(struct dir_struct *dir) /* If ent->name is prefix of an entry in the * cache, it will be killed. */ - pos = cache_name_pos(ent->name, ent->len); + pos = index_name_pos(istate, ent->name, ent->len); if (0 <= pos) die("BUG: killed-file %.*s not found", ent->len, ent->name); pos = -pos - 1; - while (pos < active_nr && - ce_stage(active_cache[pos])) + while (pos < istate->cache_nr && + ce_stage(istate->cache[pos])) pos++; /* skip unmerged */ - if (active_nr <= pos) + if (istate->cache_nr <= pos) break; /* pos points at a name immediately after * ent->name in the cache. Does it expect * ent->name to be a directory? */ - len = ce_namelen(active_cache[pos]); + len = ce_namelen(istate->cache[pos]); if ((ent->len < len) && - !strncmp(active_cache[pos]->name, + !strncmp(istate->cache[pos]->name, ent->name, ent->len) && - active_cache[pos]->name[ent->len] == '/') + istate->cache[pos]->name[ent->len] == '/') killed = 1; break; } - if (0 <= cache_name_pos(ent->name, sp - ent->name)) { + if (0 <= index_name_pos(istate, ent->name, sp - ent->name)) { /* If any of the leading directories in * ent->name is registered in the cache, * ent->name will be killed. @@ -337,7 +338,7 @@ static void show_files(struct dir_struct *dir) if (show_others) show_other_files(dir); if (show_killed) - show_killed_files(dir); + show_killed_files(&the_index, dir); } if (show_cached || show_stage) { for (i = 0; i < active_nr; i++) { -- cgit v0.10.2-6-g49f6 From 23d6846b2324ef647a339b84ba3abc52e0a4dc94 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 12 Jun 2017 15:14:01 -0700 Subject: ls-files: convert show_other_files to take an index Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano diff --git a/builtin/ls-files.c b/builtin/ls-files.c index b82b780..5dbff94 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -108,13 +108,14 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent) write_name(ent->name); } -static void show_other_files(struct dir_struct *dir) +static void show_other_files(const struct index_state *istate, + const struct dir_struct *dir) { int i; for (i = 0; i < dir->nr; i++) { struct dir_entry *ent = dir->entries[i]; - if (!cache_name_is_other(ent->name, ent->len)) + if (!index_name_is_other(istate, ent->name, ent->len)) continue; show_dir_entry(tag_other, ent); } @@ -336,7 +337,7 @@ static void show_files(struct dir_struct *dir) dir->flags |= DIR_COLLECT_KILLED_ONLY; fill_directory(dir, &the_index, &pathspec); if (show_others) - show_other_files(dir); + show_other_files(&the_index, dir); if (show_killed) show_killed_files(&the_index, dir); } -- cgit v0.10.2-6-g49f6 From 2d407e2da1b12fd1f3cb5fc0b072732ab2ac1c6a Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 12 Jun 2017 15:14:02 -0700 Subject: ls-files: convert show_ru_info to take an index Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano diff --git a/builtin/ls-files.c b/builtin/ls-files.c index 5dbff94..375fe09 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -292,14 +292,14 @@ static void show_ce_entry(const char *tag, const struct cache_entry *ce) strbuf_release(&name); } -static void show_ru_info(void) +static void show_ru_info(const struct index_state *istate) { struct string_list_item *item; - if (!the_index.resolve_undo) + if (!istate->resolve_undo) return; - for_each_string_list_item(item, the_index.resolve_undo) { + for_each_string_list_item(item, istate->resolve_undo) { const char *path = item->string; struct resolve_undo_info *ui = item->util; int i, len; @@ -685,7 +685,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) } show_files(&dir); if (show_resolve_undo) - show_ru_info(); + show_ru_info(&the_index); if (ps_matched) { int bad; -- cgit v0.10.2-6-g49f6 From 1d35e3bf056b508f4ece3875f9d2851be5fcd3d4 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 12 Jun 2017 15:14:03 -0700 Subject: ls-files: convert ce_excluded to take an index Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano diff --git a/builtin/ls-files.c b/builtin/ls-files.c index 375fe09..762257f 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -321,10 +321,11 @@ static void show_ru_info(const struct index_state *istate) } } -static int ce_excluded(struct dir_struct *dir, const struct cache_entry *ce) +static int ce_excluded(struct dir_struct *dir, struct index_state *istate, + const struct cache_entry *ce) { int dtype = ce_to_dtype(ce); - return is_excluded(dir, &the_index, ce->name, &dtype); + return is_excluded(dir, istate, ce->name, &dtype); } static void show_files(struct dir_struct *dir) @@ -345,7 +346,7 @@ static void show_files(struct dir_struct *dir) for (i = 0; i < active_nr; i++) { const struct cache_entry *ce = active_cache[i]; if ((dir->flags & DIR_SHOW_IGNORED) && - !ce_excluded(dir, ce)) + !ce_excluded(dir, &the_index, ce)) continue; if (show_unmerged && !ce_stage(ce)) continue; @@ -361,7 +362,7 @@ static void show_files(struct dir_struct *dir) struct stat st; int err; if ((dir->flags & DIR_SHOW_IGNORED) && - !ce_excluded(dir, ce)) + !ce_excluded(dir, &the_index, ce)) continue; if (ce->ce_flags & CE_UPDATE) continue; -- cgit v0.10.2-6-g49f6 From 6510ae173a8630e39a225f15031a7975547979ec Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 12 Jun 2017 15:14:04 -0700 Subject: ls-files: convert prune_cache to take an index Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano diff --git a/builtin/ls-files.c b/builtin/ls-files.c index 762257f..b1626b1 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -380,30 +380,31 @@ static void show_files(struct dir_struct *dir) /* * Prune the index to only contain stuff starting with "prefix" */ -static void prune_cache(const char *prefix, size_t prefixlen) +static void prune_index(struct index_state *istate, + const char *prefix, size_t prefixlen) { int pos; unsigned int first, last; if (!prefix) return; - pos = cache_name_pos(prefix, prefixlen); + pos = index_name_pos(istate, prefix, prefixlen); if (pos < 0) pos = -pos-1; first = pos; - last = active_nr; + last = istate->cache_nr; while (last > first) { int next = (last + first) >> 1; - const struct cache_entry *ce = active_cache[next]; + const struct cache_entry *ce = istate->cache[next]; if (!strncmp(ce->name, prefix, prefixlen)) { first = next+1; continue; } last = next; } - memmove(active_cache, active_cache + pos, + memmove(istate->cache, istate->cache + pos, (last - pos) * sizeof(struct cache_entry *)); - active_nr = last - pos; + istate->cache_nr = last - pos; } static int get_common_prefix_len(const char *common_prefix) @@ -661,7 +662,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) max_prefix = common_prefix(&pathspec); max_prefix_len = get_common_prefix_len(max_prefix); - prune_cache(max_prefix, max_prefix_len); + prune_index(&the_index, max_prefix, max_prefix_len); /* Treat unmatching pathspec elements as errors */ if (pathspec.nr && error_unmatch) -- cgit v0.10.2-6-g49f6 From ff020a8ab0a40a3f938a30be6d73607c2041cc34 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 12 Jun 2017 15:14:05 -0700 Subject: ls-files: convert show_ce_entry to take an index Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano diff --git a/builtin/ls-files.c b/builtin/ls-files.c index b1626b1..927aa67 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -232,7 +232,8 @@ static void show_gitlink(const struct cache_entry *ce) exit(status); } -static void show_ce_entry(const char *tag, const struct cache_entry *ce) +static void show_ce_entry(const struct index_state *istate, + const char *tag, const struct cache_entry *ce) { struct strbuf name = STRBUF_INIT; int len = max_prefix_len; @@ -276,7 +277,7 @@ static void show_ce_entry(const char *tag, const struct cache_entry *ce) find_unique_abbrev(ce->oid.hash, abbrev), ce_stage(ce)); } - write_eolinfo(&the_index, ce, ce->name); + write_eolinfo(istate, ce, ce->name); write_name(ce->name); if (debug_mode) { const struct stat_data *sd = &ce->ce_stat_data; @@ -352,7 +353,7 @@ static void show_files(struct dir_struct *dir) continue; if (ce->ce_flags & CE_UPDATE) continue; - show_ce_entry(ce_stage(ce) ? tag_unmerged : + show_ce_entry(&the_index, ce_stage(ce) ? tag_unmerged : (ce_skip_worktree(ce) ? tag_skip_worktree : tag_cached), ce); } } @@ -370,9 +371,9 @@ static void show_files(struct dir_struct *dir) continue; err = lstat(ce->name, &st); if (show_deleted && err) - show_ce_entry(tag_removed, ce); + show_ce_entry(&the_index, tag_removed, ce); if (show_modified && ce_modified(ce, &st, 0)) - show_ce_entry(tag_modified, ce); + show_ce_entry(&the_index, tag_modified, ce); } } } -- cgit v0.10.2-6-g49f6 From f587c8dcdef17aea15aee45689e181b58b011706 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 12 Jun 2017 15:14:06 -0700 Subject: ls-files: convert show_files to take an index Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano diff --git a/builtin/ls-files.c b/builtin/ls-files.c index 927aa67..55d6f54 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -329,7 +329,7 @@ static int ce_excluded(struct dir_struct *dir, struct index_state *istate, return is_excluded(dir, istate, ce->name, &dtype); } -static void show_files(struct dir_struct *dir) +static void show_files(struct index_state *istate, struct dir_struct *dir) { int i; @@ -337,33 +337,33 @@ static void show_files(struct dir_struct *dir) if (show_others || show_killed) { if (!show_others) dir->flags |= DIR_COLLECT_KILLED_ONLY; - fill_directory(dir, &the_index, &pathspec); + fill_directory(dir, istate, &pathspec); if (show_others) - show_other_files(&the_index, dir); + show_other_files(istate, dir); if (show_killed) - show_killed_files(&the_index, dir); + show_killed_files(istate, dir); } if (show_cached || show_stage) { - for (i = 0; i < active_nr; i++) { - const struct cache_entry *ce = active_cache[i]; + for (i = 0; i < istate->cache_nr; i++) { + const struct cache_entry *ce = istate->cache[i]; if ((dir->flags & DIR_SHOW_IGNORED) && - !ce_excluded(dir, &the_index, ce)) + !ce_excluded(dir, istate, ce)) continue; if (show_unmerged && !ce_stage(ce)) continue; if (ce->ce_flags & CE_UPDATE) continue; - show_ce_entry(&the_index, ce_stage(ce) ? tag_unmerged : + show_ce_entry(istate, ce_stage(ce) ? tag_unmerged : (ce_skip_worktree(ce) ? tag_skip_worktree : tag_cached), ce); } } if (show_deleted || show_modified) { - for (i = 0; i < active_nr; i++) { - const struct cache_entry *ce = active_cache[i]; + for (i = 0; i < istate->cache_nr; i++) { + const struct cache_entry *ce = istate->cache[i]; struct stat st; int err; if ((dir->flags & DIR_SHOW_IGNORED) && - !ce_excluded(dir, &the_index, ce)) + !ce_excluded(dir, istate, ce)) continue; if (ce->ce_flags & CE_UPDATE) continue; @@ -371,9 +371,9 @@ static void show_files(struct dir_struct *dir) continue; err = lstat(ce->name, &st); if (show_deleted && err) - show_ce_entry(&the_index, tag_removed, ce); - if (show_modified && ce_modified(ce, &st, 0)) - show_ce_entry(&the_index, tag_modified, ce); + show_ce_entry(istate, tag_removed, ce); + if (show_modified && ie_modified(istate, ce, &st, 0)) + show_ce_entry(istate, tag_modified, ce); } } } @@ -686,7 +686,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) die("ls-files --with-tree is incompatible with -s or -u"); overlay_tree_on_index(&the_index, with_tree, max_prefix); } - show_files(&dir); + show_files(&the_index, &dir); if (show_resolve_undo) show_ru_info(&the_index); -- cgit v0.10.2-6-g49f6 From 5306ccf9e9ec7204eef409e90b57ddf23b8f5ca6 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 12 Jun 2017 15:14:07 -0700 Subject: ls-files: factor out debug info into a function Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano diff --git a/builtin/ls-files.c b/builtin/ls-files.c index 55d6f54..c9307f9 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -93,6 +93,19 @@ static void write_name(const char *name) strbuf_release(&full_name); } +static void print_debug(const struct cache_entry *ce) +{ + if (debug_mode) { + const struct stat_data *sd = &ce->ce_stat_data; + + printf(" ctime: %d:%d\n", sd->sd_ctime.sec, sd->sd_ctime.nsec); + printf(" mtime: %d:%d\n", sd->sd_mtime.sec, sd->sd_mtime.nsec); + printf(" dev: %d\tino: %d\n", sd->sd_dev, sd->sd_ino); + printf(" uid: %d\tgid: %d\n", sd->sd_uid, sd->sd_gid); + printf(" size: %d\tflags: %x\n", sd->sd_size, ce->ce_flags); + } +} + static void show_dir_entry(const char *tag, struct dir_entry *ent) { int len = max_prefix_len; @@ -279,15 +292,7 @@ static void show_ce_entry(const struct index_state *istate, } write_eolinfo(istate, ce, ce->name); write_name(ce->name); - if (debug_mode) { - const struct stat_data *sd = &ce->ce_stat_data; - - printf(" ctime: %d:%d\n", sd->sd_ctime.sec, sd->sd_ctime.nsec); - printf(" mtime: %d:%d\n", sd->sd_mtime.sec, sd->sd_mtime.nsec); - printf(" dev: %d\tino: %d\n", sd->sd_dev, sd->sd_ino); - printf(" uid: %d\tgid: %d\n", sd->sd_uid, sd->sd_gid); - printf(" size: %d\tflags: %x\n", sd->sd_size, ce->ce_flags); - } + print_debug(ce); } strbuf_release(&name); -- cgit v0.10.2-6-g49f6 From a84f3e59ebde9e891275ef8325c432db6bdf950c Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 12 Jun 2017 15:14:08 -0700 Subject: ls-files: factor out tag calculation Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano diff --git a/builtin/ls-files.c b/builtin/ls-files.c index c9307f9..cdc1cfd 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -93,6 +93,30 @@ static void write_name(const char *name) strbuf_release(&full_name); } +static const char *get_tag(const struct cache_entry *ce, const char *tag) +{ + static char alttag[4]; + + if (tag && *tag && show_valid_bit && (ce->ce_flags & CE_VALID)) { + memcpy(alttag, tag, 3); + + if (isalpha(tag[0])) { + alttag[0] = tolower(tag[0]); + } else if (tag[0] == '?') { + alttag[0] = '!'; + } else { + alttag[0] = 'v'; + alttag[1] = tag[0]; + alttag[2] = ' '; + alttag[3] = 0; + } + + tag = alttag; + } + + return tag; +} + static void print_debug(const struct cache_entry *ce) { if (debug_mode) { @@ -264,22 +288,7 @@ static void show_ce_entry(const struct index_state *istate, len, ps_matched, S_ISDIR(ce->ce_mode) || S_ISGITLINK(ce->ce_mode))) { - if (tag && *tag && show_valid_bit && - (ce->ce_flags & CE_VALID)) { - static char alttag[4]; - memcpy(alttag, tag, 3); - if (isalpha(tag[0])) - alttag[0] = tolower(tag[0]); - else if (tag[0] == '?') - alttag[0] = '!'; - else { - alttag[0] = 'v'; - alttag[1] = tag[0]; - alttag[2] = ' '; - alttag[3] = 0; - } - tag = alttag; - } + tag = get_tag(ce, tag); if (!show_stage) { fputs(tag, stdout); -- cgit v0.10.2-6-g49f6