Add const to all shared pointers in diff API There are a lot of places where the diff API gives the user access to internal data structures and many of these were being exposed through non-const pointers. This replaces them all with const pointers for any object that the user can access but is still owned internally to the git_diff_list or git_diff_patch objects. This will probably break some bindings... Sorry!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479
diff --git a/include/git2/diff.h b/include/git2/diff.h
index 1542645..1c41a54 100644
--- a/include/git2/diff.h
+++ b/include/git2/diff.h
@@ -122,7 +122,7 @@ typedef enum {
*/
typedef struct {
git_oid oid;
- char *path;
+ const char *path;
git_off_t size;
unsigned int flags;
uint16_t mode;
@@ -154,7 +154,7 @@ typedef struct {
*/
typedef int (*git_diff_file_fn)(
void *cb_data,
- git_diff_delta *delta,
+ const git_diff_delta *delta,
float progress);
/**
@@ -172,8 +172,8 @@ typedef struct {
*/
typedef int (*git_diff_hunk_fn)(
void *cb_data,
- git_diff_delta *delta,
- git_diff_range *range,
+ const git_diff_delta *delta,
+ const git_diff_range *range,
const char *header,
size_t header_len);
@@ -213,8 +213,8 @@ enum {
*/
typedef int (*git_diff_data_fn)(
void *cb_data,
- git_diff_delta *delta,
- git_diff_range *range,
+ const git_diff_delta *delta,
+ const git_diff_range *range,
char line_origin, /**< GIT_DIFF_LINE_... value from above */
const char *content,
size_t content_len);
@@ -486,7 +486,7 @@ GIT_EXTERN(size_t) git_diff_num_deltas_of_type(
*/
GIT_EXTERN(int) git_diff_get_patch(
git_diff_patch **patch,
- git_diff_delta **delta,
+ const git_diff_delta **delta,
git_diff_list *diff,
size_t idx);
@@ -525,7 +525,7 @@ GIT_EXTERN(size_t) git_diff_patch_num_hunks(
* @return 0 on success, GIT_ENOTFOUND if hunk_idx out of range, <0 on error
*/
GIT_EXTERN(int) git_diff_patch_get_hunk(
- git_diff_range **range,
+ const git_diff_range **range,
const char **header,
size_t *header_len,
size_t *lines_in_hunk,
@@ -595,7 +595,7 @@ GIT_EXTERN(int) git_diff_patch_get_line_in_hunk(
GIT_EXTERN(int) git_diff_blobs(
git_blob *old_blob,
git_blob *new_blob,
- git_diff_options *options,
+ const git_diff_options *options,
void *cb_data,
git_diff_file_fn file_cb,
git_diff_hunk_fn hunk_cb,
diff --git a/src/checkout.c b/src/checkout.c
index 7cf9fe0..e429d28 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -126,7 +126,7 @@ static int blob_content_to_link(git_blob *blob, const char *path, bool can_symli
static int checkout_blob(
git_repository *repo,
- git_oid *blob_oid,
+ const git_oid *blob_oid,
const char *path,
mode_t filemode,
bool can_symlink,
@@ -150,7 +150,7 @@ static int checkout_blob(
static int checkout_diff_fn(
void *cb_data,
- git_diff_delta *delta,
+ const git_diff_delta *delta,
float progress)
{
struct checkout_diff_data *data;
diff --git a/src/diff.c b/src/diff.c
index 7ee919b..4dedbe8 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -809,7 +809,7 @@ on_error:
bool git_diff_delta__should_skip(
- git_diff_options *opts, git_diff_delta *delta)
+ const git_diff_options *opts, const git_diff_delta *delta)
{
uint32_t flags = opts ? opts->flags : 0;
diff --git a/src/diff.h b/src/diff.h
index 64fe009..15745b2 100644
--- a/src/diff.h
+++ b/src/diff.h
@@ -51,7 +51,7 @@ extern void git_diff__cleanup_modes(
extern void git_diff_list_addref(git_diff_list *diff);
extern bool git_diff_delta__should_skip(
- git_diff_options *opts, git_diff_delta *delta);
+ const git_diff_options *opts, const git_diff_delta *delta);
#endif
diff --git a/src/diff_output.c b/src/diff_output.c
index 1418597..05bca46 100644
--- a/src/diff_output.c
+++ b/src/diff_output.c
@@ -177,7 +177,7 @@ static int diff_delta_is_binary_by_size(
}
static void setup_xdiff_options(
- git_diff_options *opts, xdemitconf_t *cfg, xpparam_t *param)
+ const git_diff_options *opts, xdemitconf_t *cfg, xpparam_t *param)
{
memset(cfg, 0, sizeof(xdemitconf_t));
memset(param, 0, sizeof(xpparam_t));
@@ -371,7 +371,7 @@ static void diff_context_init(
diff_context *ctxt,
git_diff_list *diff,
git_repository *repo,
- git_diff_options *opts,
+ const git_diff_options *opts,
void *data,
git_diff_file_fn file_cb,
git_diff_hunk_fn hunk_cb,
@@ -696,8 +696,8 @@ static void diff_patch_free(git_diff_patch *patch)
static int diff_patch_hunk_cb(
void *cb_data,
- git_diff_delta *delta,
- git_diff_range *range,
+ const git_diff_delta *delta,
+ const git_diff_range *range,
const char *header,
size_t header_len)
{
@@ -743,8 +743,8 @@ static int diff_patch_hunk_cb(
static int diff_patch_line_cb(
void *cb_data,
- git_diff_delta *delta,
- git_diff_range *range,
+ const git_diff_delta *delta,
+ const git_diff_range *range,
char line_origin,
const char *content,
size_t content_len)
@@ -905,7 +905,8 @@ char git_diff_status_char(git_delta_t status)
return code;
}
-static int print_compact(void *data, git_diff_delta *delta, float progress)
+static int print_compact(
+ void *data, const git_diff_delta *delta, float progress)
{
diff_print_info *pi = data;
char old_suffix, new_suffix, code = git_diff_status_char(delta->status);
@@ -967,7 +968,7 @@ int git_diff_print_compact(
return error;
}
-static int print_oid_range(diff_print_info *pi, git_diff_delta *delta)
+static int print_oid_range(diff_print_info *pi, const git_diff_delta *delta)
{
char start_oid[8], end_oid[8];
@@ -997,7 +998,8 @@ static int print_oid_range(diff_print_info *pi, git_diff_delta *delta)
return 0;
}
-static int print_patch_file(void *data, git_diff_delta *delta, float progress)
+static int print_patch_file(
+ void *data, const git_diff_delta *delta, float progress)
{
diff_print_info *pi = data;
const char *oldpfx = pi->diff->opts.old_prefix;
@@ -1064,8 +1066,8 @@ static int print_patch_file(void *data, git_diff_delta *delta, float progress)
static int print_patch_hunk(
void *data,
- git_diff_delta *d,
- git_diff_range *r,
+ const git_diff_delta *d,
+ const git_diff_range *r,
const char *header,
size_t header_len)
{
@@ -1087,8 +1089,8 @@ static int print_patch_hunk(
static int print_patch_line(
void *data,
- git_diff_delta *delta,
- git_diff_range *range,
+ const git_diff_delta *delta,
+ const git_diff_range *range,
char line_origin, /* GIT_DIFF_LINE value from above */
const char *content,
size_t content_len)
@@ -1158,7 +1160,7 @@ static void set_data_from_blob(
int git_diff_blobs(
git_blob *old_blob,
git_blob *new_blob,
- git_diff_options *options,
+ const git_diff_options *options,
void *cb_data,
git_diff_file_fn file_cb,
git_diff_hunk_fn hunk_cb,
@@ -1253,7 +1255,7 @@ size_t git_diff_num_deltas_of_type(git_diff_list *diff, git_delta_t type)
int git_diff_get_patch(
git_diff_patch **patch_ptr,
- git_diff_delta **delta_ptr,
+ const git_diff_delta **delta_ptr,
git_diff_list *diff,
size_t idx)
{
@@ -1326,7 +1328,7 @@ size_t git_diff_patch_num_hunks(git_diff_patch *patch)
}
int git_diff_patch_get_hunk(
- git_diff_range **range,
+ const git_diff_range **range,
const char **header,
size_t *header_len,
size_t *lines_in_hunk,
diff --git a/src/diff_output.h b/src/diff_output.h
index f546390..5fed1d9 100644
--- a/src/diff_output.h
+++ b/src/diff_output.h
@@ -26,7 +26,7 @@ enum {
typedef struct {
git_repository *repo;
git_diff_list *diff;
- git_diff_options *opts;
+ const git_diff_options *opts;
git_diff_file_fn file_cb;
git_diff_hunk_fn hunk_cb;
git_diff_data_fn data_cb;
diff --git a/tests-clar/diff/diff_helpers.c b/tests-clar/diff/diff_helpers.c
index 0c47218..b4c6876 100644
--- a/tests-clar/diff/diff_helpers.c
+++ b/tests-clar/diff/diff_helpers.c
@@ -23,7 +23,7 @@ git_tree *resolve_commit_oid_to_tree(
int diff_file_fn(
void *cb_data,
- git_diff_delta *delta,
+ const git_diff_delta *delta,
float progress)
{
diff_expects *e = cb_data;
@@ -48,8 +48,8 @@ int diff_file_fn(
int diff_hunk_fn(
void *cb_data,
- git_diff_delta *delta,
- git_diff_range *range,
+ const git_diff_delta *delta,
+ const git_diff_range *range,
const char *header,
size_t header_len)
{
@@ -67,8 +67,8 @@ int diff_hunk_fn(
int diff_line_fn(
void *cb_data,
- git_diff_delta *delta,
- git_diff_range *range,
+ const git_diff_delta *delta,
+ const git_diff_range *range,
char line_origin,
const char *content,
size_t content_len)
@@ -116,7 +116,7 @@ int diff_foreach_via_iterator(
for (d = 0; d < num_d; ++d) {
git_diff_patch *patch;
- git_diff_delta *delta;
+ const git_diff_delta *delta;
size_t h, num_h;
cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d));
@@ -142,7 +142,7 @@ int diff_foreach_via_iterator(
num_h = git_diff_patch_num_hunks(patch);
for (h = 0; h < num_h; h++) {
- git_diff_range *range;
+ const git_diff_range *range;
const char *hdr;
size_t hdr_len, l, num_l;
diff --git a/tests-clar/diff/diff_helpers.h b/tests-clar/diff/diff_helpers.h
index 79e1409..7984294 100644
--- a/tests-clar/diff/diff_helpers.h
+++ b/tests-clar/diff/diff_helpers.h
@@ -27,20 +27,20 @@ typedef struct {
extern int diff_file_fn(
void *cb_data,
- git_diff_delta *delta,
+ const git_diff_delta *delta,
float progress);
extern int diff_hunk_fn(
void *cb_data,
- git_diff_delta *delta,
- git_diff_range *range,
+ const git_diff_delta *delta,
+ const git_diff_range *range,
const char *header,
size_t header_len);
extern int diff_line_fn(
void *cb_data,
- git_diff_delta *delta,
- git_diff_range *range,
+ const git_diff_delta *delta,
+ const git_diff_range *range,
char line_origin,
const char *content,
size_t content_len);
diff --git a/tests-clar/diff/diffiter.c b/tests-clar/diff/diffiter.c
index 4273b16..78f97fc 100644
--- a/tests-clar/diff/diffiter.c
+++ b/tests-clar/diff/diffiter.c
@@ -20,7 +20,7 @@ void test_diff_diffiter__create(void)
num_d = git_diff_num_deltas(diff);
for (d = 0; d < num_d; ++d) {
- git_diff_delta *delta;
+ const git_diff_delta *delta;
cl_git_pass(git_diff_get_patch(NULL, &delta, diff, d));
}
@@ -40,7 +40,7 @@ void test_diff_diffiter__iterate_files(void)
cl_assert_equal_i(6, num_d);
for (d = 0; d < num_d; ++d) {
- git_diff_delta *delta;
+ const git_diff_delta *delta;
cl_git_pass(git_diff_get_patch(NULL, &delta, diff, d));
cl_assert(delta != NULL);
count++;
@@ -63,7 +63,7 @@ void test_diff_diffiter__iterate_files_2(void)
cl_assert_equal_i(8, num_d);
for (d = 0; d < num_d; ++d) {
- git_diff_delta *delta;
+ const git_diff_delta *delta;
cl_git_pass(git_diff_get_patch(NULL, &delta, diff, d));
cl_assert(delta != NULL);
count++;
@@ -91,7 +91,7 @@ void test_diff_diffiter__iterate_files_and_hunks(void)
for (d = 0; d < num_d; ++d) {
git_diff_patch *patch;
- git_diff_delta *delta;
+ const git_diff_delta *delta;
size_t h, num_h;
cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d));
@@ -104,7 +104,7 @@ void test_diff_diffiter__iterate_files_and_hunks(void)
num_h = git_diff_patch_num_hunks(patch);
for (h = 0; h < num_h; h++) {
- git_diff_range *range;
+ const git_diff_range *range;
const char *header;
size_t header_len, num_l;
@@ -143,7 +143,7 @@ void test_diff_diffiter__max_size_threshold(void)
for (d = 0; d < num_d; ++d) {
git_diff_patch *patch;
- git_diff_delta *delta;
+ const git_diff_delta *delta;
cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d));
cl_assert(delta);
@@ -178,7 +178,7 @@ void test_diff_diffiter__max_size_threshold(void)
for (d = 0; d < num_d; ++d) {
git_diff_patch *patch;
- git_diff_delta *delta;
+ const git_diff_delta *delta;
cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d));
@@ -221,7 +221,7 @@ void test_diff_diffiter__iterate_all(void)
num_d = git_diff_num_deltas(diff);
for (d = 0; d < num_d; ++d) {
git_diff_patch *patch;
- git_diff_delta *delta;
+ const git_diff_delta *delta;
size_t h, num_h;
cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d));
@@ -230,7 +230,7 @@ void test_diff_diffiter__iterate_all(void)
num_h = git_diff_patch_num_hunks(patch);
for (h = 0; h < num_h; h++) {
- git_diff_range *range;
+ const git_diff_range *range;
const char *header;
size_t header_len, l, num_l;
diff --git a/tests-clar/diff/index.c b/tests-clar/diff/index.c
index 2c6e89c..7c4bddb 100644
--- a/tests-clar/diff/index.c
+++ b/tests-clar/diff/index.c
@@ -93,7 +93,7 @@ void test_diff_index__0(void)
static int diff_stop_after_2_files(
void *cb_data,
- git_diff_delta *delta,
+ const git_diff_delta *delta,
float progress)
{
diff_expects *e = cb_data;
diff --git a/tests-clar/diff/patch.c b/tests-clar/diff/patch.c
index 05e7486..e846838 100644
--- a/tests-clar/diff/patch.c
+++ b/tests-clar/diff/patch.c
@@ -23,8 +23,8 @@ void test_diff_patch__cleanup(void)
static int check_removal_cb(
void *cb_data,
- git_diff_delta *delta,
- git_diff_range *range,
+ const git_diff_delta *delta,
+ const git_diff_range *range,
char line_origin,
const char *formatted_output,
size_t output_len)
diff --git a/tests-clar/diff/tree.c b/tests-clar/diff/tree.c
index 78ab093..e62fa26 100644
--- a/tests-clar/diff/tree.c
+++ b/tests-clar/diff/tree.c
@@ -265,9 +265,9 @@ void test_diff_tree__larger_hunks(void)
git_diff_options opts = {0};
git_diff_list *diff = NULL;
size_t d, num_d, h, num_h, l, num_l, header_len, line_len;
- git_diff_delta *delta;
+ const git_diff_delta *delta;
git_diff_patch *patch;
- git_diff_range *range;
+ const git_diff_range *range;
const char *header, *line;
char origin;
diff --git a/tests-clar/diff/workdir.c b/tests-clar/diff/workdir.c
index 612e443..9161131 100644
--- a/tests-clar/diff/workdir.c
+++ b/tests-clar/diff/workdir.c
@@ -691,7 +691,7 @@ void test_diff_workdir__larger_hunks(void)
for (i = 0; i <= 2; ++i) {
git_diff_list *diff = NULL;
git_diff_patch *patch;
- git_diff_range *range;
+ const git_diff_range *range;
const char *header, *line;
char origin;