summaryrefslogtreecommitdiff
path: root/transport.c
diff options
context:
space:
mode:
Diffstat (limited to 'transport.c')
-rw-r--r--transport.c175
1 files changed, 105 insertions, 70 deletions
diff --git a/transport.c b/transport.c
index 342db49..1c76d64 100644
--- a/transport.c
+++ b/transport.c
@@ -11,6 +11,7 @@
#include "bundle.h"
#include "dir.h"
#include "refs.h"
+#include "refspec.h"
#include "branch.h"
#include "url.h"
#include "submodule.h"
@@ -19,6 +20,57 @@
#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)
@@ -87,7 +139,7 @@ static struct ref *get_refs_from_bundle(struct transport *transport,
close(data->fd);
data->fd = read_bundle_header(transport->url, &data->header);
if (data->fd < 0)
- die ("Could not read bundle '%s'.", transport->url);
+ die(_("could not read bundle '%s'"), transport->url);
for (i = 0; i < data->header.references.nr; i++) {
struct ref_list_entry *e = data->header.references.list + i;
struct ref *ref = alloc_ref(e->name);
@@ -165,6 +217,15 @@ static int set_git_option(struct git_transport_options *opts,
} 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;
}
@@ -208,7 +269,7 @@ static struct ref *get_refs_via_connect(struct transport *transport, int for_pus
switch (data->version) {
case protocol_v2:
get_remote_refs(data->fd[1], &reader, &refs, for_push,
- ref_prefixes);
+ ref_prefixes, transport->server_options);
break;
case protocol_v1:
case protocol_v0:
@@ -252,7 +313,12 @@ static int fetch_refs_via_pack(struct transport *transport,
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;
+ args.server_options = transport->server_options;
+ args.negotiation_tips = data->options.negotiation_tips;
if (!data->got_remote_heads)
refs_tmp = get_refs_via_connect(transport, 0, NULL);
@@ -283,6 +349,7 @@ static int fetch_refs_via_pack(struct transport *transport,
data->got_remote_heads = 0;
data->options.self_contained_and_connected =
args.self_contained_and_connected;
+ data->options.connectivity_checked = args.connectivity_checked;
if (refs == NULL)
ret = -1;
@@ -326,7 +393,7 @@ int transport_refs_pushed(struct ref *ref)
void transport_update_tracking_ref(struct remote *remote, struct ref *ref, int verbose)
{
- struct refspec rs;
+ struct refspec_item rs;
if (ref->status != REF_STATUS_OK && ref->status != REF_STATUS_UPTODATE)
return;
@@ -360,7 +427,13 @@ static void print_ref_status(char flag, const char *summary,
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
@@ -389,7 +462,7 @@ static void print_ok_ref_status(struct ref *ref, int porcelain, int summary_widt
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, "...");
@@ -400,7 +473,7 @@ static void print_ok_ref_status(struct ref *ref, int porcelain, int summary_widt
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,
@@ -483,7 +556,7 @@ static int print_one_push_status(struct ref *ref, const char *dest, int count,
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;
}
@@ -509,6 +582,9 @@ void transport_print_push_status(const char *dest, struct ref *refs,
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) {
@@ -546,35 +622,15 @@ void transport_print_push_status(const char *dest, struct ref *refs,
free(head);
}
-void transport_verify_remote_names(int nr_heads, const char **heads)
-{
- int i;
-
- for (i = 0; i < nr_heads; i++) {
- const char *local = heads[i];
- const char *remote = strrchr(heads[i], ':');
-
- if (*local == '+')
- local++;
-
- /* A matching refspec is okay. */
- if (remote == local && remote[1] == '\0')
- continue;
-
- remote = remote ? (remote + 1) : local;
- if (check_refname_format(remote,
- REFNAME_ALLOW_ONELEVEL|REFNAME_REFSPEC_PATTERN))
- die("remote part of refspec is not a valid name in %s",
- heads[i]);
- }
-}
-
static int git_transport_push(struct transport *transport, struct ref *remote_refs, int flags)
{
struct git_transport_data *data = transport->data;
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);
@@ -600,7 +656,7 @@ static int git_transport_push(struct transport *transport, struct ref *remote_re
switch (data->version) {
case protocol_v2:
- die("support for protocol v2 not implemented yet");
+ die(_("support for protocol v2 not implemented yet"));
break;
case protocol_v1:
case protocol_v0:
@@ -661,7 +717,7 @@ void transport_take_over(struct transport *transport,
struct git_transport_data *data;
if (!transport->smart_options)
- die("BUG: taking over transport requires non-NULL "
+ BUG("taking over transport requires non-NULL "
"smart_options field.");
data = xcalloc(1, sizeof(*data));
@@ -726,7 +782,7 @@ static enum protocol_allow_config parse_protocol_config(const char *key,
else if (!strcasecmp(value, "user"))
return PROTOCOL_ALLOW_USER_ONLY;
- die("unknown value for config '%s': %s", key, value);
+ die(_("unknown value for config '%s': %s"), key, value);
}
static enum protocol_allow_config get_protocol_config(const char *type)
@@ -786,13 +842,13 @@ int is_transport_allowed(const char *type, int from_user)
return from_user;
}
- die("BUG: invalid protocol_allow_config type");
+ BUG("invalid protocol_allow_config type");
}
void transport_check_allowed(const char *type)
{
if (!is_transport_allowed(type, -1))
- die("transport '%s' not allowed", type);
+ die(_("transport '%s' not allowed"), type);
}
static struct transport_vtable bundle_vtable = {
@@ -821,7 +877,7 @@ struct transport *transport_get(struct remote *remote, const char *url)
ret->progress = isatty(2);
if (!remote)
- die("No remote provided to transport_get()");
+ BUG("No remote provided to transport_get()");
ret->got_remote_refs = 0;
ret->remote = remote;
@@ -844,7 +900,7 @@ struct transport *transport_get(struct remote *remote, const char *url)
if (helper) {
transport_helper_init(ret, helper);
} else if (starts_with(url, "rsync:")) {
- die("git-over-rsync is no longer supported");
+ die(_("git-over-rsync is no longer supported"));
} else if (url_is_local_not_ssh(url) && is_file(url) && is_bundle(url, 1)) {
struct bundle_transport_data *data = xcalloc(1, sizeof(*data));
transport_check_allowed("file");
@@ -1017,11 +1073,13 @@ static int run_pre_push_hook(struct transport *transport,
}
int transport_push(struct transport *transport,
- int refspec_nr, const char **refspec, int flags,
+ struct refspec *rs, int flags,
unsigned int *reject_reasons)
{
*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;
@@ -1032,38 +1090,17 @@ int transport_push(struct transport *transport,
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)
+ if (check_push_refs(local_refs, rs) < 0)
return -1;
- 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);
- }
- }
+ refspec_ref_prefixes(rs, &ref_prefixes);
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;
@@ -1074,10 +1111,8 @@ int transport_push(struct transport *transport,
if (flags & TRANSPORT_PUSH_FOLLOW_TAGS)
match_flags |= MATCH_REFS_FOLLOW_TAGS;
- if (match_push_refs(local_refs, &remote_refs,
- refspec_nr, refspec, match_flags)) {
+ if (match_push_refs(local_refs, &remote_refs, rs, match_flags))
return -1;
- }
if (transport->smart_options &&
transport->smart_options->cas &&
@@ -1106,11 +1141,11 @@ int transport_push(struct transport *transport,
if (!push_unpushed_submodules(&commits,
transport->remote,
- refspec, refspec_nr,
+ rs,
transport->push_options,
pretend)) {
oid_array_clear(&commits);
- die("Failed to push all needed submodules!");
+ die(_("failed to push all needed submodules"));
}
oid_array_clear(&commits);
}
@@ -1193,7 +1228,7 @@ int transport_fetch_refs(struct transport *transport, struct ref *refs)
nr_refs++;
if (rm->peer_ref &&
!is_null_oid(&rm->old_oid) &&
- !oidcmp(&rm->peer_ref->old_oid, &rm->old_oid))
+ oideq(&rm->peer_ref->old_oid, &rm->old_oid))
continue;
ALLOC_GROW(heads, nr_heads + 1, nr_alloc);
heads[nr_heads++] = rm;
@@ -1232,7 +1267,7 @@ int transport_connect(struct transport *transport, const char *name,
if (transport->vtable->connect)
return transport->vtable->connect(transport, name, exec, fd);
else
- die("Operation not supported by protocol");
+ die(_("operation not supported by protocol"));
}
int transport_disconnect(struct transport *transport)
@@ -1314,7 +1349,7 @@ static void read_alternate_refs(const char *path,
if (get_oid_hex(line.buf, &oid) ||
line.buf[GIT_SHA1_HEXSZ] != ' ') {
- warning("invalid line while parsing alternate refs: %s",
+ warning(_("invalid line while parsing alternate refs: %s"),
line.buf);
break;
}