Commit 0573e78d by Carlos Martín Nieto Committed by Edward Thomson

refs: constify git_reference_peel

We have no need to take a non-const reference. This does involve some other work
to make sure we don't mix const and non-const variables, but by splitting what
we want each variable to do we can also simplify the logic for when we do want
to free a new reference we might have allocated.
parent 19cde48c
...@@ -710,7 +710,7 @@ GIT_EXTERN(int) git_reference_normalize_name( ...@@ -710,7 +710,7 @@ GIT_EXTERN(int) git_reference_normalize_name(
*/ */
GIT_EXTERN(int) git_reference_peel( GIT_EXTERN(int) git_reference_peel(
git_object **out, git_object **out,
git_reference *ref, const git_reference *ref,
git_otype type); git_otype type);
/** /**
......
...@@ -1339,7 +1339,7 @@ int git_reference_is_note(const git_reference *ref) ...@@ -1339,7 +1339,7 @@ int git_reference_is_note(const git_reference *ref)
return git_reference__is_note(ref->name); return git_reference__is_note(ref->name);
} }
static int peel_error(int error, git_reference *ref, const char* msg) static int peel_error(int error, const git_reference *ref, const char* msg)
{ {
giterr_set( giterr_set(
GITERR_INVALID, GITERR_INVALID,
...@@ -1349,10 +1349,11 @@ static int peel_error(int error, git_reference *ref, const char* msg) ...@@ -1349,10 +1349,11 @@ static int peel_error(int error, git_reference *ref, const char* msg)
int git_reference_peel( int git_reference_peel(
git_object **peeled, git_object **peeled,
git_reference *ref, const git_reference *ref,
git_otype target_type) git_otype target_type)
{ {
git_reference *resolved = NULL; const git_reference *resolved = NULL;
git_reference *allocated = NULL;
git_object *target = NULL; git_object *target = NULL;
int error; int error;
...@@ -1361,8 +1362,10 @@ int git_reference_peel( ...@@ -1361,8 +1362,10 @@ int git_reference_peel(
if (ref->type == GIT_REF_OID) { if (ref->type == GIT_REF_OID) {
resolved = ref; resolved = ref;
} else { } else {
if ((error = git_reference_resolve(&resolved, ref)) < 0) if ((error = git_reference_resolve(&allocated, ref)) < 0)
return peel_error(error, ref, "Cannot resolve reference"); return peel_error(error, ref, "Cannot resolve reference");
resolved = allocated;
} }
/* /*
...@@ -1391,9 +1394,7 @@ int git_reference_peel( ...@@ -1391,9 +1394,7 @@ int git_reference_peel(
cleanup: cleanup:
git_object_free(target); git_object_free(target);
git_reference_free(allocated);
if (resolved != ref)
git_reference_free(resolved);
return error; return error;
} }
......
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