예제 #1
0
 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;
     }
 }
예제 #2
0
        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);
            }
        }
예제 #3
0
        /// <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);
            }
        }
예제 #4
0
 private static void UnregisterSmartSubtransportInternal <T>(SmartSubtransportRegistration <T> registration)
     where T : SmartSubtransport, new()
 {
     Proxy.git_transport_unregister(registration.Scheme);
     registration.Free();
 }