From 0d20573d9cdcbd41707323a7c964376218575750 Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Sun, 4 Jun 2017 13:58:16 -0700 Subject: [PATCH] fetch: Accept any SHA-1 on lhs of refspec Allow fetch to accept a SHA-1 on the left hand side of a RefSpec, enabling callers to pass a specific SHA-1 they want that may not have been advertised by the remote repository. This can be passed along to the network protocol to be sent in a "want" line. Rest of the plumbing only cares about the ObjectId of the Ref in the askFor map, so make up a fake name using ObjectId.name() to pass the desired ObjectId into the network code. Change-Id: I620a189f3de005c403aa68b7d0442d6aa94e6056 --- .../eclipse/jgit/transport/FetchProcess.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchProcess.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchProcess.java index 280e6d4df..dd26fe59a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchProcess.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchProcess.java @@ -74,6 +74,7 @@ import org.eclipse.jgit.lib.BatchRefUpdate; import org.eclipse.jgit.lib.BatchingProgressMonitor; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ObjectId; +import org.eclipse.jgit.lib.ObjectIdRef; import org.eclipse.jgit.lib.ProgressMonitor; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.RefDatabase; @@ -360,12 +361,19 @@ class FetchProcess { private void expandSingle(final RefSpec spec, final Set matched) throws TransportException { - final Ref src = conn.getRef(spec.getSource()); + String want = spec.getSource(); + if (ObjectId.isId(want)) { + want(ObjectId.fromString(want)); + return; + } + + Ref src = conn.getRef(want); if (src == null) { - throw new TransportException(MessageFormat.format(JGitText.get().remoteDoesNotHaveSpec, spec.getSource())); + throw new TransportException(MessageFormat.format(JGitText.get().remoteDoesNotHaveSpec, want)); } - if (matched.add(src)) + if (matched.add(src)) { want(src, spec); + } } private Collection expandAutoFollowTags() throws TransportException { @@ -440,6 +448,11 @@ class FetchProcess { fetchHeadUpdates.add(fhr); } + private void want(ObjectId id) { + askFor.put(id, + new ObjectIdRef.Unpeeled(Ref.Storage.NETWORK, id.name(), id)); + } + private TrackingRefUpdate createUpdate(RefSpec spec, ObjectId newId) throws TransportException { Ref ref = localRefs().get(spec.getDestination());