#include "dir.h"
#include "refs.h"
#include "branch.h"
+#include "url.h"
/* rsync support */
args.include_tag = data->options.followtags;
args.verbose = (transport->verbose > 0);
args.quiet = (transport->verbose < 0);
- args.no_progress = args.quiet || (!transport->progress && !isatty(2));
+ args.no_progress = !transport->progress;
args.depth = data->options.depth;
for (i = 0; i < nr_heads; i++)
static int print_one_push_status(struct ref *ref, const char *dest, int count, int porcelain)
{
if (!count)
- fprintf(stderr, "To %s\n", dest);
+ fprintf(porcelain ? stdout : stderr, "To %s\n", dest);
switch(ref->status) {
case REF_STATUS_NONE:
args.send_mirror = !!(flags & TRANSPORT_PUSH_MIRROR);
args.force_update = !!(flags & TRANSPORT_PUSH_FORCE);
args.use_thin_pack = data->options.thin;
- args.verbose = !!(flags & TRANSPORT_PUSH_VERBOSE);
- args.quiet = !!(flags & TRANSPORT_PUSH_QUIET);
+ args.verbose = (transport->verbose > 0);
+ args.quiet = (transport->verbose < 0);
args.dry_run = !!(flags & TRANSPORT_PUSH_DRY_RUN);
+ args.porcelain = !!(flags & TRANSPORT_PUSH_PORCELAIN);
ret = send_pack(&args, data->fd, data->conn, remote_refs,
&data->extra_have);
return S_ISREG(buf.st_mode);
}
-static int isurlschemechar(int first_flag, int ch)
-{
- /*
- * The set of valid URL schemes, as per STD66 (RFC3986) is
- * '[A-Za-z][A-Za-z0-9+.-]*'. But use sightly looser check
- * of '[A-Za-z0-9][A-Za-z0-9+.-]*' because earlier version
- * of check used '[A-Za-z0-9]+' so not to break any remote
- * helpers.
- */
- int alphanumeric, special;
- alphanumeric = ch > 0 && isalnum(ch);
- special = ch == '+' || ch == '-' || ch == '.';
- return alphanumeric || (!first_flag && special);
-}
-
-static int is_url(const char *url)
-{
- const char *url2, *first_slash;
-
- if (!url)
- return 0;
- url2 = url;
- first_slash = strchr(url, '/');
-
- /* Input with no slash at all or slash first can't be URL. */
- if (!first_slash || first_slash == url)
- return 0;
- /* Character before must be : and next must be /. */
- if (first_slash[-1] != ':' || first_slash[1] != '/')
- return 0;
- /* There must be something before the :// */
- if (first_slash == url + 1)
- return 0;
- /*
- * Check all characters up to first slash - 1. Only alphanum
- * is allowed.
- */
- url2 = url;
- while (url2 < first_slash - 1) {
- if (!isurlschemechar(url2 == url, (unsigned char)*url2))
- return 0;
- url2++;
- }
-
- /* Valid enough. */
- return 1;
-}
-
static int external_specification_len(const char *url)
{
return strchr(url, ':') - url;
const char *helper;
struct transport *ret = xcalloc(1, sizeof(*ret));
+ ret->progress = isatty(2);
+
if (!remote)
die("No remote provided to transport_get()");
if (url) {
const char *p = url;
- while (isurlschemechar(p == url, *p))
+ while (is_urlschemechar(p == url, *p))
p++;
if (!prefixcmp(p, "::"))
helper = xstrndup(url, p - url);
return 1;
}
+void transport_set_verbosity(struct transport *transport, int verbosity,
+ int force_progress)
+{
+ if (verbosity >= 2)
+ transport->verbose = verbosity <= 3 ? verbosity : 3;
+ if (verbosity < 0)
+ transport->verbose = -1;
+
+ /**
+ * Rules used to determine whether to report progress (processing aborts
+ * when a rule is satisfied):
+ *
+ * 1. Report progress, if force_progress is 1 (ie. --progress).
+ * 2. Don't report progress, if verbosity < 0 (ie. -q/--quiet ).
+ * 3. Report progress if isatty(2) is 1.
+ **/
+ transport->progress = force_progress || (verbosity >= 0 && isatty(2));
+}
+
int transport_push(struct transport *transport,
int refspec_nr, const char **refspec, int flags,
int *nonfastforward)
transport->get_refs_list(transport, 1);
struct ref *local_refs = get_local_heads();
int match_flags = MATCH_REFS_NONE;
- int verbose = flags & TRANSPORT_PUSH_VERBOSE;
- int quiet = flags & TRANSPORT_PUSH_QUIET;
+ int verbose = (transport->verbose > 0);
+ int quiet = (transport->verbose < 0);
int porcelain = flags & TRANSPORT_PUSH_PORCELAIN;
int pretend = flags & TRANSPORT_PUSH_DRY_RUN;
- int ret, err;
+ int push_ret, ret, err;
if (flags & TRANSPORT_PUSH_ALL)
match_flags |= MATCH_REFS_ALL;
flags & TRANSPORT_PUSH_MIRROR,
flags & TRANSPORT_PUSH_FORCE);
- ret = transport->push_refs(transport, remote_refs, flags);
+ push_ret = transport->push_refs(transport, remote_refs, flags);
err = push_had_errors(remote_refs);
-
- ret |= err;
+ ret = push_ret | err;
if (!quiet || err)
transport_print_push_status(transport->url, remote_refs,
transport_update_tracking_ref(transport->remote, ref, verbose);
}
- if (!quiet && !ret && !transport_refs_pushed(remote_refs))
+ if (porcelain && !push_ret)
+ puts("Done");
+ else if (!quiet && !ret && !transport_refs_pushed(remote_refs))
fprintf(stderr, "Everything up-to-date\n");
+
return ret;
}
return 1;