|
|
|
|
|
|
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.Map; |
|
|
import java.util.Map; |
|
|
import java.util.Set; |
|
|
import java.util.Set; |
|
|
|
|
|
|
|
|
import org.eclipse.jgit.errors.CorruptObjectException; |
|
|
import org.eclipse.jgit.errors.CorruptObjectException; |
|
|
import org.eclipse.jgit.errors.IncorrectObjectTypeException; |
|
|
import org.eclipse.jgit.errors.IncorrectObjectTypeException; |
|
|
import org.eclipse.jgit.errors.MissingObjectException; |
|
|
import org.eclipse.jgit.errors.MissingObjectException; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void checkWants(UploadPack up, List<ObjectId> wants) |
|
|
public void checkWants(UploadPack up, List<ObjectId> wants) |
|
|
throws PackProtocolException, IOException { |
|
|
throws PackProtocolException, IOException { |
|
|
checkNotAdvertisedWants(up.getRevWalk(), wants, |
|
|
|
|
|
|
|
|
checkNotAdvertisedWants(up, wants, |
|
|
refIdSet(up.getAdvertisedRefs().values())); |
|
|
refIdSet(up.getAdvertisedRefs().values())); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void checkWants(UploadPack up, List<ObjectId> wants) |
|
|
public void checkWants(UploadPack up, List<ObjectId> wants) |
|
|
throws PackProtocolException, IOException { |
|
|
throws PackProtocolException, IOException { |
|
|
checkNotAdvertisedWants(up.getRevWalk(), wants, |
|
|
|
|
|
|
|
|
checkNotAdvertisedWants(up, wants, |
|
|
refIdSet(up.getRepository().getRefDatabase().getRefs(ALL).values())); |
|
|
refIdSet(up.getRepository().getRefDatabase().getRefs(ALL).values())); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private static void checkNotAdvertisedWants(RevWalk walk, |
|
|
|
|
|
|
|
|
private static void checkNotAdvertisedWants(UploadPack up, |
|
|
List<ObjectId> 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 |
|
|
|
|
|
|
|
|
// 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. |
|
|
|
|
|
|
|
|
AsyncRevObjectQueue q = walk.parseAny(notAdvertisedWants, true); |
|
|
|
|
|
try { |
|
|
|
|
|
RevObject obj; |
|
|
|
|
|
while ((obj = q.next()) != null) { |
|
|
|
|
|
if (!(obj instanceof RevCommit)) |
|
|
|
|
|
throw new WantNotValidException(obj); |
|
|
|
|
|
walk.markStart((RevCommit) obj); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (MissingObjectException notFound) { |
|
|
|
|
|
throw new WantNotValidException(notFound.getObjectId(), notFound); |
|
|
|
|
|
} finally { |
|
|
|
|
|
q.release(); |
|
|
|
|
|
} |
|
|
|
|
|
for (ObjectId id : reachableFrom) { |
|
|
|
|
|
|
|
|
try (RevWalk walk = new RevWalk(up.getRevWalk().getObjectReader())) { |
|
|
|
|
|
AsyncRevObjectQueue q = walk.parseAny(notAdvertisedWants, true); |
|
|
try { |
|
|
try { |
|
|
walk.markUninteresting(walk.parseCommit(id)); |
|
|
|
|
|
} catch (IncorrectObjectTypeException notCommit) { |
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
RevObject obj; |
|
|
|
|
|
while ((obj = q.next()) != null) { |
|
|
|
|
|
if (!(obj instanceof RevCommit)) |
|
|
|
|
|
throw new WantNotValidException(obj); |
|
|
|
|
|
walk.markStart((RevCommit) obj); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (MissingObjectException notFound) { |
|
|
|
|
|
throw new WantNotValidException(notFound.getObjectId(), |
|
|
|
|
|
notFound); |
|
|
|
|
|
} finally { |
|
|
|
|
|
q.release(); |
|
|
|
|
|
} |
|
|
|
|
|
for (ObjectId id : reachableFrom) { |
|
|
|
|
|
try { |
|
|
|
|
|
walk.markUninteresting(walk.parseCommit(id)); |
|
|
|
|
|
} catch (IncorrectObjectTypeException notCommit) { |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
RevCommit bad = walk.next(); |
|
|
|
|
|
if (bad != null) { |
|
|
|
|
|
throw new WantNotValidException(bad); |
|
|
|
|
|
|
|
|
RevCommit bad = walk.next(); |
|
|
|
|
|
if (bad != null) { |
|
|
|
|
|
throw new WantNotValidException(bad); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
walk.reset(); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void addCommonBase(final RevObject o) { |
|
|
private void addCommonBase(final RevObject o) { |