Misc cleanups
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
diff --git a/src/attr.c b/src/attr.c
index ff4446e..15ed5c9 100644
--- a/src/attr.c
+++ b/src/attr.c
@@ -49,6 +49,8 @@ int git_attr_get(
git_attr_name attr;
git_attr_rule *rule;
+ assert(value && repo && name);
+
*value = NULL;
if (git_attr_path__init(&path, pathname, git_repository_workdir(repo)) < 0)
@@ -103,6 +105,11 @@ int git_attr_get_many(
attr_get_many_info *info = NULL;
size_t num_found = 0;
+ if (!num_attr)
+ return 0;
+
+ assert(values && repo && names);
+
if (git_attr_path__init(&path, pathname, git_repository_workdir(repo)) < 0)
return -1;
@@ -169,6 +176,8 @@ int git_attr_foreach(
git_attr_assignment *assign;
git_strmap *seen = NULL;
+ assert(repo && callback);
+
if (git_attr_path__init(&path, pathname, git_repository_workdir(repo)) < 0)
return -1;
diff --git a/src/branch.c b/src/branch.c
index a1a04b2..d0dc21b 100644
--- a/src/branch.c
+++ b/src/branch.c
@@ -21,27 +21,22 @@ static int retrieve_branch_reference(
const char *branch_name,
int is_remote)
{
- git_reference *branch;
- int error = -1;
+ git_reference *branch = NULL;
+ int error = 0;
char *prefix;
git_buf ref_name = GIT_BUF_INIT;
- *branch_reference_out = NULL;
-
prefix = is_remote ? GIT_REFS_REMOTES_DIR : GIT_REFS_HEADS_DIR;
- if (git_buf_joinpath(&ref_name, prefix, branch_name) < 0)
- goto cleanup;
+ if ((error = git_buf_joinpath(&ref_name, prefix, branch_name)) < 0)
+ /* OOM */;
+ else if ((error = git_reference_lookup(&branch, repo, ref_name.ptr)) < 0)
+ giterr_set(
+ GITERR_REFERENCE, "Cannot locate %s branch '%s'",
+ is_remote ? "remote-tracking" : "local", branch_name);
- if ((error = git_reference_lookup(&branch, repo, ref_name.ptr)) < 0) {
- giterr_set(GITERR_REFERENCE,
- "Cannot locate %s branch '%s'.", is_remote ? "remote-tracking" : "local", branch_name);
- goto cleanup;
- }
+ *branch_reference_out = branch; /* will be NULL on error */
- *branch_reference_out = branch;
-
-cleanup:
git_buf_free(&ref_name);
return error;
}
@@ -63,21 +58,19 @@ int git_branch_create(
{
git_reference *branch = NULL;
git_buf canonical_branch_name = GIT_BUF_INIT;
- int error = -1;
+ int error = 0;
assert(branch_name && commit && ref_out);
assert(git_object_owner((const git_object *)commit) == repository);
- if (git_buf_joinpath(&canonical_branch_name, GIT_REFS_HEADS_DIR, branch_name) < 0)
- goto cleanup;
-
- error = git_reference_create(&branch, repository,
- git_buf_cstr(&canonical_branch_name), git_commit_id(commit), force, NULL, NULL);
+ if (!(error = git_buf_joinpath(
+ &canonical_branch_name, GIT_REFS_HEADS_DIR, branch_name)))
+ error = git_reference_create(
+ &branch, repository, git_buf_cstr(&canonical_branch_name),
+ git_commit_id(commit), force, NULL, NULL);
- if (!error)
- *ref_out = branch;
+ *ref_out = branch;
-cleanup:
git_buf_free(&canonical_branch_name);
return error;
}
diff --git a/tests/status/renames.c b/tests/status/renames.c
index a81910e..df5e230 100644
--- a/tests/status/renames.c
+++ b/tests/status/renames.c
@@ -560,7 +560,6 @@ void test_status_renames__zero_byte_file_does_not_fail(void)
{
git_status_list *statuslist;
git_status_options opts = GIT_STATUS_OPTIONS_INIT;
- status_entry_counts counts = {0};
struct status_entry expected[] = {
{ GIT_STATUS_WT_DELETED, "ikeepsix.txt", "ikeepsix.txt" },