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 <barkalow@iabervon.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Daniel Barkalow
2007-10-29 21:05:40 -04:00
committed by Junio C Hamano
parent e3d6d56f1c
commit 4577370e9b
9 changed files with 57 additions and 33 deletions

View File

@ -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(target_host);
free(url);
if (free_path)
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 */
strbuf_release(&cmd);
free(url);
if (free_path)
free(path);
return conn;