From: Daniel Barkalow Date: Sat, 28 Apr 2007 17:05:14 GMT Subject: [PATCH 3/5] Use remote functions in git-push Message-ID: Replace the local parsing implementation with the library implementation. Note that this incidentally makes the config file override remotes files. Signed-off-by: Daniel Barkalow --- builtin-push.c | 188 ++++++-------------------------------------------------- 1 files changed, 20 insertions(+), 168 deletions(-) diff --git a/builtin-push.c b/builtin-push.c index cb78401..2e944cd 100644 --- a/builtin-push.c +++ b/builtin-push.c @@ -5,6 +5,7 @@ #include "refs.h" #include "run-command.h" #include "builtin.h" +#include "remote.h" #define MAX_URI (16) @@ -13,9 +14,6 @@ static const char push_usage[] = "git-push [--all] [--tags] [--receive-pack= 0) - return n; - - n = get_config_remotes_uri(repo, uri); - if (n > 0) - return n; - - n = get_branches_uri(repo, uri); - if (n > 0) - return n; - } - - uri[0] = repo; - return 1; -} - static int do_push(const char *repo) { - const char *uri[MAX_URI]; - int i, n, errs; + int i, errs; int common_argc; const char **argv; int argc; + struct remote *remote; + + remote = remote_get(repo); - n = read_config(repo, uri); - if (n <= 0) + if (!remote) die("bad repository '%s'", repo); + if (remote->receivepack) { + char *rp = xmalloc(strlen(remote->receivepack) + 16); + sprintf(rp, "--receive-pack=%s", remote->receivepack); + receivepack = rp; + } + if (!refspec && !all && !tags && remote->push_refspec_nr) { + refspec_nr = remote->push_refspec_nr; + refspec = remote->push_refspec; + } + argv = xmalloc((refspec_nr + 10) * sizeof(char *)); argv[0] = "dummy-send-pack"; argc = 1; @@ -318,12 +170,12 @@ static int do_push(const char *repo) common_argc = argc; errs = 0; - for (i = 0; i < n; i++) { + for (i = 0; remote->uri[i]; i++) { int err; int dest_argc = common_argc; int dest_refspec_nr = refspec_nr; const char **dest_refspec = refspec; - const char *dest = uri[i]; + const char *dest = remote->uri[i]; const char *sender = "send-pack"; if (!prefixcmp(dest, "http://") || !prefixcmp(dest, "https://")) @@ -341,7 +193,7 @@ static int do_push(const char *repo) if (!err) continue; - error("failed to push to '%s'", uri[i]); + error("failed to push to '%s'", remote->uri[i]); switch (err) { case -ERR_RUN_COMMAND_FORK: error("unable to fork for %s", sender); @@ -362,7 +214,7 @@ static int do_push(const char *repo) int cmd_push(int argc, const char **argv, const char *prefix) { int i; - const char *repo = "origin"; /* default repository */ + const char *repo = NULL; /* default repository */ for (i = 1; i < argc; i++) { const char *arg = argv[i]; -- 1.5.1.2.255.g6ead4-dirty