summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse
diff options
context:
space:
mode:
authorShawn Pearce <sop@google.com>2014-08-27 10:41:59 -0700
committerShawn Pearce <sop@google.com>2014-08-27 12:45:17 -0700
commit199dd4a9a938e5c6ee7a06d0e0610e47b47ff050 (patch)
tree3380fb0545fb6e6c189ecfbf04be564366f7f86b /org.eclipse.jgit/src/org/eclipse
parent9bb891e44d23f87e3a97710ffdf877c2ec10b8ee (diff)
downloadjgit-199dd4a9a938e5c6ee7a06d0e0610e47b47ff050.tar.gz
jgit-199dd4a9a938e5c6ee7a06d0e0610e47b47ff050.zip
ReceivePack: Accept shallow lines from Git >= 1.9
In Git 1.9 (5dbd767601 "support pushing from a shallow clone") the git-core project intentionally broke the existing send-pack protocol from shallow clients. Shallow clients now transmit their shallow information during push, ahead of the old-new command sequence. JGit must accept these lines when presented. To protect the server against clients sending partial history, require the connectivity check when pushed to by a shallow client. Change-Id: I46639366b0900052c376091e1688f07def44ab79
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java23
1 files changed, 21 insertions, 2 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java
index 9d39f436c6..72c1697593 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java
@@ -222,7 +222,7 @@ public abstract class BaseReceivePack {
/** Capabilities requested by the client. */
private Set<String> enabledCapabilities;
-
+ private Set<ObjectId> clientShallowCommits;
private List<ReceiveCommand> commands;
private StringBuilder advertiseError;
@@ -263,6 +263,7 @@ public abstract class BaseReceivePack {
advertiseRefsHook = AdvertiseRefsHook.DEFAULT;
refFilter = RefFilter.DEFAULT;
advertisedHaves = new HashSet<ObjectId>();
+ clientShallowCommits = new HashSet<ObjectId>();
}
/** Configuration for receive operations. */
@@ -770,6 +771,18 @@ public abstract class BaseReceivePack {
throw new IllegalStateException(JGitText.get().packSizeNotSetYet);
}
+ /**
+ * Get the commits from the client's shallow file.
+ *
+ * @return if the client is a shallow repository, the list of edge commits
+ * that define the client's shallow boundary. Empty set if the client
+ * is earlier than Git 1.9, or is a full clone.
+ * @since 3.5
+ */
+ protected Set<ObjectId> getClientShallowCommits() {
+ return clientShallowCommits;
+ }
+
/** @return true if any commands to be executed have been read. */
protected boolean hasCommands() {
return !commands.isEmpty();
@@ -923,6 +936,11 @@ public abstract class BaseReceivePack {
if (line == PacketLineIn.END)
break;
+ if (line.length() >= 48 && line.startsWith("shallow ")) { //$NON-NLS-1$
+ clientShallowCommits.add(ObjectId.fromString(line.substring(8, 48)));
+ continue;
+ }
+
if (commands.isEmpty()) {
final FirstLine firstLine = new FirstLine(line);
enabledCapabilities = firstLine.getCapabilities();
@@ -1030,7 +1048,8 @@ public abstract class BaseReceivePack {
private boolean needCheckConnectivity() {
return isCheckReceivedObjects()
- || isCheckReferencedObjectsAreReachable();
+ || isCheckReferencedObjectsAreReachable()
+ || !getClientShallowCommits().isEmpty();
}
private void checkConnectivity() throws IOException {