Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
diff-lib, read-tree, unpack-trees: mark cache_entry array paramters c…
…onst

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 <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
René Scharfe authored and Junio C Hamano committed Jun 2, 2013
1 parent eb9ae4b commit 5828e83
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
3 changes: 2 additions & 1 deletion builtin/read-tree.c
Expand Up @@ -80,7 +80,8 @@ static void debug_stage(const char *label, const struct cache_entry *ce,
sha1_to_hex(ce->sha1));
}

static int debug_merge(struct cache_entry **stages, struct unpack_trees_options *o)
static int debug_merge(const struct cache_entry * const *stages,
struct unpack_trees_options *o)
{
int i;

Expand Down
3 changes: 2 additions & 1 deletion diff-lib.c
Expand Up @@ -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];
Expand Down
21 changes: 13 additions & 8 deletions unpack-trees.c
Expand Up @@ -300,7 +300,8 @@ static int apply_sparse_checkout(struct cache_entry *ce, struct unpack_trees_opt
return 0;
}

static inline int call_unpack_fn(struct cache_entry **src, struct unpack_trees_options *o)
static inline int call_unpack_fn(const struct cache_entry * const *src,
struct unpack_trees_options *o)
{
int ret = o->fn(src, o);
if (ret > 0)
Expand Down Expand Up @@ -397,7 +398,7 @@ static void add_same_unmerged(struct cache_entry *ce,
static int unpack_index_entry(struct cache_entry *ce,
struct unpack_trees_options *o)
{
struct cache_entry *src[MAX_UNPACK_TREES + 1] = { NULL, };
const struct cache_entry *src[MAX_UNPACK_TREES + 1] = { NULL, };
int ret;

src[0] = ce;
Expand Down Expand Up @@ -600,7 +601,8 @@ static int unpack_nondirectories(int n, unsigned long mask,
}

if (o->merge)
return call_unpack_fn(src, o);
return call_unpack_fn((const struct cache_entry * const *)src,
o);

for (i = 0; i < n; i++)
if (src[i] && src[i] != o->df_conflict_entry)
Expand Down Expand Up @@ -1574,7 +1576,8 @@ static void show_stage_entry(FILE *o,
}
#endif

int threeway_merge(struct cache_entry **stages, struct unpack_trees_options *o)
int threeway_merge(const struct cache_entry * const *stages,
struct unpack_trees_options *o)
{
const struct cache_entry *index;
const struct cache_entry *head;
Expand Down Expand Up @@ -1746,7 +1749,8 @@ int threeway_merge(struct cache_entry **stages, struct unpack_trees_options *o)
* "carry forward" rule, please see <Documentation/git-read-tree.txt>.
*
*/
int twoway_merge(struct cache_entry **src, struct unpack_trees_options *o)
int twoway_merge(const struct cache_entry * const *src,
struct unpack_trees_options *o)
{
const struct cache_entry *current = src[0];
const struct cache_entry *oldtree = src[1];
Expand Down Expand Up @@ -1812,8 +1816,8 @@ int twoway_merge(struct cache_entry **src, struct unpack_trees_options *o)
* Keep the index entries at stage0, collapse stage1 but make sure
* stage0 does not have anything there.
*/
int bind_merge(struct cache_entry **src,
struct unpack_trees_options *o)
int bind_merge(const struct cache_entry * const *src,
struct unpack_trees_options *o)
{
const struct cache_entry *old = src[0];
const struct cache_entry *a = src[1];
Expand All @@ -1836,7 +1840,8 @@ int bind_merge(struct cache_entry **src,
* The rule is:
* - take the stat information from stage0, take the data from stage1
*/
int oneway_merge(struct cache_entry **src, struct unpack_trees_options *o)
int oneway_merge(const struct cache_entry * const *src,
struct unpack_trees_options *o)
{
const struct cache_entry *old = src[0];
const struct cache_entry *a = src[1];
Expand Down
14 changes: 9 additions & 5 deletions unpack-trees.h
Expand Up @@ -8,7 +8,7 @@
struct unpack_trees_options;
struct exclude_list;

typedef int (*merge_fn_t)(struct cache_entry **src,
typedef int (*merge_fn_t)(const struct cache_entry * const *src,
struct unpack_trees_options *options);

enum unpack_trees_error_types {
Expand Down Expand Up @@ -77,9 +77,13 @@ struct unpack_trees_options {
extern int unpack_trees(unsigned n, struct tree_desc *t,
struct unpack_trees_options *options);

int threeway_merge(struct cache_entry **stages, struct unpack_trees_options *o);
int twoway_merge(struct cache_entry **src, struct unpack_trees_options *o);
int bind_merge(struct cache_entry **src, struct unpack_trees_options *o);
int oneway_merge(struct cache_entry **src, struct unpack_trees_options *o);
int threeway_merge(const struct cache_entry * const *stages,
struct unpack_trees_options *o);
int twoway_merge(const struct cache_entry * const *src,
struct unpack_trees_options *o);
int bind_merge(const struct cache_entry * const *src,
struct unpack_trees_options *o);
int oneway_merge(const struct cache_entry * const *src,
struct unpack_trees_options *o);

#endif

0 comments on commit 5828e83

Please sign in to comment.