diff-lib, read-tree, unpack-trees: mark cache_entry array paramters const
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>
René Scharfe committed
Jun 2, 2013 at 17:46 UTC
5828e8352c07753a1f751322800524bf9dff8679
4 files changed
+26
-15
builtin/read-tree.c
+2
-1
@@ -80,7 +80,8 @@ static void debug_stage(const char *label, const struct cache_entry *ce,
80
sha1_to_hex(ce->sha1));
81
}
82
83
-static int debug_merge(struct cache_entry **stages, struct unpack_trees_options *o)
83
+static int debug_merge(const struct cache_entry * const *stages,
84
+ struct unpack_trees_options *o)
85
{
86
int i;
87
diff-lib.c
+2
-1
@@ -424,7 +424,8 @@ static void do_oneway_diff(struct unpack_trees_options *o,
424
* the fairly complex unpack_trees() semantic requirements, including
425
* the skipping, the path matching, the type conflict cases etc.
426
*/
427
-static int oneway_diff(struct cache_entry **src, struct unpack_trees_options *o)
427
+static int oneway_diff(const struct cache_entry * const *src,
428
+ struct unpack_trees_options *o)
429
{
430
const struct cache_entry *idx = src[0];
431
const struct cache_entry *tree = src[1];
unpack-trees.c
+13
-8
@@ -300,7 +300,8 @@ static int apply_sparse_checkout(struct cache_entry *ce, struct unpack_trees_opt
300
return 0;
301
}
302
303
-static inline int call_unpack_fn(struct cache_entry **src, struct unpack_trees_options *o)
303
+static inline int call_unpack_fn(const struct cache_entry * const *src,
304
+ struct unpack_trees_options *o)
305
{
306
int ret = o->fn(src, o);
307
if (ret > 0)
@@ -397,7 +398,7 @@ static void add_same_unmerged(struct cache_entry *ce,
398
static int unpack_index_entry(struct cache_entry *ce,
399
struct unpack_trees_options *o)
400
{
400
- struct cache_entry *src[MAX_UNPACK_TREES + 1] = { NULL, };
401
+ const struct cache_entry *src[MAX_UNPACK_TREES + 1] = { NULL, };
402
int ret;
403
404
src[0] = ce;
@@ -600,7 +601,8 @@ static int unpack_nondirectories(int n, unsigned long mask,
601
}
602
603
if (o->merge)
603
- return call_unpack_fn(src, o);
604
+ return call_unpack_fn((const struct cache_entry * const *)src,
605
+ o);
606
607
for (i = 0; i < n; i++)
608
if (src[i] && src[i] != o->df_conflict_entry)
@@ -1574,7 +1576,8 @@ static void show_stage_entry(FILE *o,
1576
}
1577
#endif
1578
1577
-int threeway_merge(struct cache_entry **stages, struct unpack_trees_options *o)
1579
+int threeway_merge(const struct cache_entry * const *stages,
1580
+ struct unpack_trees_options *o)
1581
{
1582
const struct cache_entry *index;
1583
const struct cache_entry *head;
@@ -1746,7 +1749,8 @@ int threeway_merge(struct cache_entry **stages, struct unpack_trees_options *o)
1749
* "carry forward" rule, please see <Documentation/git-read-tree.txt>.
1750
*
1751
*/
1749
-int twoway_merge(struct cache_entry **src, struct unpack_trees_options *o)
1752
+int twoway_merge(const struct cache_entry * const *src,
1753
+ struct unpack_trees_options *o)
1754
{
1755
const struct cache_entry *current = src[0];
1756
const struct cache_entry *oldtree = src[1];
@@ -1812,8 +1816,8 @@ int twoway_merge(struct cache_entry **src, struct unpack_trees_options *o)
1816
* Keep the index entries at stage0, collapse stage1 but make sure
1817
* stage0 does not have anything there.
1818
*/
1815
-int bind_merge(struct cache_entry **src,
1816
- struct unpack_trees_options *o)
1819
+int bind_merge(const struct cache_entry * const *src,
1820
+ struct unpack_trees_options *o)
1821
{
1822
const struct cache_entry *old = src[0];
1823
const struct cache_entry *a = src[1];
@@ -1836,7 +1840,8 @@ int bind_merge(struct cache_entry **src,
1840
* The rule is:
1841
* - take the stat information from stage0, take the data from stage1
1842
*/
1839
-int oneway_merge(struct cache_entry **src, struct unpack_trees_options *o)
1843
+int oneway_merge(const struct cache_entry * const *src,
1844
+ struct unpack_trees_options *o)
1845
{
1846
const struct cache_entry *old = src[0];
1847
const struct cache_entry *a = src[1];
unpack-trees.h
+9
-5
@@ -8,7 +8,7 @@
8
struct unpack_trees_options;
9
struct exclude_list;
10
11
-typedef int (*merge_fn_t)(struct cache_entry **src,
11
+typedef int (*merge_fn_t)(const struct cache_entry * const *src,
12
struct unpack_trees_options *options);
13
14
enum unpack_trees_error_types {
@@ -77,9 +77,13 @@ struct unpack_trees_options {
77
extern int unpack_trees(unsigned n, struct tree_desc *t,
78
struct unpack_trees_options *options);
79
80
-int threeway_merge(struct cache_entry **stages, struct unpack_trees_options *o);
81
-int twoway_merge(struct cache_entry **src, struct unpack_trees_options *o);
82
-int bind_merge(struct cache_entry **src, struct unpack_trees_options *o);
83
-int oneway_merge(struct cache_entry **src, struct unpack_trees_options *o);
80
+int threeway_merge(const struct cache_entry * const *stages,
81
+ struct unpack_trees_options *o);
82
+int twoway_merge(const struct cache_entry * const *src,
83
+ struct unpack_trees_options *o);
84
+int bind_merge(const struct cache_entry * const *src,
85
+ struct unpack_trees_options *o);
86
+int oneway_merge(const struct cache_entry * const *src,
87
+ struct unpack_trees_options *o);
88
89
#endif