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 8 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.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<Ref> 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<Ref> 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());

Loading…
Cancel
Save