diff-lib, read-tree, unpack-trees: mark cache_entry pointers const
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 <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Jun 2, 2013 at 17:46 UTC
eb9ae4b505bfacc4974a9ef4f4e6996c78d04a4c
3 files changed
+63
-53
builtin/read-tree.c
+1
-1
@@ -66,7 +66,7 @@ static int exclude_per_directory_cb(const struct option *opt, const char *arg,
66
return 0;
67
}
68
69
-static void debug_stage(const char *label, struct cache_entry *ce,
69
+static void debug_stage(const char *label, const struct cache_entry *ce,
70
struct unpack_trees_options *o)
71
{
72
printf("%s ", label);
diff-lib.c
+12
-11
@@ -64,8 +64,9 @@ static int check_removed(const struct cache_entry *ce, struct stat *st)
64
* commits, untracked content and/or modified content).
65
*/
66
static int match_stat_with_submodule(struct diff_options *diffopt,
67
- struct cache_entry *ce, struct stat *st,
68
- unsigned ce_option, unsigned *dirty_submodule)
67
+ const struct cache_entry *ce,
68
+ struct stat *st, unsigned ce_option,
69
+ unsigned *dirty_submodule)
70
{
71
int changed = ce_match_stat(ce, st, ce_option);
72
if (S_ISGITLINK(ce->ce_mode)) {
@@ -237,7 +238,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
238
/* A file entry went away or appeared */
239
static void diff_index_show_file(struct rev_info *revs,
240
const char *prefix,
240
- struct cache_entry *ce,
241
+ const struct cache_entry *ce,
242
const unsigned char *sha1, int sha1_valid,
243
unsigned int mode,
244
unsigned dirty_submodule)
@@ -246,7 +247,7 @@ static void diff_index_show_file(struct rev_info *revs,
247
sha1, sha1_valid, ce->name, dirty_submodule);
248
}
249
249
-static int get_stat_data(struct cache_entry *ce,
250
+static int get_stat_data(const struct cache_entry *ce,
251
const unsigned char **sha1p,
252
unsigned int *modep,
253
int cached, int match_missing,
@@ -283,7 +284,7 @@ static int get_stat_data(struct cache_entry *ce,
284
}
285
286
static void show_new_file(struct rev_info *revs,
286
- struct cache_entry *new,
287
+ const struct cache_entry *new,
288
int cached, int match_missing)
289
{
290
const unsigned char *sha1;
@@ -302,8 +303,8 @@ static void show_new_file(struct rev_info *revs,
303
}
304
305
static int show_modified(struct rev_info *revs,
305
- struct cache_entry *old,
306
- struct cache_entry *new,
306
+ const struct cache_entry *old,
307
+ const struct cache_entry *new,
308
int report_missing,
309
int cached, int match_missing)
310
{
@@ -362,8 +363,8 @@ static int show_modified(struct rev_info *revs,
363
* give you the position and number of entries in the index).
364
*/
365
static void do_oneway_diff(struct unpack_trees_options *o,
365
- struct cache_entry *idx,
366
- struct cache_entry *tree)
366
+ const struct cache_entry *idx,
367
+ const struct cache_entry *tree)
368
{
369
struct rev_info *revs = o->unpack_data;
370
int match_missing, cached;
@@ -425,8 +426,8 @@ static void do_oneway_diff(struct unpack_trees_options *o,
426
*/
427
static int oneway_diff(struct cache_entry **src, struct unpack_trees_options *o)
428
{
428
- struct cache_entry *idx = src[0];
429
- struct cache_entry *tree = src[1];
429
+ const struct cache_entry *idx = src[0];
430
+ const struct cache_entry *tree = src[1];
431
struct rev_info *revs = o->unpack_data;
432
433
/*
unpack-trees.c
+50
-41
@@ -241,8 +241,11 @@ static int check_updates(struct unpack_trees_options *o)
241
return errs != 0;
242
}
243
244
-static int verify_uptodate_sparse(struct cache_entry *ce, struct unpack_trees_options *o);
245
-static int verify_absent_sparse(struct cache_entry *ce, enum unpack_trees_error_types, struct unpack_trees_options *o);
244
+static int verify_uptodate_sparse(const struct cache_entry *ce,
245
+ struct unpack_trees_options *o);
246
+static int verify_absent_sparse(const struct cache_entry *ce,
247
+ enum unpack_trees_error_types,
248
+ struct unpack_trees_options *o);
249
250
static int apply_sparse_checkout(struct cache_entry *ce, struct unpack_trees_options *o)
251
{
@@ -326,7 +329,7 @@ static void mark_all_ce_unused(struct index_state *index)
329
index->cache[i]->ce_flags &= ~(CE_UNPACKED | CE_ADDED | CE_NEW_SKIP_WORKTREE);
330
}
331
329
-static int locate_in_src_index(struct cache_entry *ce,
332
+static int locate_in_src_index(const struct cache_entry *ce,
333
struct unpack_trees_options *o)
334
{
335
struct index_state *index = o->src_index;
@@ -1001,7 +1004,9 @@ static void mark_new_skip_worktree(struct exclude_list *el,
1004
select_flag, skip_wt_flag, el);
1005
}
1006
1004
-static int verify_absent(struct cache_entry *, enum unpack_trees_error_types, struct unpack_trees_options *);
1007
+static int verify_absent(const struct cache_entry *,
1008
+ enum unpack_trees_error_types,
1009
+ struct unpack_trees_options *);
1010
/*
1011
* N-way merge "len" trees. Returns 0 on success, -1 on failure to manipulate the
1012
* resulting index, -2 on failure to reflect the changes to the work tree.
@@ -1171,12 +1176,13 @@ return_failed:
1176
1177
/* Here come the merge functions */
1178
1174
-static int reject_merge(struct cache_entry *ce, struct unpack_trees_options *o)
1179
+static int reject_merge(const struct cache_entry *ce,
1180
+ struct unpack_trees_options *o)
1181
{
1182
return add_rejected_path(o, ERROR_WOULD_OVERWRITE, ce->name);
1183
}
1184
1179
-static int same(struct cache_entry *a, struct cache_entry *b)
1185
+static int same(const struct cache_entry *a, const struct cache_entry *b)
1186
{
1187
if (!!a != !!b)
1188
return 0;
@@ -1193,9 +1199,9 @@ static int same(struct cache_entry *a, struct cache_entry *b)
1199
* When a CE gets turned into an unmerged entry, we
1200
* want it to be up-to-date
1201
*/
1196
-static int verify_uptodate_1(struct cache_entry *ce,
1197
- struct unpack_trees_options *o,
1198
- enum unpack_trees_error_types error_type)
1202
+static int verify_uptodate_1(const struct cache_entry *ce,
1203
+ struct unpack_trees_options *o,
1204
+ enum unpack_trees_error_types error_type)
1205
{
1206
struct stat st;
1207
@@ -1234,7 +1240,7 @@ static int verify_uptodate_1(struct cache_entry *ce,
1240
add_rejected_path(o, error_type, ce->name);
1241
}
1242
1237
-static int verify_uptodate(struct cache_entry *ce,
1243
+static int verify_uptodate(const struct cache_entry *ce,
1244
struct unpack_trees_options *o)
1245
{
1246
if (!o->skip_sparse_checkout && (ce->ce_flags & CE_NEW_SKIP_WORKTREE))
@@ -1242,13 +1248,14 @@ static int verify_uptodate(struct cache_entry *ce,
1248
return verify_uptodate_1(ce, o, ERROR_NOT_UPTODATE_FILE);
1249
}
1250
1245
-static int verify_uptodate_sparse(struct cache_entry *ce,
1251
+static int verify_uptodate_sparse(const struct cache_entry *ce,
1252
struct unpack_trees_options *o)
1253
{
1254
return verify_uptodate_1(ce, o, ERROR_SPARSE_NOT_UPTODATE_FILE);
1255
}
1256
1251
-static void invalidate_ce_path(struct cache_entry *ce, struct unpack_trees_options *o)
1257
+static void invalidate_ce_path(const struct cache_entry *ce,
1258
+ struct unpack_trees_options *o)
1259
{
1260
if (ce)
1261
cache_tree_invalidate_path(o->src_index->cache_tree, ce->name);
@@ -1261,16 +1268,16 @@ static void invalidate_ce_path(struct cache_entry *ce, struct unpack_trees_optio
1268
* Currently, git does not checkout subprojects during a superproject
1269
* checkout, so it is not going to overwrite anything.
1270
*/
1264
-static int verify_clean_submodule(struct cache_entry *ce,
1265
- enum unpack_trees_error_types error_type,
1266
- struct unpack_trees_options *o)
1271
+static int verify_clean_submodule(const struct cache_entry *ce,
1272
+ enum unpack_trees_error_types error_type,
1273
+ struct unpack_trees_options *o)
1274
{
1275
return 0;
1276
}
1277
1271
-static int verify_clean_subdirectory(struct cache_entry *ce,
1272
- enum unpack_trees_error_types error_type,
1273
- struct unpack_trees_options *o)
1278
+static int verify_clean_subdirectory(const struct cache_entry *ce,
1279
+ enum unpack_trees_error_types error_type,
1280
+ struct unpack_trees_options *o)
1281
{
1282
/*
1283
* we are about to extract "ce->name"; we would not want to lose
@@ -1356,7 +1363,7 @@ static int icase_exists(struct unpack_trees_options *o, const char *name, int le
1363
}
1364
1365
static int check_ok_to_remove(const char *name, int len, int dtype,
1359
- struct cache_entry *ce, struct stat *st,
1366
+ const struct cache_entry *ce, struct stat *st,
1367
enum unpack_trees_error_types error_type,
1368
struct unpack_trees_options *o)
1369
{
@@ -1411,9 +1418,9 @@ static int check_ok_to_remove(const char *name, int len, int dtype,
1418
* We do not want to remove or overwrite a working tree file that
1419
* is not tracked, unless it is ignored.
1420
*/
1414
-static int verify_absent_1(struct cache_entry *ce,
1415
- enum unpack_trees_error_types error_type,
1416
- struct unpack_trees_options *o)
1421
+static int verify_absent_1(const struct cache_entry *ce,
1422
+ enum unpack_trees_error_types error_type,
1423
+ struct unpack_trees_options *o)
1424
{
1425
int len;
1426
struct stat st;
@@ -1446,7 +1453,7 @@ static int verify_absent_1(struct cache_entry *ce,
1453
}
1454
}
1455
1449
-static int verify_absent(struct cache_entry *ce,
1456
+static int verify_absent(const struct cache_entry *ce,
1457
enum unpack_trees_error_types error_type,
1458
struct unpack_trees_options *o)
1459
{
@@ -1455,9 +1462,9 @@ static int verify_absent(struct cache_entry *ce,
1462
return verify_absent_1(ce, error_type, o);
1463
}
1464
1458
-static int verify_absent_sparse(struct cache_entry *ce,
1459
- enum unpack_trees_error_types error_type,
1460
- struct unpack_trees_options *o)
1465
+static int verify_absent_sparse(const struct cache_entry *ce,
1466
+ enum unpack_trees_error_types error_type,
1467
+ struct unpack_trees_options *o)
1468
{
1469
enum unpack_trees_error_types orphaned_error = error_type;
1470
if (orphaned_error == ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN)
@@ -1467,7 +1474,7 @@ static int verify_absent_sparse(struct cache_entry *ce,
1474
}
1475
1476
static int merged_entry(const struct cache_entry *ce,
1470
- struct cache_entry *old,
1477
+ const struct cache_entry *old,
1478
struct unpack_trees_options *o)
1479
{
1480
int update = CE_UPDATE;
@@ -1527,8 +1534,9 @@ static int merged_entry(const struct cache_entry *ce,
1534
return 1;
1535
}
1536
1530
-static int deleted_entry(struct cache_entry *ce, struct cache_entry *old,
1531
- struct unpack_trees_options *o)
1537
+static int deleted_entry(const struct cache_entry *ce,
1538
+ const struct cache_entry *old,
1539
+ struct unpack_trees_options *o)
1540
{
1541
/* Did it exist in the index? */
1542
if (!old) {
@@ -1543,7 +1551,8 @@ static int deleted_entry(struct cache_entry *ce, struct cache_entry *old,
1551
return 1;
1552
}
1553
1546
-static int keep_entry(struct cache_entry *ce, struct unpack_trees_options *o)
1554
+static int keep_entry(const struct cache_entry *ce,
1555
+ struct unpack_trees_options *o)
1556
{
1557
add_entry(o, ce, 0, 0);
1558
return 1;
@@ -1567,9 +1576,9 @@ static void show_stage_entry(FILE *o,
1576
1577
int threeway_merge(struct cache_entry **stages, struct unpack_trees_options *o)
1578
{
1570
- struct cache_entry *index;
1571
- struct cache_entry *head;
1572
- struct cache_entry *remote = stages[o->head_idx + 1];
1579
+ const struct cache_entry *index;
1580
+ const struct cache_entry *head;
1581
+ const struct cache_entry *remote = stages[o->head_idx + 1];
1582
int count;
1583
int head_match = 0;
1584
int remote_match = 0;
@@ -1654,7 +1663,7 @@ int threeway_merge(struct cache_entry **stages, struct unpack_trees_options *o)
1663
if (o->aggressive) {
1664
int head_deleted = !head;
1665
int remote_deleted = !remote;
1657
- struct cache_entry *ce = NULL;
1666
+ const struct cache_entry *ce = NULL;
1667
1668
if (index)
1669
ce = index;
@@ -1739,9 +1748,9 @@ int threeway_merge(struct cache_entry **stages, struct unpack_trees_options *o)
1748
*/
1749
int twoway_merge(struct cache_entry **src, struct unpack_trees_options *o)
1750
{
1742
- struct cache_entry *current = src[0];
1743
- struct cache_entry *oldtree = src[1];
1744
- struct cache_entry *newtree = src[2];
1751
+ const struct cache_entry *current = src[0];
1752
+ const struct cache_entry *oldtree = src[1];
1753
+ const struct cache_entry *newtree = src[2];
1754
1755
if (o->merge_size != 2)
1756
return error("Cannot do a twoway merge of %d trees",
@@ -1806,8 +1815,8 @@ int twoway_merge(struct cache_entry **src, struct unpack_trees_options *o)
1815
int bind_merge(struct cache_entry **src,
1816
struct unpack_trees_options *o)
1817
{
1809
- struct cache_entry *old = src[0];
1810
- struct cache_entry *a = src[1];
1818
+ const struct cache_entry *old = src[0];
1819
+ const struct cache_entry *a = src[1];
1820
1821
if (o->merge_size != 1)
1822
return error("Cannot do a bind merge of %d trees",
@@ -1829,8 +1838,8 @@ int bind_merge(struct cache_entry **src,
1838
*/
1839
int oneway_merge(struct cache_entry **src, struct unpack_trees_options *o)
1840
{
1832
- struct cache_entry *old = src[0];
1833
- struct cache_entry *a = src[1];
1841
+ const struct cache_entry *old = src[0];
1842
+ const struct cache_entry *a = src[1];
1843
1844
if (o->merge_size != 1)
1845
return error("Cannot do a oneway merge of %d trees",