receive-pack: check connectivity before concluding "git push"
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Sep 2, 2011 at 16:52 UTC
52fed6e1ce07250ada3d2d0128015f131e3ad6c1
1 file changed
+43
builtin/receive-pack.c
+43
@@ -11,6 +11,7 @@
11
#include "transport.h"
12
#include "string-list.h"
13
#include "sha1-array.h"
14
+#include "connected.h"
15
16
static const char receive_pack_usage[] = "git receive-pack <git-dir>";
17
@@ -546,6 +547,43 @@ static void check_aliased_updates(struct command *commands)
547
string_list_clear(&ref_list, 0);
548
}
549
550
+static int command_singleton_iterator(void *cb_data, unsigned char sha1[20])
551
+{
552
+ struct command **cmd_list = cb_data;
553
+ struct command *cmd = *cmd_list;
554
+
555
+ if (!cmd)
556
+ return -1; /* end of list */
557
+ *cmd_list = NULL; /* this returns only one */
558
+ hashcpy(sha1, cmd->new_sha1);
559
+ return 0;
560
+}
561
+
562
+static void set_connectivity_errors(struct command *commands)
563
+{
564
+ struct command *cmd;
565
+
566
+ for (cmd = commands; cmd; cmd = cmd->next) {
567
+ struct command *singleton = cmd;
568
+ if (!check_everything_connected(command_singleton_iterator,
569
+ 0, &singleton))
570
+ continue;
571
+ cmd->error_string = "missing necessary objects";
572
+ }
573
+}
574
+
575
+static int iterate_receive_command_list(void *cb_data, unsigned char sha1[20])
576
+{
577
+ struct command **cmd_list = cb_data;
578
+ struct command *cmd = *cmd_list;
579
+
580
+ if (!cmd)
581
+ return -1; /* end of list */
582
+ *cmd_list = cmd->next;
583
+ hashcpy(sha1, cmd->new_sha1);
584
+ return 0;
585
+}
586
+
587
static void execute_commands(struct command *commands, const char *unpacker_error)
588
{
589
struct command *cmd;
@@ -557,6 +595,11 @@ static void execute_commands(struct command *commands, const char *unpacker_erro
595
return;
596
}
597
598
+ cmd = commands;
599
+ if (check_everything_connected(iterate_receive_command_list,
600
+ 0, &cmd))
601
+ set_connectivity_errors(commands);
602
+
603
if (run_receive_hook(commands, pre_receive_hook)) {
604
for (cmd = commands; cmd; cmd = cmd->next)
605
cmd->error_string = "pre-receive hook declined";