Skip to content

Commit 80ea092

Browse files
committed
Fix when Register is called before NativeMethod cctor
1 parent 9daf4cc commit 80ea092

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

LibGit2Sharp/GlobalSettings.cs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,15 @@ internal static SmartSubtransportRegistration<T> RegisterDefaultSmartSubtranspor
116116
throw new Exception(string.Format("A default subtransport is already configured for {0}", scheme));
117117
}
118118

119-
var registration = RegisterSmartSubtransportInternal<T>(scheme);
119+
var registration = new SmartSubtransportRegistration<T>(scheme);
120+
121+
if (!data.isCustom)
122+
{
123+
RegisterSmartSubtransportInternal(registration);
124+
}
120125

121126
data.defaultSubtransport = registration;
127+
122128
return registration;
123129
}
124130
}
@@ -140,8 +146,6 @@ internal static SmartSubtransportRegistration<T> RegisterDefaultSmartSubtranspor
140146
public static SmartSubtransportRegistration<T> RegisterSmartSubtransport<T>(string scheme)
141147
where T : SmartSubtransport, new()
142148
{
143-
SmartSubtransportRegistration<T> registration;
144-
145149
Ensure.ArgumentNotNull(scheme, "scheme");
146150

147151
lock (smartSubtransportData)
@@ -158,31 +162,39 @@ public static SmartSubtransportRegistration<T> RegisterSmartSubtransport<T>(stri
158162
Proxy.git_transport_unregister(scheme);
159163
}
160164

161-
registration = RegisterSmartSubtransportInternal<T>(scheme);
165+
var previousValue = data.isCustom;
162166
data.isCustom = true;
163-
}
164167

165-
return registration;
168+
var registration = new SmartSubtransportRegistration<T>(scheme);
169+
170+
try
171+
{
172+
RegisterSmartSubtransportInternal(registration);
173+
}
174+
catch
175+
{
176+
data.isCustom = previousValue;
177+
throw;
178+
}
179+
180+
return registration;
181+
}
166182
}
167183

168-
private static SmartSubtransportRegistration<T> RegisterSmartSubtransportInternal<T>(string scheme)
184+
private static void RegisterSmartSubtransportInternal<T>(SmartSubtransportRegistration<T> registration)
169185
where T : SmartSubtransport, new()
170186
{
171-
var registration = new SmartSubtransportRegistration<T>(scheme);
172-
173187
try
174188
{
175189
Proxy.git_transport_register(registration.Scheme,
176190
registration.FunctionPointer,
177191
registration.RegistrationPointer);
178192
}
179-
catch (Exception)
193+
catch
180194
{
181195
registration.Free();
182196
throw;
183197
}
184-
185-
return registration;
186198
}
187199

188200
/// <summary>

0 commit comments

Comments
 (0)