8000 Configuration: now backed by a repository · vrkcse2011/libgit2sharp@ff2d847 · GitHub
[go: up one dir, main page]

Skip to content

Commit ff2d847

Browse files
committed
Configuration: now backed by a repository
Configurations are now (optionally) backed by a repository. Provide one whenever possible.
1 parent 70229b0 commit ff2d847

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

LibGit2Sharp/Configuration.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,41 +52,42 @@ internal Configuration(
5252
private void Init(Repository repository)
5353
{
5454
configHandle = Proxy.git_config_new();
55+
RepositoryHandle repoHandle = (repository != null) ? repository.Handle : null;
5556

56-
if (repository != null)
57+
if (repoHandle != null)
5758
{
5859
//TODO: push back this logic into libgit2.
5960
// As stated by @carlosmn "having a helper function to load the defaults and then allowing you
6061
// to modify it before giving it to git_repository_open_ext() would be a good addition, I think."
6162
// -- Agreed :)
6263
string repoConfigLocation = Path.Combine(repository.Info.Path, "config");
63-
Proxy.git_config_add_file_ondisk(configHandle, repoConfigLocation, ConfigurationLevel.Local);
64+
Proxy.git_config_add_file_ondisk(configHandle, repoConfigLocation, ConfigurationLevel.Local, repoHandle);
6465

65-
Proxy.git_repository_set_config(repository.Handle, configHandle);
66+
Proxy.git_repository_set_config(repoHandle, configHandle);
6667
}
6768
else if (repoConfigPath != null)
6869
{
69-
Proxy.git_config_add_file_ondisk(configHandle, repoConfigPath, ConfigurationLevel.Local);
70+
Proxy.git_config_add_file_ondisk(configHandle, repoConfigPath, ConfigurationLevel.Local, repoHandle);
7071
}
7172

7273
if (globalConfigPath != null)
7374
{
74-
Proxy.git_config_add_file_ondisk(configHandle, globalConfigPath, ConfigurationLevel.Global);
75+
Proxy.git_config_add_file_ondisk(configHandle, globalConfigPath, ConfigurationLevel.Global, repoHandle);
7576
}
7677

7778
if (xdgConfigPath != null)
7879
{
79-
Proxy.git_config_add_file_ondisk(configHandle, xdgConfigPath, ConfigurationLevel.Xdg);
80+
Proxy.git_config_add_file_ondisk(configHandle, xdgConfigPath, ConfigurationLevel.Xdg, repoHandle);
8081
}
8182

8283
if (systemConfigPath != null)
8384
{
84-
Proxy.git_config_add_file_ondisk(configHandle, systemConfigPath, ConfigurationLevel.System);
85+
Proxy.git_config_add_file_ondisk(configHandle, systemConfigPath, ConfigurationLevel.System, repoHandle);
8586
}
8687

8788
if (programDataConfigPath != null)
8889
{
89-
Proxy.git_config_add_file_ondisk(configHandle, programDataConfigPath, ConfigurationLevel.ProgramData);
90+
Proxy.git_config_add_file_ondisk(configHandle, programDataConfigPath, ConfigurationLevel.ProgramData, repoHandle);
9091
}
9192
}
9293

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ internal static extern unsafe int git_config_add_file_ondisk(
373373
git_config* cfg,
374374
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictFilePathMarshaler))] FilePath path,
375375
uint level,
376+
git_repository* repo,
376377
[MarshalAs(UnmanagedType.Bool)] bool force);
377378

378379
[DllImport(libgit2)]

LibGit2Sharp/Core/Proxy.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,9 +517,11 @@ public static unsafe SignatureInfo git_commit_extract_signature(RepositoryHandle
517517

518518
#region git_config_
519519

520-
public static unsafe void git_config_add_file_ondisk(ConfigurationHandle config, FilePath path, ConfigurationLevel level)
520+
public static unsafe void git_config_add_file_ondisk(ConfigurationHandle config, FilePath path, ConfigurationLevel level, RepositoryHandle repo)
521521
{
522-
int res = NativeMethods.git_config_add_file_ondisk(config, path, (uint)level, true);
522+
// RepositoryHandle does implicit cast voodoo that is not null-safe, thus this explicit check
523+
git_repository* repoHandle = (repo != null) ? (git_repository*)repo : null;
524+
int res = NativeMethods.git_config_add_file_ondisk(config, path, (uint)level, repoHandle, true);
523525
Ensure.ZeroResult(res);
524526
}
525527

0 commit comments

Comments
 (0)
0