Change RequestValidator parameter to ObjectId list
Instead of RevObject list, this allows a custom request validator to be called on SHA-1's corresponding to objects that may not exist in repository storage Change-Id: I19bb667beff0d0c144150a61d7a1dc6c9703be7f Signed-off-by: Greg Hill <greghill@google.com>
This commit is contained in:
parent
a76a4acf87
commit
1471fb4e0f
|
@ -161,7 +161,7 @@ public interface RequestValidator {
|
||||||
* if a low-level exception occurred.
|
* if a low-level exception occurred.
|
||||||
* @since 3.1
|
* @since 3.1
|
||||||
*/
|
*/
|
||||||
void checkWants(UploadPack up, List<RevObject> wants)
|
void checkWants(UploadPack up, List<ObjectId> wants)
|
||||||
throws PackProtocolException, IOException;
|
throws PackProtocolException, IOException;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1034,16 +1034,21 @@ private ObjectId processHaveLines(List<ObjectId> peerHas, ObjectId last)
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseWants() throws IOException {
|
private void parseWants() throws IOException {
|
||||||
AsyncRevObjectQueue q = walk.parseAny(wantIds, true);
|
List<ObjectId> notAdvertisedWants = null;
|
||||||
try {
|
for (ObjectId obj : wantIds) {
|
||||||
List<RevObject> notAdvertisedWants = null;
|
|
||||||
RevObject obj;
|
|
||||||
while ((obj = q.next()) != null) {
|
|
||||||
if (!advertised.contains(obj)) {
|
if (!advertised.contains(obj)) {
|
||||||
if (notAdvertisedWants == null)
|
if (notAdvertisedWants == null)
|
||||||
notAdvertisedWants = new ArrayList<RevObject>();
|
notAdvertisedWants = new ArrayList<ObjectId>();
|
||||||
notAdvertisedWants.add(obj);
|
notAdvertisedWants.add(obj);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (notAdvertisedWants != null)
|
||||||
|
requestValidator.checkWants(this, notAdvertisedWants);
|
||||||
|
|
||||||
|
AsyncRevObjectQueue q = walk.parseAny(wantIds, true);
|
||||||
|
try {
|
||||||
|
RevObject obj;
|
||||||
|
while ((obj = q.next()) != null) {
|
||||||
want(obj);
|
want(obj);
|
||||||
|
|
||||||
if (!(obj instanceof RevCommit))
|
if (!(obj instanceof RevCommit))
|
||||||
|
@ -1054,8 +1059,6 @@ private void parseWants() throws IOException {
|
||||||
want(obj);
|
want(obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (notAdvertisedWants != null)
|
|
||||||
requestValidator.checkWants(this, notAdvertisedWants);
|
|
||||||
wantIds.clear();
|
wantIds.clear();
|
||||||
} catch (MissingObjectException notFound) {
|
} catch (MissingObjectException notFound) {
|
||||||
ObjectId id = notFound.getObjectId();
|
ObjectId id = notFound.getObjectId();
|
||||||
|
@ -1080,7 +1083,7 @@ private void want(RevObject obj) {
|
||||||
*/
|
*/
|
||||||
public static final class AdvertisedRequestValidator
|
public static final class AdvertisedRequestValidator
|
||||||
implements RequestValidator {
|
implements RequestValidator {
|
||||||
public void checkWants(UploadPack up, List<RevObject> wants)
|
public void checkWants(UploadPack up, List<ObjectId> wants)
|
||||||
throws PackProtocolException, IOException {
|
throws PackProtocolException, IOException {
|
||||||
if (!up.isBiDirectionalPipe())
|
if (!up.isBiDirectionalPipe())
|
||||||
new ReachableCommitRequestValidator().checkWants(up, wants);
|
new ReachableCommitRequestValidator().checkWants(up, wants);
|
||||||
|
@ -1097,7 +1100,7 @@ else if (!wants.isEmpty())
|
||||||
*/
|
*/
|
||||||
public static final class ReachableCommitRequestValidator
|
public static final class ReachableCommitRequestValidator
|
||||||
implements RequestValidator {
|
implements RequestValidator {
|
||||||
public void checkWants(UploadPack up, List<RevObject> wants)
|
public void checkWants(UploadPack up, List<ObjectId> wants)
|
||||||
throws PackProtocolException, IOException {
|
throws PackProtocolException, IOException {
|
||||||
checkNotAdvertisedWants(up.getRevWalk(), wants,
|
checkNotAdvertisedWants(up.getRevWalk(), wants,
|
||||||
refIdSet(up.getAdvertisedRefs().values()));
|
refIdSet(up.getAdvertisedRefs().values()));
|
||||||
|
@ -1110,14 +1113,14 @@ public void checkWants(UploadPack up, List<RevObject> wants)
|
||||||
* @since 3.1
|
* @since 3.1
|
||||||
*/
|
*/
|
||||||
public static final class TipRequestValidator implements RequestValidator {
|
public static final class TipRequestValidator implements RequestValidator {
|
||||||
public void checkWants(UploadPack up, List<RevObject> wants)
|
public void checkWants(UploadPack up, List<ObjectId> wants)
|
||||||
throws PackProtocolException, IOException {
|
throws PackProtocolException, IOException {
|
||||||
if (!up.isBiDirectionalPipe())
|
if (!up.isBiDirectionalPipe())
|
||||||
new ReachableCommitTipRequestValidator().checkWants(up, wants);
|
new ReachableCommitTipRequestValidator().checkWants(up, wants);
|
||||||
else if (!wants.isEmpty()) {
|
else if (!wants.isEmpty()) {
|
||||||
Set<ObjectId> refIds =
|
Set<ObjectId> refIds =
|
||||||
refIdSet(up.getRepository().getAllRefs().values());
|
refIdSet(up.getRepository().getAllRefs().values());
|
||||||
for (RevObject obj : wants) {
|
for (ObjectId obj : wants) {
|
||||||
if (!refIds.contains(obj))
|
if (!refIds.contains(obj))
|
||||||
throw new PackProtocolException(MessageFormat.format(
|
throw new PackProtocolException(MessageFormat.format(
|
||||||
JGitText.get().wantNotValid, obj.name()));
|
JGitText.get().wantNotValid, obj.name()));
|
||||||
|
@ -1133,7 +1136,7 @@ else if (!wants.isEmpty()) {
|
||||||
*/
|
*/
|
||||||
public static final class ReachableCommitTipRequestValidator
|
public static final class ReachableCommitTipRequestValidator
|
||||||
implements RequestValidator {
|
implements RequestValidator {
|
||||||
public void checkWants(UploadPack up, List<RevObject> wants)
|
public void checkWants(UploadPack up, List<ObjectId> wants)
|
||||||
throws PackProtocolException, IOException {
|
throws PackProtocolException, IOException {
|
||||||
checkNotAdvertisedWants(up.getRevWalk(), wants,
|
checkNotAdvertisedWants(up.getRevWalk(), wants,
|
||||||
refIdSet(up.getRepository().getAllRefs().values()));
|
refIdSet(up.getRepository().getAllRefs().values()));
|
||||||
|
@ -1146,14 +1149,14 @@ public void checkWants(UploadPack up, List<RevObject> wants)
|
||||||
* @since 3.1
|
* @since 3.1
|
||||||
*/
|
*/
|
||||||
public static final class AnyRequestValidator implements RequestValidator {
|
public static final class AnyRequestValidator implements RequestValidator {
|
||||||
public void checkWants(UploadPack up, List<RevObject> wants)
|
public void checkWants(UploadPack up, List<ObjectId> wants)
|
||||||
throws PackProtocolException, IOException {
|
throws PackProtocolException, IOException {
|
||||||
// All requests are valid.
|
// All requests are valid.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void checkNotAdvertisedWants(RevWalk walk,
|
private static void checkNotAdvertisedWants(RevWalk walk,
|
||||||
List<RevObject> notAdvertisedWants, Set<ObjectId> reachableFrom)
|
List<ObjectId> notAdvertisedWants, Set<ObjectId> reachableFrom)
|
||||||
throws MissingObjectException, IncorrectObjectTypeException, IOException {
|
throws MissingObjectException, IncorrectObjectTypeException, IOException {
|
||||||
// Walk the requested commits back to the provided set of commits. If any
|
// Walk the requested commits back to the provided set of commits. If any
|
||||||
// commit exists, a branch was deleted or rewound and the repository owner
|
// commit exists, a branch was deleted or rewound and the repository owner
|
||||||
|
@ -1161,12 +1164,22 @@ private static void checkNotAdvertisedWants(RevWalk walk,
|
||||||
// into an advertised branch it will be marked UNINTERESTING and no commits
|
// into an advertised branch it will be marked UNINTERESTING and no commits
|
||||||
// return.
|
// return.
|
||||||
|
|
||||||
for (RevObject obj : notAdvertisedWants) {
|
AsyncRevObjectQueue q = walk.parseAny(notAdvertisedWants, true);
|
||||||
|
try {
|
||||||
|
RevObject obj;
|
||||||
|
while ((obj = q.next()) != null) {
|
||||||
if (!(obj instanceof RevCommit))
|
if (!(obj instanceof RevCommit))
|
||||||
throw new PackProtocolException(MessageFormat.format(
|
throw new PackProtocolException(MessageFormat.format(
|
||||||
JGitText.get().wantNotValid, obj.name()));
|
JGitText.get().wantNotValid, obj.name()));
|
||||||
walk.markStart((RevCommit) obj);
|
walk.markStart((RevCommit) obj);
|
||||||
}
|
}
|
||||||
|
} catch (MissingObjectException notFound) {
|
||||||
|
ObjectId id = notFound.getObjectId();
|
||||||
|
throw new PackProtocolException(MessageFormat.format(
|
||||||
|
JGitText.get().wantNotValid, id.name()), notFound);
|
||||||
|
} finally {
|
||||||
|
q.release();
|
||||||
|
}
|
||||||
for (ObjectId id : reachableFrom) {
|
for (ObjectId id : reachableFrom) {
|
||||||
try {
|
try {
|
||||||
walk.markUninteresting(walk.parseCommit(id));
|
walk.markUninteresting(walk.parseCommit(id));
|
||||||
|
|
Loading…
Reference in New Issue