remote: Assert things that should be asserted
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
diff --git a/src/remote.c b/src/remote.c
index e0c127b..12af545 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -60,8 +60,8 @@ int git_remote_new(git_remote **out, git_repository *repo, const char *url, cons
{
git_remote *remote;
- if (url == NULL)
- return git__throw(GIT_EINVALIDARGS, "No URL was given");
+ /* name is optional */
+ assert(out && repo && url);
remote = git__malloc(sizeof(git_remote));
if (remote == NULL)
@@ -95,6 +95,8 @@ int git_remote_get(git_remote **out, git_config *cfg, const char *name)
const char *val;
int ret, error, buf_len;
+ assert(out && cfg && name);
+
remote = git__malloc(sizeof(git_remote));
if (remote == NULL)
return GIT_ENOMEM;
@@ -169,23 +171,27 @@ cleanup:
return error;
}
-const char *git_remote_name(struct git_remote *remote)
+const char *git_remote_name(git_remote *remote)
{
+ assert(remote);
return remote->name;
}
-const char *git_remote_url(struct git_remote *remote)
+const char *git_remote_url(git_remote *remote)
{
+ assert(remote);
return remote->url;
}
-const git_refspec *git_remote_fetchspec(struct git_remote *remote)
+const git_refspec *git_remote_fetchspec(git_remote *remote)
{
+ assert(remote);
return &remote->fetch;
}
-const git_refspec *git_remote_pushspec(struct git_remote *remote)
+const git_refspec *git_remote_pushspec(git_remote *remote)
{
+ assert(remote);
return &remote->push;
}
@@ -194,6 +200,8 @@ int git_remote_connect(git_remote *remote, int direction)
int error;
git_transport *t;
+ assert(remote);
+
error = git_transport_new(&t, remote->url);
if (error < GIT_SUCCESS)
return git__rethrow(error, "Failed to create transport");
@@ -215,6 +223,7 @@ cleanup:
int git_remote_ls(git_remote *remote, git_headarray *refs)
{
+ assert(remote && refs);
return remote->transport->ls(remote->transport, refs);
}
@@ -222,13 +231,15 @@ int git_remote_download(char **filename, git_remote *remote)
{
int error;
+ assert(filename && remote);
+
if ((error = git_fetch_negotiate(remote)) < 0)
return git__rethrow(error, "Error negotiating");
return git_fetch_download_pack(filename, remote);
}
-int git_remote_update_tips(struct git_remote *remote)
+int git_remote_update_tips(git_remote *remote)
{
int error = GIT_SUCCESS;
unsigned int i = 0;
@@ -238,6 +249,8 @@ int git_remote_update_tips(struct git_remote *remote)
git_reference *ref;
struct git_refspec *spec = &remote->fetch;
+ assert(remote);
+
memset(refname, 0x0, sizeof(refname));
if (refs->len == 0)
@@ -269,11 +282,14 @@ int git_remote_update_tips(struct git_remote *remote)
int git_remote_connected(git_remote *remote)
{
+ assert(remote);
return remote->transport == NULL ? 0 : remote->transport->connected;
}
void git_remote_disconnect(git_remote *remote)
{
+ assert(remote);
+
if (remote->transport != NULL) {
if (remote->transport->connected)
remote->transport->close(remote->transport);