Teach UploadPack "include-tag" in "fetch"
Add support for the "include-tag" parameter in the "fetch" command in the fetch-pack/upload-pack protocol v2. In order to determine which tags to include, only objects pointed to by refs starting with "refs/tags/" are checked. This restriction is for performance reasons and to match the behavior of Git (see add_ref_tag() in builtin/pack-objects.c). Change-Id: I7d70aa09bcc8a525218ff1559e286c2a610258ca Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Jonathan Nieder <jrn@google.com>
This commit is contained in:
parent
c79e7f1c27
commit
5a87d50408
|
@ -805,6 +805,39 @@ public void testV2FetchNoProgress() throws Exception {
|
|||
assertTrue(sw.toString().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testV2FetchIncludeTag() throws Exception {
|
||||
RevCommit commit = remote.commit().message("x").create();
|
||||
RevTag tag = remote.tag("tag", commit);
|
||||
remote.update("branch1", commit);
|
||||
remote.update("refs/tags/tag", tag);
|
||||
|
||||
// Without include-tag.
|
||||
ByteArrayInputStream recvStream = uploadPackV2(
|
||||
"command=fetch\n",
|
||||
PacketLineIn.DELIM,
|
||||
"want " + commit.toObjectId().getName() + "\n",
|
||||
"done\n",
|
||||
PacketLineIn.END);
|
||||
PacketLineIn pckIn = new PacketLineIn(recvStream);
|
||||
assertThat(pckIn.readString(), is("packfile"));
|
||||
parsePack(recvStream);
|
||||
assertFalse(client.hasObject(tag.toObjectId()));
|
||||
|
||||
// With tag.
|
||||
recvStream = uploadPackV2(
|
||||
"command=fetch\n",
|
||||
PacketLineIn.DELIM,
|
||||
"want " + commit.toObjectId().getName() + "\n",
|
||||
"include-tag\n",
|
||||
"done\n",
|
||||
PacketLineIn.END);
|
||||
pckIn = new PacketLineIn(recvStream);
|
||||
assertThat(pckIn.readString(), is("packfile"));
|
||||
parsePack(recvStream);
|
||||
assertTrue(client.hasObject(tag.toObjectId()));
|
||||
}
|
||||
|
||||
private static class RejectAllRefFilter implements RefFilter {
|
||||
@Override
|
||||
public Map<String, Ref> filter(Map<String, Ref> refs) {
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
|
||||
package org.eclipse.jgit.transport;
|
||||
|
||||
import static org.eclipse.jgit.lib.Constants.R_TAGS;
|
||||
import static org.eclipse.jgit.lib.RefDatabase.ALL;
|
||||
import static org.eclipse.jgit.transport.GitProtocolConstants.COMMAND_FETCH;
|
||||
import static org.eclipse.jgit.transport.GitProtocolConstants.COMMAND_LS_REFS;
|
||||
|
@ -951,6 +952,7 @@ private void fetchV2() throws IOException {
|
|||
.format(JGitText.get().unexpectedPacketLine, line));
|
||||
}
|
||||
|
||||
boolean includeTag = false;
|
||||
while ((line = pckIn.readString()) != PacketLineIn.END) {
|
||||
if (line.startsWith("want ")) { //$NON-NLS-1$
|
||||
wantIds.add(ObjectId.fromString(line.substring(5)));
|
||||
|
@ -962,6 +964,9 @@ private void fetchV2() throws IOException {
|
|||
options.add(OPTION_THIN_PACK);
|
||||
} else if (line.equals(OPTION_NO_PROGRESS)) {
|
||||
options.add(OPTION_NO_PROGRESS);
|
||||
} else if (line.equals(OPTION_INCLUDE_TAG)) {
|
||||
options.add(OPTION_INCLUDE_TAG);
|
||||
includeTag = true;
|
||||
}
|
||||
// else ignore it
|
||||
}
|
||||
|
@ -990,7 +995,9 @@ private void fetchV2() throws IOException {
|
|||
pckOut.writeDelim();
|
||||
pckOut.writeString("packfile\n"); //$NON-NLS-1$
|
||||
sendPack(new PackStatistics.Accumulator(),
|
||||
refs == null ? null : refs.values());
|
||||
includeTag
|
||||
? db.getRefDatabase().getRefsByPrefix(R_TAGS)
|
||||
: null);
|
||||
}
|
||||
pckOut.end();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue