path: root/connect.c
diff options
authorDaniel Barkalow <>2007-10-30 01:05:40 (GMT)
committerJunio C Hamano <>2007-11-03 05:40:43 (GMT)
commit4577370e9bfeca8652880b99b8499f76d18865ba (patch)
tree3df529fad99232d7f82f0389d0d8f5dc571319c8 /connect.c
parente3d6d56f1c2097f13a427e158638e5e0918e5705 (diff)
Miscellaneous const changes and utilities
The list of remote refs in struct transport should be const, because builtin-fetch will get confused if it changes. The url in git_connect should be const (and work on a copy) instead of requiring the caller to copy it. match_refs doesn't modify the refspecs it gets. get_fetch_map and get_remote_ref don't change the list they get. Allow transport get_refs_list methods to modify the struct transport. Add a function to copy a list of refs, when a function needs a mutable copy of a const list. Add a function to check the type of a ref, as per the code in connect.c Signed-off-by: Daniel Barkalow <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'connect.c')
1 files changed, 9 insertions, 1 deletions
diff --git a/connect.c b/connect.c
index 44e423d..3aefd4a 100644
--- a/connect.c
+++ b/connect.c
@@ -36,6 +36,11 @@ static int check_ref(const char *name, int len, unsigned int flags)
return !(flags & ~REF_NORMAL);
+int check_ref_type(const struct ref *ref, int flags)
+ return check_ref(ref->name, strlen(ref->name), flags);
* Read all the refs from the other end
@@ -476,9 +481,10 @@ char *get_port(char *host)
* If it returns, the connect is successful; it just dies on errors.
-struct child_process *git_connect(int fd[2], char *url,
+struct child_process *git_connect(int fd[2], const char *url_orig,
const char *prog, int flags)
+ char *url = xstrdup(url_orig);
char *host, *path = url;
char *end;
int c;
@@ -568,6 +574,7 @@ struct child_process *git_connect(int fd[2], char *url,
prog, path, 0,
target_host, 0);
+ free(url);
if (free_path)
return NULL;
@@ -619,6 +626,7 @@ struct child_process *git_connect(int fd[2], char *url,
fd[0] = conn->out; /* read from child's stdout */
fd[1] = conn->in; /* write to child's stdin */
+ free(url);
if (free_path)
return conn;