#include "sigchain.h"
#include "transport-internal.h"
#include "protocol.h"
+#include "object-store.h"
+#include "color.h"
+
+static int transport_use_color = -1;
+static char transport_colors[][COLOR_MAXLEN] = {
+ GIT_COLOR_RESET,
+ GIT_COLOR_RED /* REJECTED */
+};
+
+enum color_transport {
+ TRANSPORT_COLOR_RESET = 0,
+ TRANSPORT_COLOR_REJECTED = 1
+};
+
+static int transport_color_config(void)
+{
+ const char *keys[] = {
+ "color.transport.reset",
+ "color.transport.rejected"
+ }, *key = "color.transport";
+ char *value;
+ int i;
+ static int initialized;
+
+ if (initialized)
+ return 0;
+ initialized = 1;
+
+ if (!git_config_get_string(key, &value))
+ transport_use_color = git_config_colorbool(key, value);
+
+ if (!want_color_stderr(transport_use_color))
+ return 0;
+
+ for (i = 0; i < ARRAY_SIZE(keys); i++)
+ if (!git_config_get_string(keys[i], &value)) {
+ if (!value)
+ return config_error_nonbool(keys[i]);
+ if (color_parse(value, transport_colors[i]) < 0)
+ return -1;
+ }
+
+ return 0;
+}
+
+static const char *transport_get_color(enum color_transport ix)
+{
+ if (want_color_stderr(transport_use_color))
+ return transport_colors[ix];
+ return "";
+}
static void set_upstreams(struct transport *transport, struct ref *refs,
int pretend)
} else if (!strcmp(name, TRANS_OPT_DEEPEN_RELATIVE)) {
opts->deepen_relative = !!value;
return 0;
+ } else if (!strcmp(name, TRANS_OPT_FROM_PROMISOR)) {
+ opts->from_promisor = !!value;
+ return 0;
+ } else if (!strcmp(name, TRANS_OPT_NO_DEPENDENTS)) {
+ opts->no_dependents = !!value;
+ return 0;
+ } else if (!strcmp(name, TRANS_OPT_LIST_OBJECTS_FILTER)) {
+ parse_list_objects_filter(&opts->filter_options, value);
+ return 0;
}
return 1;
}
data->options.check_self_contained_and_connected;
args.cloning = transport->cloning;
args.update_shallow = data->options.update_shallow;
+ args.from_promisor = data->options.from_promisor;
+ args.no_dependents = data->options.no_dependents;
+ args.filter_options = data->options.filter_options;
+ args.stateless_rpc = transport->stateless_rpc;
if (!data->got_remote_heads)
refs_tmp = get_refs_via_connect(transport, 0, NULL);
switch (data->version) {
case protocol_v2:
- die("support for protocol v2 not implemented yet");
+ refs = fetch_pack(&args, data->fd, data->conn,
+ refs_tmp ? refs_tmp : transport->remote_refs,
+ dest, to_fetch, nr_heads, &data->shallow,
+ &transport->pack_lockfile, data->version);
break;
case protocol_v1:
case protocol_v0:
refs = fetch_pack(&args, data->fd, data->conn,
refs_tmp ? refs_tmp : transport->remote_refs,
dest, to_fetch, nr_heads, &data->shallow,
- &transport->pack_lockfile);
+ &transport->pack_lockfile, data->version);
break;
case protocol_unknown_version:
BUG("unknown protocol version");
else
fprintf(stdout, "%s\n", summary);
} else {
- fprintf(stderr, " %c %-*s ", flag, summary_width, summary);
+ const char *red = "", *reset = "";
+ if (push_had_errors(to)) {
+ red = transport_get_color(TRANSPORT_COLOR_REJECTED);
+ reset = transport_get_color(TRANSPORT_COLOR_RESET);
+ }
+ fprintf(stderr, " %s%c %-*s%s ", red, flag, summary_width,
+ summary, reset);
if (from)
fprintf(stderr, "%s -> %s", prettify_refname(from->name), prettify_refname(to->name));
else
char type;
const char *msg;
- strbuf_add_unique_abbrev(&quickref, ref->old_oid.hash,
+ strbuf_add_unique_abbrev(&quickref, &ref->old_oid,
DEFAULT_ABBREV);
if (ref->forced_update) {
strbuf_addstr(&quickref, "...");
type = ' ';
msg = NULL;
}
- strbuf_add_unique_abbrev(&quickref, ref->new_oid.hash,
+ strbuf_add_unique_abbrev(&quickref, &ref->new_oid,
DEFAULT_ABBREV);
print_ref_status(type, quickref.buf, ref, ref->peer_ref, msg,
static int measure_abbrev(const struct object_id *oid, int sofar)
{
char hex[GIT_MAX_HEXSZ + 1];
- int w = find_unique_abbrev_r(hex, oid->hash, DEFAULT_ABBREV);
+ int w = find_unique_abbrev_r(hex, oid, DEFAULT_ABBREV);
return (w < sofar) ? sofar : w;
}
char *head;
int summary_width = transport_summary_width(refs);
+ if (transport_color_config() < 0)
+ warning(_("could not parse transport.color.* config"));
+
head = resolve_refdup("HEAD", RESOLVE_REF_READING, NULL, NULL);
if (verbose) {
struct send_pack_args args;
int ret = 0;
+ if (transport_color_config() < 0)
+ return -1;
+
if (!data->got_remote_heads)
get_refs_via_connect(transport, 1, NULL);
*reject_reasons = 0;
transport_verify_remote_names(refspec_nr, refspec);
+ if (transport_color_config() < 0)
+ return -1;
+
if (transport->vtable->push_refs) {
struct ref *remote_refs;
struct ref *local_refs = get_local_heads();
int porcelain = flags & TRANSPORT_PUSH_PORCELAIN;
int pretend = flags & TRANSPORT_PUSH_DRY_RUN;
int push_ret, ret, err;
+ struct refspec *tmp_rs;
+ struct argv_array ref_prefixes = ARGV_ARRAY_INIT;
+ int i;
if (check_push_refs(local_refs, refspec_nr, refspec) < 0)
return -1;
- remote_refs = transport->vtable->get_refs_list(transport, 1, NULL);
+ tmp_rs = parse_push_refspec(refspec_nr, refspec);
+ for (i = 0; i < refspec_nr; i++) {
+ const char *prefix = NULL;
+
+ if (tmp_rs[i].dst)
+ prefix = tmp_rs[i].dst;
+ else if (tmp_rs[i].src && !tmp_rs[i].exact_sha1)
+ prefix = tmp_rs[i].src;
+
+ if (prefix) {
+ const char *glob = strchr(prefix, '*');
+ if (glob)
+ argv_array_pushf(&ref_prefixes, "%.*s",
+ (int)(glob - prefix),
+ prefix);
+ else
+ expand_ref_prefix(&ref_prefixes, prefix);
+ }
+ }
+
+ remote_refs = transport->vtable->get_refs_list(transport, 1,
+ &ref_prefixes);
+
+ argv_array_clear(&ref_prefixes);
+ free_refspec(refspec_nr, tmp_rs);
if (flags & TRANSPORT_PUSH_ALL)
match_flags |= MATCH_REFS_ALL;
return 1;
}
-const struct ref *transport_get_remote_refs(struct transport *transport)
+const struct ref *transport_get_remote_refs(struct transport *transport,
+ const struct argv_array *ref_prefixes)
{
if (!transport->got_remote_refs) {
- transport->remote_refs = transport->vtable->get_refs_list(transport, 0, NULL);
+ transport->remote_refs =
+ transport->vtable->get_refs_list(transport, 0,
+ ref_prefixes);
transport->got_remote_refs = 1;
}