aboutsummaryrefslogtreecommitdiff
path: root/network/receivepack/service/hook_apply.go
diff options
context:
space:
mode:
Diffstat (limited to 'network/receivepack/service/hook_apply.go')
-rw-r--r--network/receivepack/service/hook_apply.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/network/receivepack/service/hook_apply.go b/network/receivepack/service/hook_apply.go
new file mode 100644
index 00000000..5bd8f596
--- /dev/null
+++ b/network/receivepack/service/hook_apply.go
@@ -0,0 +1,44 @@
+package service
+
+func buildHookUpdates(commands []Command) []RefUpdate {
+ updates := make([]RefUpdate, 0, len(commands))
+ for _, command := range commands {
+ updates = append(updates, RefUpdate{
+ Name: command.Name,
+ OldID: command.OldID,
+ NewID: command.NewID,
+ })
+ }
+
+ return updates
+}
+
+func resultForHookRejection(command Command, message string) CommandResult {
+ result := successCommandResult(command)
+ result.Error = message
+
+ return result
+}
+
+func mergeCommandResults(
+ commands []Command,
+ rejected map[int]string,
+ applied []CommandResult,
+ appliedIndices []int,
+) []CommandResult {
+ out := make([]CommandResult, len(commands))
+
+ for index, message := range rejected {
+ out[index] = resultForHookRejection(commands[index], message)
+ }
+
+ for i, appliedResult := range applied {
+ if i >= len(appliedIndices) {
+ break
+ }
+
+ out[appliedIndices[i]] = appliedResult
+ }
+
+ return out
+}