This repository was archived by the owner on Feb 3, 2023. It is now read-only.
forked from libgit2/libgit2sharp
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathGlobalSettings.cs
More file actions
207 lines (179 loc) · 7.33 KB
/
Copy pathGlobalSettings.cs
File metadata and controls
207 lines (179 loc) · 7.33 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
using System;
using System.IO;
using System.Reflection;
using LibGit2Sharp.Core;
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;
private static string nativeLibraryPath;
private static bool nativeLibraryPathLocked;
static GlobalSettings()
{
if (Platform.OperatingSystem == OperatingSystemType.Windows)
{
string managedPath = new Uri(Assembly.GetExecutingAssembly().EscapedCodeBase).LocalPath;
nativeLibraryPath = Path.Combine(Path.GetDirectoryName(managedPath), "NativeBinaries");
}
}
/// <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.GitTraceCallback);
Log.Write(LogLevel.Info, "Logging enabled at level {0}", value.Level);
}
}
get
{
return logConfiguration;
}
}
/// <summary>
/// Sets a hint path for searching for native binaries: when
/// specified, native binaries will first be searched in a
/// subdirectory of the given path corresponding to the architecture
/// (eg, "x86" or "amd64") before falling back to the default
/// path ("NativeBinaries\x86" or "NativeBinaries\amd64" next
/// to the application).
/// <para>
/// This must be set before any other calls to the library,
/// and is not available on Unix platforms: see your dynamic
/// library loader's documentation for details.
/// </para>
/// </summary>
public static string NativeLibraryPath
{
get
{
if (Platform.OperatingSystem != OperatingSystemType.Windows)
{
throw new LibGit2SharpException("Querying the native hint path is only supported on Windows platforms");
}
return nativeLibraryPath;
}
set
{
if (Platform.OperatingSystem != OperatingSystemType.Windows)
{
throw new LibGit2SharpException("Setting the native hint path is only supported on Windows platforms");
}
if (nativeLibraryPathLocked)
{
throw new LibGit2SharpException("You cannot set the native library path after it has been loaded");
}
nativeLibraryPath = value;
}
}
internal static string GetAndLockNativeLibraryPath()
{
nativeLibraryPathLocked = true;
return nativeLibraryPath;
}
/// <summary>
/// Register a filter globally with a default priority of 200 allowing the custom filter
/// to imitate a core Git filter driver. It will be run last on checkout and first on checkin.
/// </summary>
public static FilterRegistration RegisterFilter(Filter filter)
{
return RegisterFilter(filter, 200);
}
/// <summary>
/// Register a filter globally with given priority for execution.
/// A filter with the priority of 200 will be run last on checkout and first on checkin.
/// A filter with the priority of 0 will be run first on checkout and last on checkin.
/// </summary>
public static FilterRegistration RegisterFilter(Filter filter, int priority)
{
var registration = new FilterRegistration(filter);
Proxy.git_filter_register(filter.Name, registration, priority);
return registration;
}
/// <summary>
/// Remove the filter from the registry, and frees the native heap allocation.
/// </summary>
public static void DeregisterFilter(FilterRegistration registration)
{
Ensure.ArgumentNotNull(registration, "registration");
Proxy.git_filter_unregister(registration.Name);
registration.Free();
}
}
}