summaryrefslogtreecommitdiff
path: root/transport-helper.c
diff options
context:
space:
mode:
Diffstat (limited to 'transport-helper.c')
-rw-r--r--transport-helper.c298
1 files changed, 216 insertions, 82 deletions
diff --git a/transport-helper.c b/transport-helper.c
index a46afcb..8d284b2 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -1,19 +1,23 @@
-#include "cache.h"
+#include "git-compat-util.h"
#include "transport.h"
#include "quote.h"
#include "run-command.h"
#include "commit.h"
-#include "diff.h"
-#include "revision.h"
+#include "environment.h"
+#include "gettext.h"
+#include "hex.h"
+#include "object-name.h"
+#include "repository.h"
#include "remote.h"
#include "string-list.h"
#include "thread-utils.h"
#include "sigchain.h"
-#include "argv-array.h"
+#include "strvec.h"
#include "refs.h"
#include "refspec.h"
#include "transport-internal.h"
#include "protocol.h"
+#include "packfile.h"
static int debug;
@@ -32,7 +36,8 @@ struct helper_data {
signed_tags : 1,
check_connectivity : 1,
no_disconnect_req : 1,
- no_private_update : 1;
+ no_private_update : 1,
+ object_format : 1;
/*
* As an optimization, the transport code may invoke fetch before
@@ -127,17 +132,17 @@ static struct child_process *get_helper(struct transport *transport)
helper->in = -1;
helper->out = -1;
helper->err = 0;
- argv_array_pushf(&helper->args, "git-remote-%s", data->name);
- argv_array_push(&helper->args, transport->remote->name);
- argv_array_push(&helper->args, remove_ext_force(transport->url));
- helper->git_cmd = 0;
+ strvec_pushf(&helper->args, "remote-%s", data->name);
+ strvec_push(&helper->args, transport->remote->name);
+ strvec_push(&helper->args, remove_ext_force(transport->url));
+ helper->git_cmd = 1;
helper->silent_exec_failure = 1;
if (have_git_dir())
- argv_array_pushf(&helper->env_array, "%s=%s",
- GIT_DIR_ENVIRONMENT, get_git_dir());
+ strvec_pushf(&helper->env, "%s=%s",
+ GIT_DIR_ENVIRONMENT, get_git_dir());
- helper->trace2_child_class = helper->args.argv[0]; /* "remote-<name>" */
+ helper->trace2_child_class = helper->args.v[0]; /* "remote-<name>" */
code = start_command(helper);
if (code < 0 && errno == ENOENT)
@@ -207,6 +212,8 @@ static struct child_process *get_helper(struct transport *transport)
data->import_marks = xstrdup(arg);
} else if (starts_with(capname, "no-private-update")) {
data->no_private_update = 1;
+ } else if (starts_with(capname, "object-format")) {
+ data->object_format = 1;
} else if (mandatory) {
die(_("unknown mandatory capability %s; this remote "
"helper probably needs newer version of Git"),
@@ -410,10 +417,11 @@ static int fetch_with_fetch(struct transport *transport,
exit(128);
if (skip_prefix(buf.buf, "lock ", &name)) {
- if (transport->pack_lockfile)
+ if (transport->pack_lockfiles.nr)
warning(_("%s also locked %s"), data->name, name);
else
- transport->pack_lockfile = xstrdup(name);
+ string_list_append(&transport->pack_lockfiles,
+ name);
}
else if (data->check_connectivity &&
data->transport_options.check_self_contained_and_connected &&
@@ -425,6 +433,8 @@ static int fetch_with_fetch(struct transport *transport,
warning(_("%s unexpectedly said: '%s'"), data->name, buf.buf);
}
strbuf_release(&buf);
+
+ reprepare_packed_git(the_repository);
return 0;
}
@@ -435,13 +445,13 @@ static int get_importer(struct transport *transport, struct child_process *fasti
int cat_blob_fd, code;
child_process_init(fastimport);
fastimport->in = xdup(helper->out);
- argv_array_push(&fastimport->args, "fast-import");
- argv_array_push(&fastimport->args, "--allow-unsafe-features");
- argv_array_push(&fastimport->args, debug ? "--stats" : "--quiet");
+ strvec_push(&fastimport->args, "fast-import");
+ strvec_push(&fastimport->args, "--allow-unsafe-features");
+ strvec_push(&fastimport->args, debug ? "--stats" : "--quiet");
if (data->bidi_import) {
cat_blob_fd = xdup(helper->in);
- argv_array_pushf(&fastimport->args, "--cat-blob-fd=%d", cat_blob_fd);
+ strvec_pushf(&fastimport->args, "--cat-blob-fd=%d", cat_blob_fd);
}
fastimport->git_cmd = 1;
@@ -462,17 +472,17 @@ static int get_exporter(struct transport *transport,
/* we need to duplicate helper->in because we want to use it after
* fastexport is done with it. */
fastexport->out = dup(helper->in);
- argv_array_push(&fastexport->args, "fast-export");
- argv_array_push(&fastexport->args, "--use-done-feature");
- argv_array_push(&fastexport->args, data->signed_tags ?
+ strvec_push(&fastexport->args, "fast-export");
+ strvec_push(&fastexport->args, "--use-done-feature");
+ strvec_push(&fastexport->args, data->signed_tags ?
"--signed-tags=verbatim" : "--signed-tags=warn-strip");
if (data->export_marks)
- argv_array_pushf(&fastexport->args, "--export-marks=%s.tmp", data->export_marks);
+ strvec_pushf(&fastexport->args, "--export-marks=%s.tmp", data->export_marks);
if (data->import_marks)
- argv_array_pushf(&fastexport->args, "--import-marks=%s", data->import_marks);
+ strvec_pushf(&fastexport->args, "--import-marks=%s", data->import_marks);
for (i = 0; i < revlist_args->nr; i++)
- argv_array_push(&fastexport->args, revlist_args->items[i].string);
+ strvec_push(&fastexport->args, revlist_args->items[i].string);
fastexport->git_cmd = 1;
return start_command(fastexport);
@@ -619,7 +629,8 @@ static int process_connect_service(struct transport *transport,
ret = run_connect(transport, &cmdbuf);
} else if (data->stateless_connect &&
(get_protocol_version_config() == protocol_v2) &&
- !strcmp("git-upload-pack", name)) {
+ (!strcmp("git-upload-pack", name) ||
+ !strcmp("git-upload-archive", name))) {
strbuf_addf(&cmdbuf, "stateless-connect %s\n", name);
ret = run_connect(transport, &cmdbuf);
if (ret)
@@ -636,6 +647,7 @@ static int process_connect(struct transport *transport,
struct helper_data *data = transport->data;
const char *name;
const char *exec;
+ int ret;
name = for_push ? "git-receive-pack" : "git-upload-pack";
if (for_push)
@@ -643,7 +655,10 @@ static int process_connect(struct transport *transport,
else
exec = data->transport_options.uploadpack;
- return process_connect_service(transport, name, exec);
+ ret = process_connect_service(transport, name, exec);
+ if (ret)
+ do_take_over(transport);
+ return ret;
}
static int connect_helper(struct transport *transport, const char *name,
@@ -653,31 +668,39 @@ static int connect_helper(struct transport *transport, const char *name,
/* Get_helper so connect is inited. */
get_helper(transport);
- if (!data->connect)
- die(_("operation not supported by protocol"));
if (!process_connect_service(transport, name, exec))
die(_("can't connect to subservice %s"), name);
fd[0] = data->helper->out;
fd[1] = data->helper->in;
+
+ do_take_over(transport);
return 0;
}
static struct ref *get_refs_list_using_list(struct transport *transport,
int for_push);
-static int fetch(struct transport *transport,
- int nr_heads, struct ref **to_fetch)
+static int fetch_refs(struct transport *transport,
+ int nr_heads, struct ref **to_fetch)
{
struct helper_data *data = transport->data;
int i, count;
get_helper(transport);
- if (process_connect(transport, 0)) {
- do_take_over(transport);
- return transport->vtable->fetch(transport, nr_heads, to_fetch);
+ if (process_connect(transport, 0))
+ return transport->vtable->fetch_refs(transport, nr_heads, to_fetch);
+
+ /*
+ * If we reach here, then the server, the client, and/or the transport
+ * helper does not support protocol v2. --negotiate-only requires
+ * protocol v2.
+ */
+ if (data->transport_options.acked_commits) {
+ warning(_("--negotiate-only requires protocol v2"));
+ return -1;
}
if (!data->get_refs_list_called)
@@ -701,6 +724,9 @@ static int fetch(struct transport *transport,
if (data->transport_options.update_shallow)
set_helper_option(transport, "update-shallow", "true");
+ if (data->transport_options.refetch)
+ set_helper_option(transport, "refetch", "true");
+
if (data->transport_options.filter_options.choice) {
const char *spec = expand_list_objects_filter_spec(
&data->transport_options.filter_options);
@@ -719,13 +745,61 @@ static int fetch(struct transport *transport,
return -1;
}
+struct push_update_ref_state {
+ struct ref *hint;
+ struct ref_push_report *report;
+ int new_report;
+};
+
static int push_update_ref_status(struct strbuf *buf,
- struct ref **ref,
+ struct push_update_ref_state *state,
struct ref *remote_refs)
{
char *refname, *msg;
int status, forced = 0;
+ if (starts_with(buf->buf, "option ")) {
+ struct object_id old_oid, new_oid;
+ const char *key, *val;
+ char *p;
+
+ if (!state->hint || !(state->report || state->new_report))
+ die(_("'option' without a matching 'ok/error' directive"));
+ if (state->new_report) {
+ if (!state->hint->report) {
+ CALLOC_ARRAY(state->hint->report, 1);
+ state->report = state->hint->report;
+ } else {
+ state->report = state->hint->report;
+ while (state->report->next)
+ state->report = state->report->next;
+ CALLOC_ARRAY(state->report->next, 1);
+ state->report = state->report->next;
+ }
+ state->new_report = 0;
+ }
+ key = buf->buf + 7;
+ p = strchr(key, ' ');
+ if (p)
+ *p++ = '\0';
+ val = p;
+ if (!strcmp(key, "refname"))
+ state->report->ref_name = xstrdup_or_null(val);
+ else if (!strcmp(key, "old-oid") && val &&
+ !parse_oid_hex(val, &old_oid, &val))
+ state->report->old_oid = oiddup(&old_oid);
+ else if (!strcmp(key, "new-oid") && val &&
+ !parse_oid_hex(val, &new_oid, &val))
+ state->report->new_oid = oiddup(&new_oid);
+ else if (!strcmp(key, "forced-update"))
+ state->report->forced_update = 1;
+ /* Not update remote namespace again. */
+ return 1;
+ }
+
+ state->report = NULL;
+ state->new_report = 0;
+
if (starts_with(buf->buf, "ok ")) {
status = REF_STATUS_OK;
refname = buf->buf + 3;
@@ -775,22 +849,30 @@ static int push_update_ref_status(struct strbuf *buf,
status = REF_STATUS_REJECT_STALE;
FREE_AND_NULL(msg);
}
+ else if (!strcmp(msg, "remote ref updated since checkout")) {
+ status = REF_STATUS_REJECT_REMOTE_UPDATED;
+ FREE_AND_NULL(msg);
+ }
else if (!strcmp(msg, "forced update")) {
forced = 1;
FREE_AND_NULL(msg);
}
+ else if (!strcmp(msg, "expecting report")) {
+ status = REF_STATUS_EXPECTING_REPORT;
+ FREE_AND_NULL(msg);
+ }
}
- if (*ref)
- *ref = find_ref_by_name(*ref, refname);
- if (!*ref)
- *ref = find_ref_by_name(remote_refs, refname);
- if (!*ref) {
+ if (state->hint)
+ state->hint = find_ref_by_name(state->hint, refname);
+ if (!state->hint)
+ state->hint = find_ref_by_name(remote_refs, refname);
+ if (!state->hint) {
warning(_("helper reported unexpected status of %s"), refname);
return 1;
}
- if ((*ref)->status != REF_STATUS_NONE) {
+ if (state->hint->status != REF_STATUS_NONE) {
/*
* Earlier, the ref was marked not to be pushed, so ignore the ref
* status reported by the remote helper if the latter is 'no match'.
@@ -799,9 +881,11 @@ static int push_update_ref_status(struct strbuf *buf,
return 1;
}
- (*ref)->status = status;
- (*ref)->forced_update |= forced;
- (*ref)->remote_status = msg;
+ if (status == REF_STATUS_OK)
+ state->new_report = 1;
+ state->hint->status = status;
+ state->hint->forced_update |= forced;
+ state->hint->remote_status = msg;
return !(status == REF_STATUS_OK);
}
@@ -809,37 +893,57 @@ static int push_update_refs_status(struct helper_data *data,
struct ref *remote_refs,
int flags)
{
+ struct ref *ref;
+ struct ref_push_report *report;
struct strbuf buf = STRBUF_INIT;
- struct ref *ref = remote_refs;
- int ret = 0;
+ struct push_update_ref_state state = { remote_refs, NULL, 0 };
for (;;) {
- char *private;
-
if (recvline(data, &buf)) {
- ret = 1;
- break;
+ strbuf_release(&buf);
+ return 1;
}
-
if (!buf.len)
break;
+ push_update_ref_status(&buf, &state, remote_refs);
+ }
+ strbuf_release(&buf);
- if (push_update_ref_status(&buf, &ref, remote_refs))
- continue;
+ if (flags & TRANSPORT_PUSH_DRY_RUN || !data->rs.nr || data->no_private_update)
+ return 0;
- if (flags & TRANSPORT_PUSH_DRY_RUN || !data->rs.nr || data->no_private_update)
- continue;
+ /* propagate back the update to the remote namespace */
+ for (ref = remote_refs; ref; ref = ref->next) {
+ char *private;
- /* propagate back the update to the remote namespace */
- private = apply_refspecs(&data->rs, ref->name);
- if (!private)
+ if (ref->status != REF_STATUS_OK)
continue;
- update_ref("update by helper", private, &ref->new_oid, NULL,
- 0, 0);
- free(private);
+
+ if (!ref->report) {
+ private = apply_refspecs(&data->rs, ref->name);
+ if (!private)
+ continue;
+ update_ref("update by helper", private, &(ref->new_oid),
+ NULL, 0, 0);
+ free(private);
+ } else {
+ for (report = ref->report; report; report = report->next) {
+ private = apply_refspecs(&data->rs,
+ report->ref_name
+ ? report->ref_name
+ : ref->name);
+ if (!private)
+ continue;
+ update_ref("update by helper", private,
+ report->new_oid
+ ? report->new_oid
+ : &(ref->new_oid),
+ NULL, 0, 0);
+ free(private);
+ }
+ }
}
- strbuf_release(&buf);
- return ret;
+ return 0;
}
static void set_common_push_options(struct transport *transport,
@@ -860,6 +964,11 @@ static void set_common_push_options(struct transport *transport,
if (set_helper_option(transport, TRANS_OPT_ATOMIC, "true") != 0)
die(_("helper %s does not support --atomic"), name);
+ if (flags & TRANSPORT_PUSH_FORCE_IF_INCLUDES)
+ if (set_helper_option(transport, TRANS_OPT_FORCE_IF_INCLUDES, "true") != 0)
+ die(_("helper %s does not support --%s"),
+ name, TRANS_OPT_FORCE_IF_INCLUDES);
+
if (flags & TRANSPORT_PUSH_OPTIONS) {
struct string_list_item *item;
for_each_string_list_item(item, transport->push_options)
@@ -893,6 +1002,7 @@ static int push_refs_with_push(struct transport *transport,
case REF_STATUS_REJECT_NONFASTFORWARD:
case REF_STATUS_REJECT_STALE:
case REF_STATUS_REJECT_ALREADY_EXISTS:
+ case REF_STATUS_REJECT_REMOTE_UPDATED:
if (atomic) {
reject_atomic_push(remote_refs, mirror);
string_list_clear(&cas_options, 0);
@@ -968,7 +1078,7 @@ static int push_refs_with_export(struct transport *transport,
set_common_push_options(transport, data->name, flags);
if (flags & TRANSPORT_PUSH_FORCE) {
if (set_helper_option(transport, "force", "true") != 0)
- warning(_("helper %s does not support 'force'"), data->name);
+ warning(_("helper %s does not support '--force'"), data->name);
}
helper = get_helper(transport);
@@ -980,7 +1090,7 @@ static int push_refs_with_export(struct transport *transport,
struct object_id oid;
private = apply_refspecs(&data->rs, ref->name);
- if (private && !get_oid(private, &oid)) {
+ if (private && !repo_get_oid(the_repository, private, &oid)) {
strbuf_addf(&buf, "^%s", private);
string_list_append_nodup(&revlist_args,
strbuf_detach(&buf, NULL));
@@ -1038,15 +1148,13 @@ static int push_refs(struct transport *transport,
{
struct helper_data *data = transport->data;
- if (process_connect(transport, 1)) {
- do_take_over(transport);
+ if (process_connect(transport, 1))
return transport->vtable->push_refs(transport, remote_refs, flags);
- }
if (!remote_refs) {
fprintf(stderr,
_("No refs in common and none specified; doing nothing.\n"
- "Perhaps you should specify a branch such as 'master'.\n"));
+ "Perhaps you should specify a branch.\n"));
return 0;
}
@@ -1078,14 +1186,13 @@ static int has_attribute(const char *attrs, const char *attr)
}
static struct ref *get_refs_list(struct transport *transport, int for_push,
- const struct argv_array *ref_prefixes)
+ struct transport_ls_refs_options *transport_options)
{
get_helper(transport);
- if (process_connect(transport, for_push)) {
- do_take_over(transport);
- return transport->vtable->get_refs_list(transport, for_push, ref_prefixes);
- }
+ if (process_connect(transport, for_push))
+ return transport->vtable->get_refs_list(transport, for_push,
+ transport_options);
return get_refs_list_using_list(transport, for_push);
}
@@ -1103,10 +1210,13 @@ static struct ref *get_refs_list_using_list(struct transport *transport,
data->get_refs_list_called = 1;
helper = get_helper(transport);
+ if (data->object_format)
+ set_helper_option(transport, "object-format", "true");
+
if (data->push && for_push)
- write_str_in_full(helper->in, "list for-push\n");
+ write_constant(helper->in, "list for-push\n");
else
- write_str_in_full(helper->in, "list\n");
+ write_constant(helper->in, "list\n");
while (1) {
char *eov, *eon;
@@ -1115,6 +1225,17 @@ static struct ref *get_refs_list_using_list(struct transport *transport,
if (!*buf.buf)
break;
+ else if (buf.buf[0] == ':') {
+ const char *value;
+ if (skip_prefix(buf.buf, ":object-format ", &value)) {
+ int algo = hash_algo_by_name(value);
+ if (algo == GIT_HASH_UNKNOWN)
+ die(_("unsupported object format '%s'"),
+ value);
+ transport->hash_algo = &hash_algos[algo];
+ }
+ continue;
+ }
eov = strchr(buf.buf, ' ');
if (!eov)
@@ -1127,7 +1248,7 @@ static struct ref *get_refs_list_using_list(struct transport *transport,
if (buf.buf[0] == '@')
(*tail)->symref = xstrdup(buf.buf + 1);
else if (buf.buf[0] != '?')
- get_oid_hex(buf.buf, &(*tail)->old_oid);
+ get_oid_hex_algop(buf.buf, &(*tail)->old_oid, transport->hash_algo);
if (eon) {
if (has_attribute(eon + 1, "unchanged")) {
(*tail)->status |= REF_STATUS_UPTODATE;
@@ -1148,13 +1269,24 @@ static struct ref *get_refs_list_using_list(struct transport *transport,
return ret;
}
+static int get_bundle_uri(struct transport *transport)
+{
+ get_helper(transport);
+
+ if (process_connect(transport, 0))
+ return transport->vtable->get_bundle_uri(transport);
+
+ return -1;
+}
+
static struct transport_vtable vtable = {
- set_helper_option,
- get_refs_list,
- fetch,
- push_refs,
- connect_helper,
- release_helper
+ .set_option = set_helper_option,
+ .get_refs_list = get_refs_list,
+ .get_bundle_uri = get_bundle_uri,
+ .fetch_refs = fetch_refs,
+ .push_refs = push_refs,
+ .connect = connect_helper,
+ .disconnect = release_helper
};
int transport_helper_init(struct transport *transport, const char *name)
@@ -1167,6 +1299,8 @@ int transport_helper_init(struct transport *transport, const char *name)
if (getenv("GIT_TRANSPORT_HELPER_DEBUG"))
debug = 1;
+ list_objects_filter_init(&data->transport_options.filter_options);
+
transport->data = data;
transport->vtable = &vtable;
transport->smart_options = &(data->transport_options);