1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.internal.ketch;
12
13 import java.util.Collection;
14 import java.util.Map;
15
16 import org.eclipse.jgit.annotations.Nullable;
17 import org.eclipse.jgit.lib.Ref;
18 import org.eclipse.jgit.lib.Repository;
19 import org.eclipse.jgit.transport.ReceiveCommand;
20
21
22
23
24
25
26
27
28
29 public class ReplicaPushRequest {
30 private final KetchReplica replica;
31 private final Collection<ReceiveCommand> commands;
32 private Map<String, Ref> refs;
33 private Throwable exception;
34 private boolean notified;
35
36
37
38
39
40
41
42
43
44 public ReplicaPushRequest(KetchReplica replica,
45 Collection<ReceiveCommand> commands) {
46 this.replica = replica;
47 this.commands = commands;
48 }
49
50
51
52
53
54
55 public Collection<ReceiveCommand> getCommands() {
56 return commands;
57 }
58
59
60
61
62
63
64 @Nullable
65 public Map<String, Ref> getRefs() {
66 return refs;
67 }
68
69
70
71
72
73
74
75 public void setRefs(Map<String, Ref> refs) {
76 this.refs = refs;
77 }
78
79
80
81
82
83
84 @Nullable
85 public Throwable getException() {
86 return exception;
87 }
88
89
90
91
92
93
94
95
96
97
98
99
100 public void setException(@Nullable Repository repo, Throwable err) {
101 if (KetchReplica.log.isErrorEnabled()) {
102 KetchReplica.log.error(describe("failed"), err);
103 }
104 if (!notified) {
105 notified = true;
106 exception = err;
107 replica.afterPush(repo, this);
108 }
109 }
110
111
112
113
114
115
116
117
118
119
120 public void done(Repository repo) {
121 if (KetchReplica.log.isDebugEnabled()) {
122 KetchReplica.log.debug(describe("completed"));
123 }
124 if (!notified) {
125 notified = true;
126 replica.afterPush(repo, this);
127 }
128 }
129
130 private String describe(String heading) {
131 StringBuilder b = new StringBuilder();
132 b.append("push to ");
133 b.append(replica.describeForLog());
134 b.append(' ').append(heading).append(":\n");
135 for (ReceiveCommand cmd : commands) {
136 b.append(String.format(
137 " %-12s %-12s %s %s",
138 LeaderSnapshot.str(cmd.getOldId()),
139 LeaderSnapshot.str(cmd.getNewId()),
140 cmd.getRefName(),
141 cmd.getResult()));
142 if (cmd.getMessage() != null) {
143 b.append(' ').append(cmd.getMessage());
144 }
145 b.append('\n');
146 }
147 return b.toString();
148 }
149 }