From eb9ae4b505bfacc4974a9ef4f4e6996c78d04a4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Sun, 2 Jun 2013 17:46:55 +0200 Subject: diff-lib, read-tree, unpack-trees: mark cache_entry pointers const MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add const to struct cache_entry pointers throughout the tree which are only used for reading. This allows callers to pass in const pointers. Signed-off-by: René Scharfe Signed-off-by: Junio C Hamano --- diff-lib.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'diff-lib.c') diff --git a/diff-lib.c b/diff-lib.c index f35de0ffa0..83d0cb8f82 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -64,8 +64,9 @@ static int check_removed(const struct cache_entry *ce, struct stat *st) * commits, untracked content and/or modified content). */ static int match_stat_with_submodule(struct diff_options *diffopt, - struct cache_entry *ce, struct stat *st, - unsigned ce_option, unsigned *dirty_submodule) + const struct cache_entry *ce, + struct stat *st, unsigned ce_option, + unsigned *dirty_submodule) { int changed = ce_match_stat(ce, st, ce_option); if (S_ISGITLINK(ce->ce_mode)) { @@ -237,7 +238,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option) /* A file entry went away or appeared */ static void diff_index_show_file(struct rev_info *revs, const char *prefix, - struct cache_entry *ce, + const struct cache_entry *ce, const unsigned char *sha1, int sha1_valid, unsigned int mode, unsigned dirty_submodule) @@ -246,7 +247,7 @@ static void diff_index_show_file(struct rev_info *revs, sha1, sha1_valid, ce->name, dirty_submodule); } -static int get_stat_data(struct cache_entry *ce, +static int get_stat_data(const struct cache_entry *ce, const unsigned char **sha1p, unsigned int *modep, int cached, int match_missing, @@ -283,7 +284,7 @@ static int get_stat_data(struct cache_entry *ce, } static void show_new_file(struct rev_info *revs, - struct cache_entry *new, + const struct cache_entry *new, int cached, int match_missing) { const unsigned char *sha1; @@ -302,8 +303,8 @@ static void show_new_file(struct rev_info *revs, } static int show_modified(struct rev_info *revs, - struct cache_entry *old, - struct cache_entry *new, + const struct cache_entry *old, + const struct cache_entry *new, int report_missing, int cached, int match_missing) { @@ -362,8 +363,8 @@ static int show_modified(struct rev_info *revs, * give you the position and number of entries in the index). */ static void do_oneway_diff(struct unpack_trees_options *o, - struct cache_entry *idx, - struct cache_entry *tree) + const struct cache_entry *idx, + const struct cache_entry *tree) { struct rev_info *revs = o->unpack_data; int match_missing, cached; @@ -425,8 +426,8 @@ static void do_oneway_diff(struct unpack_trees_options *o, */ static int oneway_diff(struct cache_entry **src, struct unpack_trees_options *o) { - struct cache_entry *idx = src[0]; - struct cache_entry *tree = src[1]; + const struct cache_entry *idx = src[0]; + const struct cache_entry *tree = src[1]; struct rev_info *revs = o->unpack_data; /* -- cgit v1.2.3 From 5828e8352c07753a1f751322800524bf9dff8679 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Sun, 2 Jun 2013 17:46:56 +0200 Subject: diff-lib, read-tree, unpack-trees: mark cache_entry array paramters const MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change the type merge_fn_t to accept the array of cache_entry pointers as const pointers to const pointers. This documents the fact that the merge functions don't modify the cache_entry contents or replace any of the pointers in the array. Only a single cast is necessary in unpack_nondirectories because adding two const modifiers at once is not allowed in C. The cast is safe in that it doesn't mask any modfication; call_unpack_fn only needs the array for reading. Signed-off-by: René Scharfe Signed-off-by: Junio C Hamano --- diff-lib.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'diff-lib.c') diff --git a/diff-lib.c b/diff-lib.c index 83d0cb8f82..b6f4b21637 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -424,7 +424,8 @@ static void do_oneway_diff(struct unpack_trees_options *o, * the fairly complex unpack_trees() semantic requirements, including * the skipping, the path matching, the type conflict cases etc. */ -static int oneway_diff(struct cache_entry **src, struct unpack_trees_options *o) +static int oneway_diff(const struct cache_entry * const *src, + struct unpack_trees_options *o) { const struct cache_entry *idx = src[0]; const struct cache_entry *tree = src[1]; -- cgit v1.2.3