Enforce coding conventions in refs.c Internal methods are static and without the git prefix. 'Force' methods have a `_f` prefix to match the other 'force' methods.
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
diff --git a/include/git2/refs.h b/include/git2/refs.h
index 328a9f1..298c66d 100644
--- a/include/git2/refs.h
+++ b/include/git2/refs.h
@@ -87,7 +87,7 @@ GIT_EXTERN(int) git_reference_create_symbolic(git_reference **ref_out, git_repos
* @param target The target of the reference
* @return 0 on success; error code otherwise
*/
-GIT_EXTERN(int) git_reference_create_symbolic_force(git_reference **ref_out, git_repository *repo, const char *name, const char *target);
+GIT_EXTERN(int) git_reference_create_symbolic_f(git_reference **ref_out, git_repository *repo, const char *name, const char *target);
/**
* Create a new object id reference.
@@ -125,7 +125,7 @@ GIT_EXTERN(int) git_reference_create_oid(git_reference **ref_out, git_repository
* @param id The object id pointed to by the reference.
* @return 0 on success; error code otherwise
*/
-GIT_EXTERN(int) git_reference_create_oid_force(git_reference **ref_out, git_repository *repo, const char *name, const git_oid *id);
+GIT_EXTERN(int) git_reference_create_oid_f(git_reference **ref_out, git_repository *repo, const char *name, const git_oid *id);
/**
* Get the OID pointed to by a reference.
@@ -243,7 +243,7 @@ GIT_EXTERN(int) git_reference_rename(git_reference *ref, const char *new_name);
* and on disk.
*
*/
-GIT_EXTERN(int) git_reference_rename_force(git_reference *ref, const char *new_name);
+GIT_EXTERN(int) git_reference_rename_f(git_reference *ref, const char *new_name);
/**
* Delete an existing reference
diff --git a/src/refs.c b/src/refs.c
index ae745e5..c6508ca 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -79,6 +79,11 @@ static int packed_remove_loose(git_repository *repo, git_vector *packing_list);
static int packed_sort(const void *a, const void *b);
static int packed_write(git_repository *repo);
+/* internal helpers */
+static int reference_create_symbolic(git_reference **ref_out, git_repository *repo, const char *name, const char *target, int force);
+static int reference_create_oid(git_reference **ref_out, git_repository *repo, const char *name, const git_oid *id, int force);
+static int reference_rename(git_reference *ref, const char *new_name, int force);
+
/* name normalization */
static int check_valid_ref_char(char ch);
static int normalize_name(char *buffer_out, const char *name, int is_oid_ref);
@@ -919,7 +924,7 @@ cleanup:
* Internal methods - reference creation
*****************************************/
-int git_reference_create_symbolic_internal(git_reference **ref_out, git_repository *repo, const char *name, const char *target, int force)
+static int reference_create_symbolic(git_reference **ref_out, git_repository *repo, const char *name, const char *target, int force)
{
char normalized[MAX_GITDIR_TREE_STRUCTURE_PATH_LENGTH];
int error = GIT_SUCCESS, updated = 0;
@@ -976,7 +981,7 @@ cleanup:
return error;
}
-int git_reference_create_oid_internal(git_reference **ref_out, git_repository *repo, const char *name, const git_oid *id, int force)
+static int reference_create_oid(git_reference **ref_out, git_repository *repo, const char *name, const git_oid *id, int force)
{
int error = GIT_SUCCESS, updated = 0;
git_reference *ref = NULL, *old_ref = NULL;
@@ -1036,7 +1041,7 @@ cleanup:
* We also need to re-insert the reference on its corresponding
* in-memory cache, since the caches are indexed by refname.
*/
-int git_reference_rename_internal(git_reference *ref, const char *new_name, int force)
+static int reference_rename(git_reference *ref, const char *new_name, int force)
{
int error;
char *old_name;
@@ -1207,22 +1212,22 @@ int git_reference_lookup(git_reference **ref_out, git_repository *repo, const ch
int git_reference_create_symbolic(git_reference **ref_out, git_repository *repo, const char *name, const char *target)
{
- return git_reference_create_symbolic_internal(ref_out, repo, name, target, 0);
+ return reference_create_symbolic(ref_out, repo, name, target, 0);
}
-int git_reference_create_symbolic_force(git_reference **ref_out, git_repository *repo, const char *name, const char *target)
+int git_reference_create_symbolic_f(git_reference **ref_out, git_repository *repo, const char *name, const char *target)
{
- return git_reference_create_symbolic_internal(ref_out, repo, name, target, 1);
+ return reference_create_symbolic(ref_out, repo, name, target, 1);
}
int git_reference_create_oid(git_reference **ref_out, git_repository *repo, const char *name, const git_oid *id)
{
- return git_reference_create_oid_internal(ref_out, repo, name, id, 0);
+ return reference_create_oid(ref_out, repo, name, id, 0);
}
-int git_reference_create_oid_force(git_reference **ref_out, git_repository *repo, const char *name, const git_oid *id)
+int git_reference_create_oid_f(git_reference **ref_out, git_repository *repo, const char *name, const git_oid *id)
{
- return git_reference_create_oid_internal(ref_out, repo, name, id, 1);
+ return reference_create_oid(ref_out, repo, name, id, 1);
}
/**
@@ -1433,12 +1438,12 @@ cleanup:
int git_reference_rename(git_reference *ref, const char *new_name)
{
- return git_reference_rename_internal(ref, new_name, 0);
+ return reference_rename(ref, new_name, 0);
}
-int git_reference_rename_force(git_reference *ref, const char *new_name)
+int git_reference_rename_f(git_reference *ref, const char *new_name)
{
- return git_reference_rename_internal(ref, new_name, 1);
+ return reference_rename(ref, new_name, 1);
}
int git_reference_resolve(git_reference **resolved_ref, git_reference *ref)
diff --git a/tests/t10-refs.c b/tests/t10-refs.c
index 528c29a..995865d 100644
--- a/tests/t10-refs.c
+++ b/tests/t10-refs.c
@@ -315,7 +315,7 @@ BEGIN_TEST(overwrite0, "Overwrite an existing symbolic reference")
/* Ensure we can't create it unless we force it to */
must_fail(git_reference_create_symbolic(&ref, repo, ref_name, ref_master_name));
- must_pass(git_reference_create_symbolic_force(&ref, repo, ref_name, ref_master_name));
+ must_pass(git_reference_create_symbolic_f(&ref, repo, ref_name, ref_master_name));
/* Ensure it points to the right place */
must_pass(git_reference_lookup(&ref, repo, ref_name));
@@ -347,7 +347,7 @@ BEGIN_TEST(overwrite1, "Overwrite an existing object id reference")
/* Ensure we can't overwrite unless we force it */
must_fail(git_reference_create_oid(&ref, repo, ref_name, &id));
- must_pass(git_reference_create_oid_force(&ref, repo, ref_name, &id));
+ must_pass(git_reference_create_oid_f(&ref, repo, ref_name, &id));
/* Ensure it has been overwritten */
must_pass(git_reference_lookup(&ref, repo, ref_name));
@@ -370,7 +370,7 @@ BEGIN_TEST(overwrite2, "Overwrite an existing object id reference with a symboli
must_pass(git_reference_create_oid(&ref, repo, ref_name, &id));
must_fail(git_reference_create_symbolic(&ref, repo, ref_name, ref_master_name));
- must_pass(git_reference_create_symbolic_force(&ref, repo, ref_name, ref_master_name));
+ must_pass(git_reference_create_symbolic_f(&ref, repo, ref_name, ref_master_name));
/* Ensure it points to the right place */
must_pass(git_reference_lookup(&ref, repo, ref_name));
@@ -396,7 +396,7 @@ BEGIN_TEST(overwrite3, "Overwrite an existing symbolic reference with an object
must_pass(git_reference_create_symbolic(&ref, repo, ref_name, ref_master_name));
/* It shouldn't overwrite unless we tell it to */
must_fail(git_reference_create_oid(&ref, repo, ref_name, &id));
- must_pass(git_reference_create_oid_force(&ref, repo, ref_name, &id));
+ must_pass(git_reference_create_oid_f(&ref, repo, ref_name, &id));
/* Ensure it points to the right place */
must_pass(git_reference_lookup(&ref, repo, ref_name));
@@ -622,7 +622,7 @@ BEGIN_TEST(rename5, "can force-rename a reference with the name of an existing r
must_pass(git_reference_lookup(&looked_up_ref, repo, packed_head_name));
/* Can not be renamed to the name of another existing reference. */
- must_pass(git_reference_rename_force(looked_up_ref, packed_test_head_name));
+ must_pass(git_reference_rename_f(looked_up_ref, packed_test_head_name));
/* Check we actually renamed it */
must_pass(git_reference_lookup(&looked_up_ref, repo, packed_test_head_name));