diff options
author | Jonathan Tan <jonathantanmy@google.com> | 2018-09-12 12:32:27 -0700 |
---|---|---|
committer | Jonathan Tan <jonathantanmy@google.com> | 2018-09-27 14:43:05 -0700 |
commit | 1bb430dc215f6522b62bab9b5f3c2663d522dc6a (patch) | |
tree | f335415da34c54e2ed931ad45cd69ce7c580fb3f /org.eclipse.jgit.test | |
parent | 953cf2c9dab3ee2a4e1fefa87ea87c7b8b1eb18f (diff) | |
download | jgit-1bb430dc215f6522b62bab9b5f3c2663d522dc6a.tar.gz jgit-1bb430dc215f6522b62bab9b5f3c2663d522dc6a.zip |
UploadPack: support deepen-since in protocol v2
Support the deepen-since parameter when requested by a client using
protocol v2. This is done by:
- adding a DepthWalk.RevWalk#setDeepenSince method
- updating DepthGenerator to recognize when deepen-since is set
- recording in DepthWalk.Commit whether a commit is a boundary commit
Existing users of DepthWalk such as UploadPack previously recognized
boundary commits by comparing their depths against the threshold, not
tracking whether any parents were truly excluded. This behavior is
preserved - UploadPack considers a commit as boundary if its depth is
equal to the threshold *or* a parent was excluded (whether by depth or
by deepen-since).
Change-Id: I852bba6b1279f9cc8aee38282e9339d62b8dcddc
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java index 317ac32e6d..20fb12b3ef 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java @@ -27,6 +27,7 @@ import org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription; import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository; import org.eclipse.jgit.junit.TestRepository; import org.eclipse.jgit.lib.NullProgressMonitor; +import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.lib.ProgressMonitor; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Repository; @@ -1191,6 +1192,59 @@ public class UploadPackTest { } @Test + public void testV2FetchShallowSince() throws Exception { + PersonIdent person = new PersonIdent(remote.getRepository()); + + RevCommit beyondBoundary = remote.commit() + .committer(new PersonIdent(person, 1510000000, 0)).create(); + RevCommit boundary = remote.commit().parent(beyondBoundary) + .committer(new PersonIdent(person, 1520000000, 0)).create(); + RevCommit tooOld = remote.commit() + .committer(new PersonIdent(person, 1500000000, 0)).create(); + RevCommit merge = remote.commit().parent(boundary).parent(tooOld) + .committer(new PersonIdent(person, 1530000000, 0)).create(); + + remote.update("branch1", merge); + + // Report that we only have "boundary" as a shallow boundary. + ByteArrayInputStream recvStream = uploadPackV2( + "command=fetch\n", + PacketLineIn.DELIM, + "shallow " + boundary.toObjectId().getName() + "\n", + "deepen-since 1510000\n", + "want " + merge.toObjectId().getName() + "\n", + "have " + boundary.toObjectId().getName() + "\n", + "done\n", + PacketLineIn.END); + PacketLineIn pckIn = new PacketLineIn(recvStream); + assertThat(pckIn.readString(), is("shallow-info")); + + // "merge" is shallow because one of its parents is committed + // earlier than the given deepen-since time. + assertThat(pckIn.readString(), is("shallow " + merge.toObjectId().getName())); + + // "boundary" is unshallow because its parent committed at or + // later than the given deepen-since time. + assertThat(pckIn.readString(), is("unshallow " + boundary.toObjectId().getName())); + + assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM)); + assertThat(pckIn.readString(), is("packfile")); + parsePack(recvStream); + + // The server does not send this because it is committed + // earlier than the given deepen-since time. + assertFalse(client.hasObject(tooOld.toObjectId())); + + // The server does not send this because the client claims to + // have it. + assertFalse(client.hasObject(boundary.toObjectId())); + + // The server sends both these commits. + assertTrue(client.hasObject(beyondBoundary.toObjectId())); + assertTrue(client.hasObject(merge.toObjectId())); + } + + @Test public void testV2FetchUnrecognizedArgument() throws Exception { thrown.expect(PackProtocolException.class); thrown.expectMessage("unexpected invalid-argument"); |