Skip to content

Commit a6a8431

Browse files
stefanbellergitster
authored andcommitted
receive-pack.c: shorten the execute_commands loop over all commands
Make the main "execute_commands" loop in receive-pack easier to read by splitting out some steps into helper functions. The new helper 'should_process_cmd' checks if a ref update is unnecessary, whether due to an error having occurred or for another reason. The helper 'warn_if_skipped_connectivity_check' warns if we have forgotten to run a connectivity check on a ref which is shallow for the client which would be a bug. This will help us to duplicate less code in a later patch when we make a second copy of the "execute_commands" loop. No functional change intended. Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c653e03 commit a6a8431

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

builtin/receive-pack.c

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,11 +1042,34 @@ static void reject_updates_to_hidden(struct command *commands)
10421042
}
10431043
}
10441044

1045+
static int should_process_cmd(struct command *cmd)
1046+
{
1047+
return !cmd->error_string && !cmd->skip_update;
1048+
}
1049+
1050+
static void warn_if_skipped_connectivity_check(struct command *commands,
1051+
struct shallow_info *si)
1052+
{
1053+
struct command *cmd;
1054+
int checked_connectivity = 1;
1055+
1056+
for (cmd = commands; cmd; cmd = cmd->next) {
1057+
if (should_process_cmd(cmd) && si->shallow_ref[cmd->index]) {
1058+
error("BUG: connectivity check has not been run on ref %s",
1059+
cmd->ref_name);
1060+
checked_connectivity = 0;
1061+
}
1062+
}
1063+
if (!checked_connectivity)
1064+
error("BUG: run 'git fsck' for safety.\n"
1065+
"If there are errors, try to remove "
1066+
"the reported refs above");
1067+
}
1068+
10451069
static void execute_commands(struct command *commands,
10461070
const char *unpacker_error,
10471071
struct shallow_info *si)
10481072
{
1049-
int checked_connectivity;
10501073
struct command *cmd;
10511074
unsigned char sha1[20];
10521075
struct iterate_data data;
@@ -1077,27 +1100,15 @@ static void execute_commands(struct command *commands,
10771100
free(head_name_to_free);
10781101
head_name = head_name_to_free = resolve_refdup("HEAD", 0, sha1, NULL);
10791102

1080-
checked_connectivity = 1;
10811103
for (cmd = commands; cmd; cmd = cmd->next) {
1082-
if (cmd->error_string)
1083-
continue;
1084-
1085-
if (cmd->skip_update)
1104+
if (!should_process_cmd(cmd))
10861105
continue;
10871106

10881107
cmd->error_string = update(cmd, si);
1089-
if (shallow_update && !cmd->error_string &&
1090-
si->shallow_ref[cmd->index]) {
1091-
error("BUG: connectivity check has not been run on ref %s",
1092-
cmd->ref_name);
1093-
checked_connectivity = 0;
1094-
}
10951108
}
10961109

1097-
if (shallow_update && !checked_connectivity)
1098-
error("BUG: run 'git fsck' for safety.\n"
1099-
"If there are errors, try to remove "
1100-
"the reported refs above");
1110+
if (shallow_update)
1111+
warn_if_skipped_connectivity_check(commands, si);
11011112
}
11021113

11031114
static struct command **queue_command(struct command **tail,

0 commit comments

Comments
 (0)