Refactor unshallowCommits to local variable
This reduces the amount of state held as instance variables in UploadPack, and makes it easier for a future patch to contain a clearer version of UploadPack#processShallow. Change-Id: I6df80b42f9e5118fda1420692e02e417670cced3 Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Jonathan Nieder <jrn@google.com>
This commit is contained in:
parent
f516c1df9d
commit
cd0d69ffec
|
@ -299,9 +299,6 @@ public Set<String> getOptions() {
|
||||||
/** Shallow commits the client already has. */
|
/** Shallow commits the client already has. */
|
||||||
private final Set<ObjectId> clientShallowCommits = new HashSet<>();
|
private final Set<ObjectId> clientShallowCommits = new HashSet<>();
|
||||||
|
|
||||||
/** Shallow commits on the client which are now becoming unshallow */
|
|
||||||
private final List<ObjectId> unshallowCommits = new ArrayList<>();
|
|
||||||
|
|
||||||
/** Desired depth from the client on a shallow request. */
|
/** Desired depth from the client on a shallow request. */
|
||||||
private int depth;
|
private int depth;
|
||||||
|
|
||||||
|
@ -786,6 +783,7 @@ private void service() throws IOException {
|
||||||
// If it's a non-bidi request, we need to read the entire request before
|
// If it's a non-bidi request, we need to read the entire request before
|
||||||
// writing a response. Buffer the response until then.
|
// writing a response. Buffer the response until then.
|
||||||
PackStatistics.Accumulator accumulator = new PackStatistics.Accumulator();
|
PackStatistics.Accumulator accumulator = new PackStatistics.Accumulator();
|
||||||
|
List<ObjectId> unshallowCommits = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
if (biDirectionalPipe)
|
if (biDirectionalPipe)
|
||||||
sendAdvertisedRefs(new PacketLineOutRefAdvertiser(pckOut));
|
sendAdvertisedRefs(new PacketLineOutRefAdvertiser(pckOut));
|
||||||
|
@ -815,7 +813,7 @@ else if (requestValidator instanceof AnyRequestValidator)
|
||||||
if (!clientShallowCommits.isEmpty())
|
if (!clientShallowCommits.isEmpty())
|
||||||
verifyClientShallow();
|
verifyClientShallow();
|
||||||
if (depth != 0)
|
if (depth != 0)
|
||||||
processShallow();
|
processShallow(unshallowCommits);
|
||||||
if (!clientShallowCommits.isEmpty())
|
if (!clientShallowCommits.isEmpty())
|
||||||
walk.assumeShallow(clientShallowCommits);
|
walk.assumeShallow(clientShallowCommits);
|
||||||
sendPack = negotiate(accumulator);
|
sendPack = negotiate(accumulator);
|
||||||
|
@ -867,8 +865,9 @@ else if (requestValidator instanceof AnyRequestValidator)
|
||||||
rawOut.stopBuffering();
|
rawOut.stopBuffering();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sendPack)
|
if (sendPack) {
|
||||||
sendPack(accumulator, refs == null ? null : refs.values());
|
sendPack(accumulator, refs == null ? null : refs.values(), unshallowCommits);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void lsRefsV2() throws IOException {
|
private void lsRefsV2() throws IOException {
|
||||||
|
@ -999,7 +998,8 @@ private void fetchV2() throws IOException {
|
||||||
sendPack(new PackStatistics.Accumulator(),
|
sendPack(new PackStatistics.Accumulator(),
|
||||||
includeTag
|
includeTag
|
||||||
? db.getRefDatabase().getRefsByPrefix(R_TAGS)
|
? db.getRefDatabase().getRefsByPrefix(R_TAGS)
|
||||||
: null);
|
: null,
|
||||||
|
new ArrayList<ObjectId>());
|
||||||
}
|
}
|
||||||
pckOut.end();
|
pckOut.end();
|
||||||
}
|
}
|
||||||
|
@ -1076,7 +1076,11 @@ private static Set<ObjectId> refIdSet(Collection<Ref> refs) {
|
||||||
return ids;
|
return ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processShallow() throws IOException {
|
/*
|
||||||
|
* Determines what "shallow" and "unshallow" lines to send to the user.
|
||||||
|
* The information is written to pckOut and unshallowCommits.
|
||||||
|
*/
|
||||||
|
private void processShallow(List<ObjectId> unshallowCommits) throws IOException {
|
||||||
int walkDepth = depth - 1;
|
int walkDepth = depth - 1;
|
||||||
try (DepthWalk.RevWalk depthWalk = new DepthWalk.RevWalk(
|
try (DepthWalk.RevWalk depthWalk = new DepthWalk.RevWalk(
|
||||||
walk.getObjectReader(), walkDepth)) {
|
walk.getObjectReader(), walkDepth)) {
|
||||||
|
@ -1780,16 +1784,20 @@ private boolean wantSatisfied(RevObject want) throws IOException {
|
||||||
* refs to search for annotated tags to include in the pack
|
* refs to search for annotated tags to include in the pack
|
||||||
* if the {@link #OPTION_INCLUDE_TAG} capability was
|
* if the {@link #OPTION_INCLUDE_TAG} capability was
|
||||||
* requested.
|
* requested.
|
||||||
|
* @param unshallowCommits
|
||||||
|
* shallow commits on the client that are now becoming
|
||||||
|
* unshallow
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* if an error occured while generating or writing the pack.
|
* if an error occured while generating or writing the pack.
|
||||||
*/
|
*/
|
||||||
private void sendPack(PackStatistics.Accumulator accumulator,
|
private void sendPack(PackStatistics.Accumulator accumulator,
|
||||||
@Nullable Collection<Ref> allTags) throws IOException {
|
@Nullable Collection<Ref> allTags,
|
||||||
|
List<ObjectId> unshallowCommits) throws IOException {
|
||||||
final boolean sideband = options.contains(OPTION_SIDE_BAND)
|
final boolean sideband = options.contains(OPTION_SIDE_BAND)
|
||||||
|| options.contains(OPTION_SIDE_BAND_64K);
|
|| options.contains(OPTION_SIDE_BAND_64K);
|
||||||
if (sideband) {
|
if (sideband) {
|
||||||
try {
|
try {
|
||||||
sendPack(true, accumulator, allTags);
|
sendPack(true, accumulator, allTags, unshallowCommits);
|
||||||
} catch (ServiceMayNotContinueException noPack) {
|
} catch (ServiceMayNotContinueException noPack) {
|
||||||
// This was already reported on (below).
|
// This was already reported on (below).
|
||||||
throw noPack;
|
throw noPack;
|
||||||
|
@ -1810,7 +1818,7 @@ private void sendPack(PackStatistics.Accumulator accumulator,
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sendPack(false, accumulator, allTags);
|
sendPack(false, accumulator, allTags, unshallowCommits);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1842,12 +1850,16 @@ private boolean reportInternalServerErrorOverSideband() {
|
||||||
* refs to search for annotated tags to include in the pack
|
* refs to search for annotated tags to include in the pack
|
||||||
* if the {@link #OPTION_INCLUDE_TAG} capability was
|
* if the {@link #OPTION_INCLUDE_TAG} capability was
|
||||||
* requested.
|
* requested.
|
||||||
|
* @param unshallowCommits
|
||||||
|
* shallow commits on the client that are now becoming
|
||||||
|
* unshallow
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* if an error occured while generating or writing the pack.
|
* if an error occured while generating or writing the pack.
|
||||||
*/
|
*/
|
||||||
private void sendPack(final boolean sideband,
|
private void sendPack(final boolean sideband,
|
||||||
PackStatistics.Accumulator accumulator,
|
PackStatistics.Accumulator accumulator,
|
||||||
@Nullable Collection<Ref> allTags) throws IOException {
|
@Nullable Collection<Ref> allTags,
|
||||||
|
List<ObjectId> unshallowCommits) throws IOException {
|
||||||
ProgressMonitor pm = NullProgressMonitor.INSTANCE;
|
ProgressMonitor pm = NullProgressMonitor.INSTANCE;
|
||||||
OutputStream packOut = rawOut;
|
OutputStream packOut = rawOut;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue