forked from libgit2/libgit2sharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGlobalSettings.cs
113 lines (99 loc) · 3.82 KB
/
GlobalSettings.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System;
using LibGit2Sharp.Core;
using LibGit2Sharp.Handlers;
namespace LibGit2Sharp
{
/// <summary>
/// Global settings for libgit2 and LibGit2Sharp.
/// </summary>
public static class GlobalSettings
{
private static readonly Lazy<Version> version = new Lazy<Version>(Version.Build);
private static LogConfiguration logConfiguration = LogConfiguration.None;
/// <summary>
/// Returns information related to the current LibGit2Sharp
/// library.
/// </summary>
public static Version Version
{
get
{
return version.Value;
}
}
/// <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. use this transport to communicate
/// 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");
var registration = new SmartSubtransportRegistration<T>(scheme);
try
{
Proxy.git_transport_register(
registration.Scheme,
registration.FunctionPointer,
registration.RegistrationPointer);
}
catch (Exception)
{
registration.Free();
throw;
}
return registration;
}
/// <summary>
/// Unregisters a previously registered <see cref="SmartSubtransport"/>
/// as a custom smart-protocol transport with libgit2.
/// </summary>
/// <typeparam name="T">The type of SmartSubtransport to register</typeparam>
/// <param name="registration">The previous registration</param>
public static void UnregisterSmartSubtransport<T>(SmartSubtransportRegistration<T> registration)
where T : SmartSubtransport, new()
{
Ensure.ArgumentNotNull(registration, "registration");
Proxy.git_transport_unregister(registration.Scheme);
registration.Free();
}
/// <summary>
/// Registers a new <see cref="LogConfiguration"/> to receive
/// information logging information from libgit2 and LibGit2Sharp.
///
/// Note that this configuration is global to an entire process
/// and does not honor application domains.
/// </summary>
public static LogConfiguration LogConfiguration
{
set
{
Ensure.ArgumentNotNull(value, "value");
logConfiguration = value;
if (logConfiguration.Level == LogLevel.None)
{
Proxy.git_trace_set(0, null);
}
else
{
Proxy.git_trace_set(value.Level, value.GitTraceHandler);
Log.Write(LogLevel.Info, "Logging enabled at level {0}", value.Level);
}
}
get
{
return logConfiguration;
}
}
}
}