From f84370feaaf319b7fe9bd272a7ceba235cc1e86a Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Mon, 8 Aug 2016 12:31:39 -0700 Subject: [PATCH 1/2] Shallow fetch: Pass a DepthWalk to PackWriter d385a7a5e5ca (Shallow fetch: Respect "shallow" lines, 2016-08-03) forgot that UploadPack wasn't passing a DepthWalk to PackWriter in the first place. As a result, shallow clones fail: java.lang.IllegalArgumentException: Shallow packs require a DepthWalk at org.eclipse.jgit.internal.storage.pack.PackWriter.preparePack(PackWriter.java:756) at org.eclipse.jgit.transport.UploadPack.sendPack(UploadPack.java:1497) at org.eclipse.jgit.transport.UploadPack.sendPack(UploadPack.java:1381) at org.eclipse.jgit.transport.UploadPack.service(UploadPack.java:774) at org.eclipse.jgit.transport.UploadPack.upload(UploadPack.java:667) at org.eclipse.jgit.http.server.UploadPackServlet.doPost(UploadPackServlet.java:191) Change-Id: Ib0d8c2946eebfea910a2b767fb92e23da15d4749 --- .../src/org/eclipse/jgit/transport/UploadPack.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java index e1770f282..6704251e5 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java @@ -1484,16 +1484,19 @@ public class UploadPack { pw.setTagTargets(tagTargets); } - if (depth > 0) + RevWalk rw = walk; + if (depth > 0) { pw.setShallowPack(depth, unshallowCommits); + rw = new DepthWalk.RevWalk(walk.getObjectReader(), depth); + rw.assumeShallow(clientShallowCommits); + } - RevWalk rw = walk; if (wantAll.isEmpty()) { pw.preparePack(pm, wantIds, commonBase); } else { walk.reset(); - ObjectWalk ow = walk.toObjectWalkWithSameObjects(); + ObjectWalk ow = rw.toObjectWalkWithSameObjects(); pw.preparePack(pm, ow, wantAll, commonBase); rw = ow; } From b16e207742beb6a82b2b74df7bb87893a38bdd04 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Mon, 8 Aug 2016 12:35:36 -0700 Subject: [PATCH 2/2] Shallow fetch: Pass along "shallow"s in unparsed-wants case, too Since 84d2738ff21c (Don't skip want validation when the client sends no haves, 2013-06-21), this branch is not taken. Process the "shallow"s anyway as a defensive measure in case the code path gets revived. Change-Id: Idfb834825d77f51e17191c1635c9d78c78738cfd Signed-off-by: Jonathan Nieder --- .../internal/storage/pack/PackWriter.java | 25 +++++++++++++++++-- .../eclipse/jgit/transport/UploadPack.java | 2 +- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java index 106308f4a..ab879fa9e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java @@ -709,11 +709,32 @@ public class PackWriter implements AutoCloseable { public void preparePack(ProgressMonitor countingMonitor, @NonNull Set want, @NonNull Set have) throws IOException { + preparePack(countingMonitor, + want, have, Collections. emptySet()); + } + + /** + * Prepare the list of objects to be written to the pack stream. + *

+ * Like {@link #preparePack(ProgressMonitor, Set, Set)} but also allows + * specifying commits that should not be walked past ("shallow" commits). + * The caller is responsible for filtering out commits that should not + * be shallow any more ("unshallow" commits as in {@link #setShallowPack}) + * from the shallow set. + * + * @since 4.5 + */ + public void preparePack(ProgressMonitor countingMonitor, + @NonNull Set want, + @NonNull Set have, + @NonNull Set shallow) throws IOException { ObjectWalk ow; - if (shallowPack) + if (shallowPack) { ow = new DepthWalk.ObjectWalk(reader, depth); - else + } else { ow = new ObjectWalk(reader); + } + ow.assumeShallow(shallow); preparePack(countingMonitor, ow, want, have); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java index 6704251e5..d6c668dbf 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java @@ -1492,7 +1492,7 @@ public class UploadPack { } if (wantAll.isEmpty()) { - pw.preparePack(pm, wantIds, commonBase); + pw.preparePack(pm, wantIds, commonBase, clientShallowCommits); } else { walk.reset();