Commit 4cf01e9a1a3b81d1c8bc77fcdf7e0c20792175a7

Carlos Martín Nieto 2011-11-21T20:44:03

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>

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);
 }