Bug 455343 - [PATCH] Missing commit when fetching on shallow clone
Summary: [PATCH] Missing commit when fetching on shallow clone
Status: NEW
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: 3.5.2   Edit
Hardware: PC Windows 7
: P3 major with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA Friend
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-12-16 10:31 EST by Geoffrey McRae CLA Friend
Modified: 2019-08-12 12:26 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Geoffrey McRae CLA Friend 2014-12-16 10:31:14 EST
Using JGit on a shallow clone throws a 
  org.eclipse.jgit.errors.TransportException: Missing commit .....
exception.

The issue seems to be that the RevCommit.parents when set to RevCommit.NO_PARENTS by initializeShallowCommits in RevWalk is overwritten before StartGenerator.next is called.

This problem can be worked around by calling initializeShallowCommits in StartGenerator.next and commenting out the exception in initializeShallowCommits if it has already been initialized. This is obviously hacking around the problem, fixing this properly will need someone better versed with the JGit source to investigate.
Comment 1 Geoffrey McRae CLA Friend 2014-12-17 04:24:25 EST
Furhter investigation shows that initializeShallowCommits is never called on the RevWalk instance that is used in StartGenerator. The following patch fixes this, but I am unsure if this patch will cause any unexpected behaviour.

diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java
index 79cc42d..3047ad7 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java
@@ -201,8 +201,9 @@
 	 *            the repository the walker will obtain data from. An
 	 *            ObjectReader will be created by the walker, and must be
 	 *            released by the caller.
+	 * @throws RevWalkException
 	 */
-	public RevWalk(final Repository repo) {
+	public RevWalk(final Repository repo) throws RevWalkException {
 		this(repo.newObjectReader());
 	}
 
@@ -213,8 +214,9 @@
 	 *            the reader the walker will obtain data from. The reader should
 	 *            be released by the caller when the walker is no longer
 	 *            required.
+	 * @throws RevWalkException
 	 */
-	public RevWalk(ObjectReader or) {
+	public RevWalk(ObjectReader or) throws RevWalkException {
 		reader = or;
 		idBuffer = new MutableObjectId();
 		objects = new ObjectIdOwnerMap<RevObject>();
@@ -225,6 +227,12 @@
 		filter = RevFilter.ALL;
 		treeFilter = TreeFilter.ALL;
 		retainBody = true;
+
+		try {
+			initializeShallowCommits();
+		} catch (IOException e) {
+			throw new RevWalkException(e);
+		}
 	}
 
 	/** @return the reader this walker is using to load objects. */
Comment 2 Andrey Butirsky CLA Friend 2019-08-12 11:55:27 EDT
Any progress on this?
It seems blocks pushing from shallow clones to a new Gerrit repos