From c961e2d7730b5e0e63841e16bf82ec3d9f589133 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Wed, 26 Dec 2018 12:40:28 -0800 Subject: [PATCH] UploadPack: Avoid calling AdvertiseRefsHook twice The AdvertiseRefsHook can be called twice if the following conditions hold: 1. This AdvertiseRefsHook doesn't set this.refs. 2. getAdvertisedOrDefaultRefs is called after getFilteredRefs. For example, this can happen when fetchV2 is called after lsRefsV2 when using a stateful bidirectional transport. The second call does not accomplish anything useful. Guard it with 'if (!advertiseRefsHookCalled)' to avoid wasted work. Reported-by: Jonathan Tan Change-Id: Ib746582e4ef645b767a5b3fb969596df99ac2ab5 Signed-off-by: Jonathan Nieder --- .../src/org/eclipse/jgit/transport/UploadPack.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java index 1cdf8f7f1..6a3d9a1cd 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java @@ -790,8 +790,10 @@ public class UploadPack { return refs; } - advertiseRefsHook.advertiseRefs(this); - advertiseRefsHookCalled = true; + if (!advertiseRefsHookCalled) { + advertiseRefsHook.advertiseRefs(this); + advertiseRefsHookCalled = true; + } if (refs == null) { // Fall back to all refs. setAdvertisedRefs(