* [PATCH 00/17] convert ls-files internals to pass around an index
@ 2017-06-12 22:13 Brandon Williams
2017-06-12 22:13 ` [PATCH 01/17] convert: convert get_cached_convert_stats_ascii to take " Brandon Williams
` (16 more replies)
0 siblings, 17 replies; 18+ messages in thread
From: Brandon Williams @ 2017-06-12 22:13 UTC (permalink / raw)
To: git; +Cc: gitster, Brandon Williams
This is the second chunk of patches I want to carve off of my 'repository
object' series. As you can see its 17 patches long so by eliminating this the
repository series shrinks by a considerable amount.
The point of this series is to stop having some of the internals of ls-files
(and subsequent library routines) from implicitly referencing 'the_index'.
Instead a pointer to an 'index_state' struct is passed around and operated on.
This is a preparatory step to enabling ls-files to able to recurse submodule
in-process. They other step being the actual introduction of a repository object.
Brandon Williams (17):
convert: convert get_cached_convert_stats_ascii to take an index
convert: convert crlf_to_git to take an index
convert: convert convert_to_git_filter_fd to take an index
convert: convert convert_to_git to take an index
convert: convert renormalize_buffer to take an index
tree: convert read_tree to take an index parameter
ls-files: convert overlay_tree_on_cache to take an index
ls-files: convert write_eolinfo to take an index
ls-files: convert show_killed_files to take an index
ls-files: convert show_other_files to take an index
ls-files: convert show_ru_info to take an index
ls-files: convert ce_excluded to take an index
ls-files: convert prune_cache to take an index
ls-files: convert show_ce_entry to take an index
ls-files: convert show_files to take an index
ls-files: factor out debug info into a function
ls-files: factor out tag calculation
apply.c | 2 +-
blame.c | 2 +-
builtin/commit.c | 3 +-
builtin/ls-files.c | 178 +++++++++++++++++++++++++++++------------------------
cache.h | 3 +-
combine-diff.c | 2 +-
convert.c | 31 ++++++----
convert.h | 19 ++++--
diff.c | 6 +-
dir.c | 2 +-
ll-merge.c | 2 +-
merge-recursive.c | 4 +-
sha1_file.c | 6 +-
tree.c | 28 ++++++---
tree.h | 3 +-
15 files changed, 168 insertions(+), 123 deletions(-)
--
2.13.1.518.g3df882009-goog
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH 01/17] convert: convert get_cached_convert_stats_ascii to take an index
2017-06-12 22:13 [PATCH 00/17] convert ls-files internals to pass around an index Brandon Williams
@ 2017-06-12 22:13 ` Brandon Williams
2017-06-12 22:13 ` [PATCH 02/17] convert: convert crlf_to_git " Brandon Williams
` (15 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Brandon Williams @ 2017-06-12 22:13 UTC (permalink / raw)
To: git; +Cc: gitster, Brandon Williams
Signed-off-by: Brandon Williams <bmwill@google.com>
---
builtin/ls-files.c | 3 ++-
convert.c | 5 +++--
convert.h | 5 ++++-
3 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index b376afc31..0044abf66 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 f1e168bc3..03160b376 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 82871a11d..667b7dfe0 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);
--
2.13.1.518.g3df882009-goog
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 02/17] convert: convert crlf_to_git to take an index
2017-06-12 22:13 [PATCH 00/17] convert ls-files internals to pass around an index Brandon Williams
2017-06-12 22:13 ` [PATCH 01/17] convert: convert get_cached_convert_stats_ascii to take " Brandon Williams
@ 2017-06-12 22:13 ` Brandon Williams
2017-06-12 22:13 ` [PATCH 03/17] convert: convert convert_to_git_filter_fd " Brandon Williams
` (14 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Brandon Williams @ 2017-06-12 22:13 UTC (permalink / raw)
To: git; +Cc: gitster, Brandon Williams
Signed-off-by: Brandon Williams <bmwill@google.com>
---
convert.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/convert.c b/convert.c
index 03160b376..0cafb06f5 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);
}
--
2.13.1.518.g3df882009-goog
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 03/17] convert: convert convert_to_git_filter_fd to take an index
2017-06-12 22:13 [PATCH 00/17] convert ls-files internals to pass around an index Brandon Williams
2017-06-12 22:13 ` [PATCH 01/17] convert: convert get_cached_convert_stats_ascii to take " Brandon Williams
2017-06-12 22:13 ` [PATCH 02/17] convert: convert crlf_to_git " Brandon Williams
@ 2017-06-12 22:13 ` Brandon Williams
2017-06-12 22:13 ` [PATCH 04/17] convert: convert convert_to_git " Brandon Williams
` (13 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Brandon Williams @ 2017-06-12 22:13 UTC (permalink / raw)
To: git; +Cc: gitster, Brandon Williams
Signed-off-by: Brandon Williams <bmwill@google.com>
---
convert.c | 5 +++--
convert.h | 3 ++-
sha1_file.c | 2 +-
3 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/convert.c b/convert.c
index 0cafb06f5..c09242cec 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 667b7dfe0..3a813a797 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 59a4ed2ed..ab09241d2 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)
--
2.13.1.518.g3df882009-goog
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 04/17] convert: convert convert_to_git to take an index
2017-06-12 22:13 [PATCH 00/17] convert ls-files internals to pass around an index Brandon Williams
` (2 preceding siblings ...)
2017-06-12 22:13 ` [PATCH 03/17] convert: convert convert_to_git_filter_fd " Brandon Williams
@ 2017-06-12 22:13 ` Brandon Williams
2017-06-12 22:13 ` [PATCH 05/17] convert: convert renormalize_buffer " Brandon Williams
` (12 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Brandon Williams @ 2017-06-12 22:13 UTC (permalink / raw)
To: git; +Cc: gitster, Brandon Williams
Signed-off-by: Brandon Williams <bmwill@google.com>
---
apply.c | 2 +-
blame.c | 2 +-
combine-diff.c | 2 +-
convert.c | 7 ++++---
convert.h | 8 +++++---
diff.c | 6 +++---
dir.c | 2 +-
sha1_file.c | 4 ++--
8 files changed, 18 insertions(+), 15 deletions(-)
diff --git a/apply.c b/apply.c
index c49cef063..97afb6f60 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 843c845cb..a6f3d72df 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 2848034fe..74f723af3 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 c09242cec..600d11e73 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 3a813a797..60cb41d6a 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 5275c4b78..976a6f91b 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 9efcf1eab..f673b86f3 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 ab09241d2..feb227a83 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
--
2.13.1.518.g3df882009-goog
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 05/17] convert: convert renormalize_buffer to take an index
2017-06-12 22:13 [PATCH 00/17] convert ls-files internals to pass around an index Brandon Williams
` (3 preceding siblings ...)
2017-06-12 22:13 ` [PATCH 04/17] convert: convert convert_to_git " Brandon Williams
@ 2017-06-12 22:13 ` Brandon Williams
2017-06-12 22:13 ` [PATCH 06/17] tree: convert read_tree to take an index parameter Brandon Williams
` (11 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Brandon Williams @ 2017-06-12 22:13 UTC (permalink / raw)
To: git; +Cc: gitster, Brandon Williams
Signed-off-by: Brandon Williams <bmwill@google.com>
---
convert.c | 6 ++++--
convert.h | 3 ++-
ll-merge.c | 2 +-
merge-recursive.c | 4 ++--
4 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/convert.c b/convert.c
index 600d11e73..4097f521f 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 60cb41d6a..cecf59d1a 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 ac0d4a5d7..d7eafb61a 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 ae5238d82..eac12d488 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:
--
2.13.1.518.g3df882009-goog
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 06/17] tree: convert read_tree to take an index parameter
2017-06-12 22:13 [PATCH 00/17] convert ls-files internals to pass around an index Brandon Williams
` (4 preceding siblings ...)
2017-06-12 22:13 ` [PATCH 05/17] convert: convert renormalize_buffer " Brandon Williams
@ 2017-06-12 22:13 ` Brandon Williams
2017-06-12 22:13 ` [PATCH 07/17] ls-files: convert overlay_tree_on_cache to take an index Brandon Williams
` (10 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Brandon Williams @ 2017-06-12 22:13 UTC (permalink / raw)
To: git; +Cc: gitster, Brandon Williams
Signed-off-by: Brandon Williams <bmwill@google.com>
---
builtin/ls-files.c | 2 +-
tree.c | 28 ++++++++++++++++++----------
tree.h | 3 ++-
3 files changed, 21 insertions(+), 12 deletions(-)
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 0044abf66..93e46ab5f 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 603b29ee8..dd69423d9 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 0d4734b94..744e6dc2a 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 */
--
2.13.1.518.g3df882009-goog
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 07/17] ls-files: convert overlay_tree_on_cache to take an index
2017-06-12 22:13 [PATCH 00/17] convert ls-files internals to pass around an index Brandon Williams
` (5 preceding siblings ...)
2017-06-12 22:13 ` [PATCH 06/17] tree: convert read_tree to take an index parameter Brandon Williams
@ 2017-06-12 22:13 ` Brandon Williams
2017-06-12 22:13 ` [PATCH 08/17] ls-files: convert write_eolinfo " Brandon Williams
` (9 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Brandon Williams @ 2017-06-12 22:13 UTC (permalink / raw)
To: git; +Cc: gitster, Brandon Williams
Signed-off-by: Brandon Williams <bmwill@google.com>
---
builtin/commit.c | 3 ++-
builtin/ls-files.c | 15 ++++++++-------
cache.h | 3 ++-
3 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/builtin/commit.c b/builtin/commit.c
index da1ba4c86..78ef319a2 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 93e46ab5f..a78b291ab 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 4d92aae0e..5a0e0a9e5 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);
--
2.13.1.518.g3df882009-goog
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 08/17] ls-files: convert write_eolinfo to take an index
2017-06-12 22:13 [PATCH 00/17] convert ls-files internals to pass around an index Brandon Williams
` (6 preceding siblings ...)
2017-06-12 22:13 ` [PATCH 07/17] ls-files: convert overlay_tree_on_cache to take an index Brandon Williams
@ 2017-06-12 22:13 ` Brandon Williams
2017-06-12 22:14 ` [PATCH 09/17] ls-files: convert show_killed_files " Brandon Williams
` (8 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Brandon Williams @ 2017-06-12 22:13 UTC (permalink / raw)
To: git; +Cc: gitster, Brandon Williams
Signed-off-by: Brandon Williams <bmwill@google.com>
---
builtin/ls-files.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index a78b291ab..8c3f3d8ca 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;
--
2.13.1.518.g3df882009-goog
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 09/17] ls-files: convert show_killed_files to take an index
2017-06-12 22:13 [PATCH 00/17] convert ls-files internals to pass around an index Brandon Williams
` (7 preceding siblings ...)
2017-06-12 22:13 ` [PATCH 08/17] ls-files: convert write_eolinfo " Brandon Williams
@ 2017-06-12 22:14 ` Brandon Williams
2017-06-12 22:14 ` [PATCH 10/17] ls-files: convert show_other_files " Brandon Williams
` (7 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Brandon Williams @ 2017-06-12 22:14 UTC (permalink / raw)
To: git; +Cc: gitster, Brandon Williams
Signed-off-by: Brandon Williams <bmwill@google.com>
---
builtin/ls-files.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 8c3f3d8ca..b82b78036 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++) {
--
2.13.1.518.g3df882009-goog
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 10/17] ls-files: convert show_other_files to take an index
2017-06-12 22:13 [PATCH 00/17] convert ls-files internals to pass around an index Brandon Williams
` (8 preceding siblings ...)
2017-06-12 22:14 ` [PATCH 09/17] ls-files: convert show_killed_files " Brandon Williams
@ 2017-06-12 22:14 ` Brandon Williams
2017-06-12 22:14 ` [PATCH 11/17] ls-files: convert show_ru_info " Brandon Williams
` (6 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Brandon Williams @ 2017-06-12 22:14 UTC (permalink / raw)
To: git; +Cc: gitster, Brandon Williams
Signed-off-by: Brandon Williams <bmwill@google.com>
---
builtin/ls-files.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index b82b78036..5dbff9496 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);
}
--
2.13.1.518.g3df882009-goog
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 11/17] ls-files: convert show_ru_info to take an index
2017-06-12 22:13 [PATCH 00/17] convert ls-files internals to pass around an index Brandon Williams
` (9 preceding siblings ...)
2017-06-12 22:14 ` [PATCH 10/17] ls-files: convert show_other_files " Brandon Williams
@ 2017-06-12 22:14 ` Brandon Williams
2017-06-12 22:14 ` [PATCH 12/17] ls-files: convert ce_excluded " Brandon Williams
` (5 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Brandon Williams @ 2017-06-12 22:14 UTC (permalink / raw)
To: git; +Cc: gitster, Brandon Williams
Signed-off-by: Brandon Williams <bmwill@google.com>
---
builtin/ls-files.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 5dbff9496..375fe09d1 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;
--
2.13.1.518.g3df882009-goog
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 12/17] ls-files: convert ce_excluded to take an index
2017-06-12 22:13 [PATCH 00/17] convert ls-files internals to pass around an index Brandon Williams
` (10 preceding siblings ...)
2017-06-12 22:14 ` [PATCH 11/17] ls-files: convert show_ru_info " Brandon Williams
@ 2017-06-12 22:14 ` Brandon Williams
2017-06-12 22:14 ` [PATCH 13/17] ls-files: convert prune_cache " Brandon Williams
` (4 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Brandon Williams @ 2017-06-12 22:14 UTC (permalink / raw)
To: git; +Cc: gitster, Brandon Williams
Signed-off-by: Brandon Williams <bmwill@google.com>
---
builtin/ls-files.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 375fe09d1..762257f39 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;
--
2.13.1.518.g3df882009-goog
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 13/17] ls-files: convert prune_cache to take an index
2017-06-12 22:13 [PATCH 00/17] convert ls-files internals to pass around an index Brandon Williams
` (11 preceding siblings ...)
2017-06-12 22:14 ` [PATCH 12/17] ls-files: convert ce_excluded " Brandon Williams
@ 2017-06-12 22:14 ` Brandon Williams
2017-06-12 22:14 ` [PATCH 14/17] ls-files: convert show_ce_entry " Brandon Williams
` (3 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Brandon Williams @ 2017-06-12 22:14 UTC (permalink / raw)
To: git; +Cc: gitster, Brandon Williams
Signed-off-by: Brandon Williams <bmwill@google.com>
---
builtin/ls-files.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 762257f39..b1626b13b 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)
--
2.13.1.518.g3df882009-goog
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 14/17] ls-files: convert show_ce_entry to take an index
2017-06-12 22:13 [PATCH 00/17] convert ls-files internals to pass around an index Brandon Williams
` (12 preceding siblings ...)
2017-06-12 22:14 ` [PATCH 13/17] ls-files: convert prune_cache " Brandon Williams
@ 2017-06-12 22:14 ` Brandon Williams
2017-06-12 22:14 ` [PATCH 15/17] ls-files: convert show_files " Brandon Williams
` (2 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Brandon Williams @ 2017-06-12 22:14 UTC (permalink / raw)
To: git; +Cc: gitster, Brandon Williams
Signed-off-by: Brandon Williams <bmwill@google.com>
---
builtin/ls-files.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index b1626b13b..927aa6746 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);
}
}
}
--
2.13.1.518.g3df882009-goog
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 15/17] ls-files: convert show_files to take an index
2017-06-12 22:13 [PATCH 00/17] convert ls-files internals to pass around an index Brandon Williams
` (13 preceding siblings ...)
2017-06-12 22:14 ` [PATCH 14/17] ls-files: convert show_ce_entry " Brandon Williams
@ 2017-06-12 22:14 ` Brandon Williams
2017-06-12 22:14 ` [PATCH 16/17] ls-files: factor out debug info into a function Brandon Williams
2017-06-12 22:14 ` [PATCH 17/17] ls-files: factor out tag calculation Brandon Williams
16 siblings, 0 replies; 18+ messages in thread
From: Brandon Williams @ 2017-06-12 22:14 UTC (permalink / raw)
To: git; +Cc: gitster, Brandon Williams
Signed-off-by: Brandon Williams <bmwill@google.com>
---
builtin/ls-files.c | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 927aa6746..55d6f54fd 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);
--
2.13.1.518.g3df882009-goog
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 16/17] ls-files: factor out debug info into a function
2017-06-12 22:13 [PATCH 00/17] convert ls-files internals to pass around an index Brandon Williams
` (14 preceding siblings ...)
2017-06-12 22:14 ` [PATCH 15/17] ls-files: convert show_files " Brandon Williams
@ 2017-06-12 22:14 ` Brandon Williams
2017-06-12 22:14 ` [PATCH 17/17] ls-files: factor out tag calculation Brandon Williams
16 siblings, 0 replies; 18+ messages in thread
From: Brandon Williams @ 2017-06-12 22:14 UTC (permalink / raw)
To: git; +Cc: gitster, Brandon Williams
Signed-off-by: Brandon Williams <bmwill@google.com>
---
builtin/ls-files.c | 23 ++++++++++++++---------
1 file changed, 14 insertions(+), 9 deletions(-)
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 55d6f54fd..c9307f9ef 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);
--
2.13.1.518.g3df882009-goog
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 17/17] ls-files: factor out tag calculation
2017-06-12 22:13 [PATCH 00/17] convert ls-files internals to pass around an index Brandon Williams
` (15 preceding siblings ...)
2017-06-12 22:14 ` [PATCH 16/17] ls-files: factor out debug info into a function Brandon Williams
@ 2017-06-12 22:14 ` Brandon Williams
16 siblings, 0 replies; 18+ messages in thread
From: Brandon Williams @ 2017-06-12 22:14 UTC (permalink / raw)
To: git; +Cc: gitster, Brandon Williams
Signed-off-by: Brandon Williams <bmwill@google.com>
---
builtin/ls-files.c | 41 +++++++++++++++++++++++++----------------
1 file changed, 25 insertions(+), 16 deletions(-)
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index c9307f9ef..cdc1cfdd2 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);
--
2.13.1.518.g3df882009-goog
^ permalink raw reply related [flat|nested] 18+ messages in thread
end of thread, other threads:[~2017-06-12 22:15 UTC | newest]
Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-12 22:13 [PATCH 00/17] convert ls-files internals to pass around an index Brandon Williams
2017-06-12 22:13 ` [PATCH 01/17] convert: convert get_cached_convert_stats_ascii to take " Brandon Williams
2017-06-12 22:13 ` [PATCH 02/17] convert: convert crlf_to_git " Brandon Williams
2017-06-12 22:13 ` [PATCH 03/17] convert: convert convert_to_git_filter_fd " Brandon Williams
2017-06-12 22:13 ` [PATCH 04/17] convert: convert convert_to_git " Brandon Williams
2017-06-12 22:13 ` [PATCH 05/17] convert: convert renormalize_buffer " Brandon Williams
2017-06-12 22:13 ` [PATCH 06/17] tree: convert read_tree to take an index parameter Brandon Williams
2017-06-12 22:13 ` [PATCH 07/17] ls-files: convert overlay_tree_on_cache to take an index Brandon Williams
2017-06-12 22:13 ` [PATCH 08/17] ls-files: convert write_eolinfo " Brandon Williams
2017-06-12 22:14 ` [PATCH 09/17] ls-files: convert show_killed_files " Brandon Williams
2017-06-12 22:14 ` [PATCH 10/17] ls-files: convert show_other_files " Brandon Williams
2017-06-12 22:14 ` [PATCH 11/17] ls-files: convert show_ru_info " Brandon Williams
2017-06-12 22:14 ` [PATCH 12/17] ls-files: convert ce_excluded " Brandon Williams
2017-06-12 22:14 ` [PATCH 13/17] ls-files: convert prune_cache " Brandon Williams
2017-06-12 22:14 ` [PATCH 14/17] ls-files: convert show_ce_entry " Brandon Williams
2017-06-12 22:14 ` [PATCH 15/17] ls-files: convert show_files " Brandon Williams
2017-06-12 22:14 ` [PATCH 16/17] ls-files: factor out debug info into a function Brandon Williams
2017-06-12 22:14 ` [PATCH 17/17] ls-files: factor out tag calculation Brandon Williams
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.