private static void RegisterSmartSubtransportInternal <T>(SmartSubtransportRegistration <T> registration) where T : SmartSubtransport, new() { try { Proxy.git_transport_register(registration.Scheme, registration.FunctionPointer, registration.RegistrationPointer); } catch { registration.Free(); throw; } }
internal static void UnregisterDefaultSmartSubtransport <T>(SmartSubtransportRegistration <T> registration) where T : SmartSubtransport, new() { Ensure.ArgumentNotNull(registration, "registration"); var scheme = registration.Scheme; lock (smartSubtransportData) { if (!smartSubtransportData.ContainsKey(scheme)) { throw new Exception(string.Format("No default smart subtransport has been registered for {0}", scheme)); } if (registration != smartSubtransportData[scheme].defaultSubtransport) { throw new Exception(string.Format("The given smart subtransport is not the default for {0}", scheme)); } smartSubtransportData.Remove(scheme); UnregisterSmartSubtransportInternal(registration); } }
/// <summary> /// Registers a new <see cref="SmartSubtransport"/> as a custom /// smart-protocol transport with libgit2. Any Git remote with /// the scheme registered will delegate to the given transport /// for all communication with the server. This is not commonly /// used: some callers may want to re-use an existing connection to /// perform fetch / push operations to a remote. /// /// Note that this configuration is global to an entire process /// and does not honor application domains. /// </summary> /// <typeparam name="T">The type of SmartSubtransport to register</typeparam> /// <param name="scheme">The scheme (eg "http" or "gopher") to register</param> public static SmartSubtransportRegistration <T> RegisterSmartSubtransport <T>(string scheme) where T : SmartSubtransport, new() { Ensure.ArgumentNotNull(scheme, "scheme"); lock (smartSubtransportData) { var data = GetOrCreateSmartSubtransportData(scheme); if (data.isCustom) { throw new EntryExistsException(string.Format("A smart subtransport is already registered for {0}", scheme)); } if (data.defaultSubtransport != null) { Proxy.git_transport_unregister(scheme); } var previousValue = data.isCustom; data.isCustom = true; var registration = new SmartSubtransportRegistration <T>(scheme); try { RegisterSmartSubtransportInternal(registration); } catch { data.isCustom = previousValue; throw; } return(registration); } }
private static void UnregisterSmartSubtransportInternal <T>(SmartSubtransportRegistration <T> registration) where T : SmartSubtransport, new() { Proxy.git_transport_unregister(registration.Scheme); registration.Free(); }