Merge pull request #2244 from jacquesg/const-correctness Const correctness!
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
diff --git a/include/git2/blob.h b/include/git2/blob.h
index ac4d843..1b65833 100644
--- a/include/git2/blob.h
+++ b/include/git2/blob.h
@@ -216,7 +216,7 @@ GIT_EXTERN(int) git_blob_create_frombuffer(
* @return 1 if the content of the blob is detected
* as binary; 0 otherwise.
*/
-GIT_EXTERN(int) git_blob_is_binary(git_blob *blob);
+GIT_EXTERN(int) git_blob_is_binary(const git_blob *blob);
/** @} */
GIT_END_DECL
diff --git a/include/git2/branch.h b/include/git2/branch.h
index d276201..ad2a70b 100644
--- a/include/git2/branch.h
+++ b/include/git2/branch.h
@@ -179,8 +179,9 @@ GIT_EXTERN(int) git_branch_lookup(
* @return 0 on success; otherwise an error code (e.g., if the
* ref is no local or remote branch).
*/
-GIT_EXTERN(int) git_branch_name(const char **out,
- git_reference *ref);
+GIT_EXTERN(int) git_branch_name(
+ const char **out,
+ const git_reference *ref);
/**
* Return the reference supporting the remote tracking branch,
@@ -196,7 +197,7 @@ GIT_EXTERN(int) git_branch_name(const char **out,
*/
GIT_EXTERN(int) git_branch_upstream(
git_reference **out,
- git_reference *branch);
+ const git_reference *branch);
/**
* Set the upstream configuration for a given local branch
diff --git a/include/git2/index.h b/include/git2/index.h
index 9a7ad28..dd6a28e 100644
--- a/include/git2/index.h
+++ b/include/git2/index.h
@@ -255,7 +255,7 @@ GIT_EXTERN(int) git_index_write(git_index *index);
* @param index an existing index object
* @return path to index file or NULL for in-memory index
*/
-GIT_EXTERN(const char *) git_index_path(git_index *index);
+GIT_EXTERN(const char *) git_index_path(const git_index *index);
/**
* Read a tree into the index file with stats
diff --git a/include/git2/merge.h b/include/git2/merge.h
index 769df5a..6d97e81 100644
--- a/include/git2/merge.h
+++ b/include/git2/merge.h
@@ -341,7 +341,7 @@ GIT_EXTERN(int) git_merge_base_octopus(
GIT_EXTERN(int) git_merge_head_from_ref(
git_merge_head **out,
git_repository *repo,
- git_reference *ref);
+ const git_reference *ref);
/**
* Creates a `git_merge_head` from the given fetch head data. The resulting
diff --git a/include/git2/push.h b/include/git2/push.h
index 899d21e..7a8bec1 100644
--- a/include/git2/push.h
+++ b/include/git2/push.h
@@ -148,7 +148,7 @@ GIT_EXTERN(int) git_push_finish(git_push *push);
*
* @return true if remote side successfully unpacked, false otherwise
*/
-GIT_EXTERN(int) git_push_unpack_ok(git_push *push);
+GIT_EXTERN(int) git_push_unpack_ok(const git_push *push);
/**
* Invoke callback `cb' on each status entry
diff --git a/include/git2/refs.h b/include/git2/refs.h
index 1bbb4ca..6a1db65 100644
--- a/include/git2/refs.h
+++ b/include/git2/refs.h
@@ -487,7 +487,9 @@ GIT_EXTERN(void) git_reference_free(git_reference *ref);
* @param ref2 The second git_reference
* @return 0 if the same, else a stable but meaningless ordering.
*/
-GIT_EXTERN(int) git_reference_cmp(git_reference *ref1, git_reference *ref2);
+GIT_EXTERN(int) git_reference_cmp(
+ const git_reference *ref1,
+ const git_reference *ref2);
/**
* Create an iterator for the repo's references
@@ -596,7 +598,7 @@ GIT_EXTERN(int) git_reference_is_branch(const git_reference *ref);
* @return 1 when the reference lives in the refs/remotes
* namespace; 0 otherwise.
*/
-GIT_EXTERN(int) git_reference_is_remote(git_reference *ref);
+GIT_EXTERN(int) git_reference_is_remote(const git_reference *ref);
/**
* Check if a reference is a tag
@@ -606,7 +608,7 @@ GIT_EXTERN(int) git_reference_is_remote(git_reference *ref);
* @return 1 when the reference lives in the refs/tags
* namespace; 0 otherwise.
*/
-GIT_EXTERN(int) git_reference_is_tag(git_reference *ref);
+GIT_EXTERN(int) git_reference_is_tag(const git_reference *ref);
/**
* Check if a reference is a note
@@ -616,7 +618,7 @@ GIT_EXTERN(int) git_reference_is_tag(git_reference *ref);
* @return 1 when the reference lives in the refs/notes
* namespace; 0 otherwise.
*/
-GIT_EXTERN(int) git_reference_is_note(git_reference *ref);
+GIT_EXTERN(int) git_reference_is_note(const git_reference *ref);
typedef enum {
GIT_REF_FORMAT_NORMAL = 0u,
@@ -720,7 +722,7 @@ GIT_EXTERN(int) git_reference_is_valid_name(const char *refname);
* @param ref a reference
* @return the human-readable version of the name
*/
-GIT_EXTERN(const char *) git_reference_shorthand(git_reference *ref);
+GIT_EXTERN(const char *) git_reference_shorthand(const git_reference *ref);
/** @} */
diff --git a/src/blob.c b/src/blob.c
index faf8a4a..0aa2516 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -326,7 +326,7 @@ cleanup:
return error;
}
-int git_blob_is_binary(git_blob *blob)
+int git_blob_is_binary(const git_blob *blob)
{
git_buf content;
diff --git a/src/branch.c b/src/branch.c
index df665a4..63c6ec1 100644
--- a/src/branch.c
+++ b/src/branch.c
@@ -281,7 +281,9 @@ int git_branch_lookup(
return retrieve_branch_reference(ref_out, repo, branch_name, branch_type == GIT_BRANCH_REMOTE);
}
-int git_branch_name(const char **out, git_reference *ref)
+int git_branch_name(
+ const char **out,
+ const git_reference *ref)
{
const char *branch_name;
@@ -450,8 +452,8 @@ cleanup:
}
int git_branch_upstream(
- git_reference **tracking_out,
- git_reference *branch)
+ git_reference **tracking_out,
+ const git_reference *branch)
{
int error;
git_buf tracking_name = GIT_BUF_INIT;
diff --git a/src/index.c b/src/index.c
index ea0815e..3fcd211 100644
--- a/src/index.c
+++ b/src/index.c
@@ -553,7 +553,7 @@ int git_index_write(git_index *index)
return 0;
}
-const char * git_index_path(git_index *index)
+const char * git_index_path(const git_index *index)
{
assert(index);
return index->index_file_path;
diff --git a/src/merge.c b/src/merge.c
index f9ed7b0..dd6a39f 100644
--- a/src/merge.c
+++ b/src/merge.c
@@ -2695,7 +2695,7 @@ static int merge_head_init(
int git_merge_head_from_ref(
git_merge_head **out,
git_repository *repo,
- git_reference *ref)
+ const git_reference *ref)
{
git_reference *resolved;
int error = 0;
diff --git a/src/push.c b/src/push.c
index 5213556..5c8de33 100644
--- a/src/push.c
+++ b/src/push.c
@@ -651,7 +651,7 @@ int git_push_finish(git_push *push)
return 0;
}
-int git_push_unpack_ok(git_push *push)
+int git_push_unpack_ok(const git_push *push)
{
return push->unpack_ok;
}
diff --git a/src/refs.c b/src/refs.c
index 8b6e09a..9428f61 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -1031,7 +1031,9 @@ int git_reference__normalize_name_lax(
}
#define GIT_REF_TYPEMASK (GIT_REF_OID | GIT_REF_SYMBOLIC)
-int git_reference_cmp(git_reference *ref1, git_reference *ref2)
+int git_reference_cmp(
+ const git_reference *ref1,
+ const git_reference *ref2)
{
git_ref_t type1, type2;
assert(ref1 && ref2);
@@ -1148,7 +1150,7 @@ int git_reference__is_remote(const char *ref_name)
return git__prefixcmp(ref_name, GIT_REFS_REMOTES_DIR) == 0;
}
-int git_reference_is_remote(git_reference *ref)
+int git_reference_is_remote(const git_reference *ref)
{
assert(ref);
return git_reference__is_remote(ref->name);
@@ -1159,7 +1161,7 @@ int git_reference__is_tag(const char *ref_name)
return git__prefixcmp(ref_name, GIT_REFS_TAGS_DIR) == 0;
}
-int git_reference_is_tag(git_reference *ref)
+int git_reference_is_tag(const git_reference *ref)
{
assert(ref);
return git_reference__is_tag(ref->name);
@@ -1170,7 +1172,7 @@ int git_reference__is_note(const char *ref_name)
return git__prefixcmp(ref_name, GIT_REFS_NOTES_DIR) == 0;
}
-int git_reference_is_note(git_reference *ref)
+int git_reference_is_note(const git_reference *ref)
{
assert(ref);
return git_reference__is_note(ref->name);
@@ -1244,7 +1246,7 @@ int git_reference_is_valid_name(const char *refname)
return git_reference__is_valid_name(refname, GIT_REF_FORMAT_ALLOW_ONELEVEL);
}
-const char *git_reference_shorthand(git_reference *ref)
+const char *git_reference_shorthand(const git_reference *ref)
{
const char *name = ref->name;