summaryrefslogtreecommitdiff
path: root/builtin/receive-pack.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2011-10-05 19:36:21 (GMT)
committerJunio C Hamano <gitster@pobox.com>2011-10-05 19:36:21 (GMT)
commit6f62cd7ab1c47a7ea32ab05cf1292d82c47310e9 (patch)
treea804881bfeb0e7b859d531b41bf95b1efaa891f5 /builtin/receive-pack.c
parent2e2e7e9dd07107af8ce96428929775f267fdf98a (diff)
parent52fed6e1ce07250ada3d2d0128015f131e3ad6c1 (diff)
downloadgit-6f62cd7ab1c47a7ea32ab05cf1292d82c47310e9.zip
git-6f62cd7ab1c47a7ea32ab05cf1292d82c47310e9.tar.gz
git-6f62cd7ab1c47a7ea32ab05cf1292d82c47310e9.tar.bz2
Merge branch 'jc/receive-verify'
* jc/receive-verify: receive-pack: check connectivity before concluding "git push" check_everything_connected(): libify check_everything_connected(): refactor to use an iterator fetch: verify we have everything we need before updating our ref Conflicts: builtin/fetch.c
Diffstat (limited to 'builtin/receive-pack.c')
-rw-r--r--builtin/receive-pack.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 4cc0306..9b56be3 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -11,6 +11,7 @@
#include "transport.h"
#include "string-list.h"
#include "sha1-array.h"
+#include "connected.h"
static const char receive_pack_usage[] = "git receive-pack <git-dir>";
@@ -585,6 +586,43 @@ static void check_aliased_updates(struct command *commands)
string_list_clear(&ref_list, 0);
}
+static int command_singleton_iterator(void *cb_data, unsigned char sha1[20])
+{
+ struct command **cmd_list = cb_data;
+ struct command *cmd = *cmd_list;
+
+ if (!cmd)
+ return -1; /* end of list */
+ *cmd_list = NULL; /* this returns only one */
+ hashcpy(sha1, cmd->new_sha1);
+ return 0;
+}
+
+static void set_connectivity_errors(struct command *commands)
+{
+ struct command *cmd;
+
+ for (cmd = commands; cmd; cmd = cmd->next) {
+ struct command *singleton = cmd;
+ if (!check_everything_connected(command_singleton_iterator,
+ 0, &singleton))
+ continue;
+ cmd->error_string = "missing necessary objects";
+ }
+}
+
+static int iterate_receive_command_list(void *cb_data, unsigned char sha1[20])
+{
+ struct command **cmd_list = cb_data;
+ struct command *cmd = *cmd_list;
+
+ if (!cmd)
+ return -1; /* end of list */
+ *cmd_list = cmd->next;
+ hashcpy(sha1, cmd->new_sha1);
+ return 0;
+}
+
static void execute_commands(struct command *commands, const char *unpacker_error)
{
struct command *cmd;
@@ -596,6 +634,11 @@ static void execute_commands(struct command *commands, const char *unpacker_erro
return;
}
+ cmd = commands;
+ if (check_everything_connected(iterate_receive_command_list,
+ 0, &cmd))
+ set_connectivity_errors(commands);
+
if (run_receive_hook(commands, pre_receive_hook)) {
for (cmd = commands; cmd; cmd = cmd->next)
cmd->error_string = "pre-receive hook declined";