blob: d9a148622b2c54c247dfc2079971efe19895cbc4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
/*
* Copyright (c) 2019, Google LLC and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package org.eclipse.jgit.transport;
import java.io.IOException;
import java.util.List;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.transport.ReceiveCommand.Result;
/**
* Exception handler for processing {@link ReceiveCommand}.
*
* @since 5.7
*/
public interface ReceiveCommandErrorHandler {
/**
* Handle an exception thrown while validating the new commit ID.
*
* @param cmd
* offending command
* @param e
* exception thrown
*/
default void handleNewIdValidationException(ReceiveCommand cmd,
IOException e) {
cmd.setResult(Result.REJECTED_MISSING_OBJECT, cmd.getNewId().name());
}
/**
* Handle an exception thrown while validating the old commit ID.
*
* @param cmd
* offending command
* @param e
* exception thrown
*/
default void handleOldIdValidationException(ReceiveCommand cmd,
IOException e) {
cmd.setResult(Result.REJECTED_MISSING_OBJECT, cmd.getOldId().name());
}
/**
* Handle an exception thrown while checking if the update is fast-forward.
*
* @param cmd
* offending command
* @param e
* exception thrown
*/
default void handleFastForwardCheckException(ReceiveCommand cmd,
IOException e) {
if (e instanceof MissingObjectException) {
cmd.setResult(Result.REJECTED_MISSING_OBJECT, e.getMessage());
} else {
cmd.setResult(Result.REJECTED_OTHER_REASON);
}
}
/**
* Handle an exception thrown while checking if the update is fast-forward.
*
* @param cmds
* commands being processed
* @param e
* exception thrown
*/
default void handleBatchRefUpdateException(List<ReceiveCommand> cmds,
IOException e) {
for (ReceiveCommand cmd : cmds) {
if (cmd.getResult() == Result.NOT_ATTEMPTED) {
cmd.reject(e);
}
}
}
}
|