Browse Source

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
stable-4.9
Shawn Pearce 7 years ago
parent
commit
0d20573d9c
  1. 19
      org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchProcess.java

19
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.BatchingProgressMonitor;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectIdRef;
import org.eclipse.jgit.lib.ProgressMonitor; import org.eclipse.jgit.lib.ProgressMonitor;
import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefDatabase; import org.eclipse.jgit.lib.RefDatabase;
@ -360,13 +361,20 @@ class FetchProcess {
private void expandSingle(final RefSpec spec, final Set<Ref> matched) private void expandSingle(final RefSpec spec, final Set<Ref> matched)
throws TransportException { 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) { 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); want(src, spec);
} }
}
private Collection<Ref> expandAutoFollowTags() throws TransportException { private Collection<Ref> expandAutoFollowTags() throws TransportException {
final Collection<Ref> additionalTags = new ArrayList<>(); final Collection<Ref> additionalTags = new ArrayList<>();
@ -440,6 +448,11 @@ class FetchProcess {
fetchHeadUpdates.add(fhr); 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) private TrackingRefUpdate createUpdate(RefSpec spec, ObjectId newId)
throws TransportException { throws TransportException {
Ref ref = localRefs().get(spec.getDestination()); Ref ref = localRefs().get(spec.getDestination());

Loading…
Cancel
Save