HackPushNegotiateHook to retain existing haves line
Since org.eclipse.jgit.transport.ReceivePack.setAdvertisedRefs() clears the any existing haves line added by the previous AdvertiseRefHook in the chain, HackPushNegotiateHook should include those in its own haves line. Change-Id: I51aad7b71f742717faa97112fdff5a0a1da8c4ac
This commit is contained in:
		| @@ -21,7 +21,6 @@ import com.google.common.flogger.FluentLogger; | |||||||
| import com.google.gerrit.git.ObjectIds; | import com.google.gerrit.git.ObjectIds; | ||||||
| import java.io.IOException; | import java.io.IOException; | ||||||
| import java.util.Collection; | import java.util.Collection; | ||||||
| import java.util.Collections; |  | ||||||
| import java.util.Map; | import java.util.Map; | ||||||
| import java.util.Set; | import java.util.Set; | ||||||
| import org.eclipse.jgit.lib.ObjectId; | import org.eclipse.jgit.lib.ObjectId; | ||||||
| @@ -92,35 +91,30 @@ public class HackPushNegotiateHook implements AdvertiseRefsHook { | |||||||
|  |  | ||||||
|   private Set<ObjectId> history(Collection<Ref> refs, BaseReceivePack rp) { |   private Set<ObjectId> history(Collection<Ref> refs, BaseReceivePack rp) { | ||||||
|     Set<ObjectId> alreadySending = rp.getAdvertisedObjects(); |     Set<ObjectId> alreadySending = rp.getAdvertisedObjects(); | ||||||
|     if (alreadySending.isEmpty()) { |     if (MAX_HISTORY <= alreadySending.size()) { | ||||||
|       alreadySending = idsOf(refs); |       return alreadySending; | ||||||
|     } |  | ||||||
|  |  | ||||||
|     int max = MAX_HISTORY - Math.max(0, alreadySending.size() - refs.size()); |  | ||||||
|     if (max <= 0) { |  | ||||||
|       return Collections.emptySet(); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     // Scan history until the advertisement is full. |     // Scan history until the advertisement is full. | ||||||
|     RevWalk rw = rp.getRevWalk(); |     RevWalk rw = rp.getRevWalk(); | ||||||
|     rw.reset(); |     rw.reset(); | ||||||
|     try { |     try { | ||||||
|       for (Ref ref : refs) { |       Set<ObjectId> tips = idsOf(refs); | ||||||
|  |       for (ObjectId tip : tips) { | ||||||
|         try { |         try { | ||||||
|           if (ref.getObjectId() != null) { |           rw.markStart(rw.parseCommit(tip)); | ||||||
|             rw.markStart(rw.parseCommit(ref.getObjectId())); |  | ||||||
|           } |  | ||||||
|         } catch (IOException badCommit) { |         } catch (IOException badCommit) { | ||||||
|           continue; |           continue; | ||||||
|         } |         } | ||||||
|       } |       } | ||||||
|  |  | ||||||
|       Set<ObjectId> history = Sets.newHashSetWithExpectedSize(max); |       Set<ObjectId> history = Sets.newHashSetWithExpectedSize(MAX_HISTORY); | ||||||
|  |       history.addAll(alreadySending); | ||||||
|       try { |       try { | ||||||
|         int stepCnt = 0; |         int stepCnt = 0; | ||||||
|         for (RevCommit c; history.size() < max && (c = rw.next()) != null; ) { |         for (RevCommit c; history.size() < MAX_HISTORY && (c = rw.next()) != null; ) { | ||||||
|           if (c.getParentCount() <= 1 |           if (c.getParentCount() <= 1 | ||||||
|               && !alreadySending.contains(c) |               && !tips.contains(c) | ||||||
|               && (history.size() < BASE_COMMITS || (++stepCnt % STEP_COMMITS) == 0)) { |               && (history.size() < BASE_COMMITS || (++stepCnt % STEP_COMMITS) == 0)) { | ||||||
|             history.add(c); |             history.add(c); | ||||||
|           } |           } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Minh Thai
					Minh Thai