Commit bae957b9 by Russell Belfer

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!
parent 64286308
......@@ -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,
......
......@@ -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;
......
......@@ -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;
......
......@@ -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
......@@ -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,
......
......@@ -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;
......
......@@ -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;
......
......@@ -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);
......
......@@ -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;
......
......@@ -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;
......
......@@ -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)
......
......@@ -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;
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment