Fix builtin-push to honor Push: lines in remotes file.
[jc: originally from Johannes Schindelin, but reworked to lift a hard limit of Push: lines] Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
@ -68,14 +68,11 @@ static void set_refspecs(const char **refs, int nr)
|
|||||||
expand_refspecs();
|
expand_refspecs();
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MAX_REFSPECS 10
|
|
||||||
static int current_refspec = 0;
|
|
||||||
static char *refspecs_[MAX_REFSPECS];
|
|
||||||
|
|
||||||
static int get_remotes_uri(const char *repo, const char *uri[MAX_URI])
|
static int get_remotes_uri(const char *repo, const char *uri[MAX_URI])
|
||||||
{
|
{
|
||||||
int n = 0;
|
int n = 0;
|
||||||
FILE *f = fopen(git_path("remotes/%s", repo), "r");
|
FILE *f = fopen(git_path("remotes/%s", repo), "r");
|
||||||
|
int has_explicit_refspec = refspec_nr;
|
||||||
|
|
||||||
if (!f)
|
if (!f)
|
||||||
return -1;
|
return -1;
|
||||||
@ -103,10 +100,14 @@ static int get_remotes_uri(const char *repo, const char *uri[MAX_URI])
|
|||||||
while (isspace(p[-1]))
|
while (isspace(p[-1]))
|
||||||
*--p = 0;
|
*--p = 0;
|
||||||
|
|
||||||
if (!is_refspec && n < MAX_URI)
|
if (!is_refspec) {
|
||||||
uri[n++] = strdup(s);
|
if (n < MAX_URI)
|
||||||
else if (is_refspec && current_refspec < MAX_REFSPECS)
|
uri[n++] = strdup(s);
|
||||||
refspecs_[current_refspec++] = strdup(s);
|
else
|
||||||
|
error("more than %d URL's specified, ignoreing the rest", MAX_URI);
|
||||||
|
}
|
||||||
|
else if (is_refspec && !has_explicit_refspec)
|
||||||
|
add_refspec(strdup(s));
|
||||||
}
|
}
|
||||||
fclose(f);
|
fclose(f);
|
||||||
if (!n)
|
if (!n)
|
||||||
@ -146,13 +147,17 @@ static int get_branches_uri(const char *repo, const char *uri[MAX_URI])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_uri(const char *repo, const char *uri[MAX_URI])
|
/*
|
||||||
|
* Read remotes and branches file, fill the push target URI
|
||||||
|
* list. If there is no command line refspecs, read Push: lines
|
||||||
|
* to set up the *refspec list as well.
|
||||||
|
* return the number of push target URIs
|
||||||
|
*/
|
||||||
|
static int read_config(const char *repo, const char *uri[MAX_URI])
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
if (*repo != '/') {
|
if (*repo != '/') {
|
||||||
current_refspec = 0;
|
|
||||||
|
|
||||||
n = get_remotes_uri(repo, uri);
|
n = get_remotes_uri(repo, uri);
|
||||||
if (n > 0)
|
if (n > 0)
|
||||||
return n;
|
return n;
|
||||||
@ -169,18 +174,15 @@ static int get_uri(const char *repo, const char *uri[MAX_URI])
|
|||||||
static int do_push(const char *repo)
|
static int do_push(const char *repo)
|
||||||
{
|
{
|
||||||
const char *uri[MAX_URI];
|
const char *uri[MAX_URI];
|
||||||
int i, n = get_uri(repo, uri);
|
int i, n;
|
||||||
int remote;
|
int remote;
|
||||||
const char **argv;
|
const char **argv;
|
||||||
int argc;
|
int argc;
|
||||||
|
|
||||||
n = get_uri(repo, uri);
|
n = read_config(repo, uri);
|
||||||
if (n <= 0)
|
if (n <= 0)
|
||||||
die("bad repository '%s'", repo);
|
die("bad repository '%s'", repo);
|
||||||
|
|
||||||
if (refspec_nr == 0)
|
|
||||||
set_refspecs((const char**)refspecs_, current_refspec);
|
|
||||||
|
|
||||||
argv = xmalloc((refspec_nr + 10) * sizeof(char *));
|
argv = xmalloc((refspec_nr + 10) * sizeof(char *));
|
||||||
argv[0] = "dummy-send-pack";
|
argv[0] = "dummy-send-pack";
|
||||||
argc = 1;
|
argc = 1;
|
||||||
|
Reference in New Issue
Block a user