Add git_remote_disconnect It can be useful to separate disconnecting from actually destroying the object. Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
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
diff --git a/include/git2/remote.h b/include/git2/remote.h
index 15d0aa3..94453db 100644
--- a/include/git2/remote.h
+++ b/include/git2/remote.h
@@ -124,6 +124,16 @@ GIT_EXTERN(int) git_remote_ls(git_remote *remote, git_headarray *refs);
GIT_EXTERN(int) git_remote_download(char **filename, git_remote *remote);
/**
+ * Disconnect from the remote
+ *
+ * Close the connection to the remote and free the underlying
+ * transport.
+ *
+ * @param remote the remote to disconnect from
+ */
+GIT_EXTERN(void) git_remote_disconnect(git_remote *remote);
+
+/**
* Free the memory associated with a remote
*
* @param remote the remote to free
diff --git a/src/remote.c b/src/remote.c
index d541cd0..c599910 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -267,6 +267,16 @@ int git_remote_update_tips(struct git_remote *remote)
return GIT_SUCCESS;
}
+void git_remote_disconnect(git_remote *remote)
+{
+ if (remote->transport != NULL) {
+ if (remote->transport->connected)
+ remote->transport->close(remote->transport);
+
+ remote->transport->free(remote->transport);
+ }
+}
+
void git_remote_free(git_remote *remote)
{
if (remote == NULL)
@@ -278,11 +288,6 @@ void git_remote_free(git_remote *remote)
git__free(remote->push.dst);
git__free(remote->url);
git__free(remote->name);
- if (remote->transport != NULL) {
- if (remote->transport->connected)
- remote->transport->close(remote->transport);
-
- remote->transport->free(remote->transport);
- }
+ git_remote_disconnect(remote);
git__free(remote);
}