Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2sharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Dahlby <dahlbyk@gmail.com>2011-10-08 09:00:47 +0400
committernulltoken <emeric.fermas@gmail.com>2012-03-06 17:55:53 +0400
commit1d250dad563d40a71c8f119eb169f8cfc4f4becf (patch)
treeff1ecb7bdfe394035b7a591dde9907a6802ec3e9 /LibGit2Sharp
parent5e770b8517ad2e5bf06022837fe519f53b2e687b (diff)
Use FilePath and FilePathMarshaler in NativeMethods
Closes #74, #77
Diffstat (limited to 'LibGit2Sharp')
-rw-r--r--LibGit2Sharp/Configuration.cs4
-rw-r--r--LibGit2Sharp/Core/NativeMethods.cs31
-rw-r--r--LibGit2Sharp/Index.cs8
-rw-r--r--LibGit2Sharp/IndexEntry.cs6
-rw-r--r--LibGit2Sharp/Repository.cs16
-rw-r--r--LibGit2Sharp/RepositoryInformation.cs8
-rw-r--r--LibGit2Sharp/RepositoryStatus.cs8
-rw-r--r--LibGit2Sharp/Tree.cs11
8 files changed, 44 insertions, 48 deletions
diff --git a/LibGit2Sharp/Configuration.cs b/LibGit2Sharp/Configuration.cs
index fd155611..e9391355 100644
--- a/LibGit2Sharp/Configuration.cs
+++ b/LibGit2Sharp/Configuration.cs
@@ -10,8 +10,8 @@ namespace LibGit2Sharp
/// </summary>
public class Configuration : IDisposable
{
- private readonly string globalConfigPath;
- private readonly string systemConfigPath;
+ private readonly FilePath globalConfigPath;
+ private readonly FilePath systemConfigPath;
private readonly Repository repository;
diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs
index e0ebeb5d..7ed80c1c 100644
--- a/LibGit2Sharp/Core/NativeMethods.cs
+++ b/LibGit2Sharp/Core/NativeMethods.cs
@@ -139,7 +139,7 @@ namespace LibGit2Sharp.Core
[DllImport(libgit2)]
public static extern int git_config_open_ondisk(
out ConfigurationSafeHandle cfg,
- [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string path);
+ [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath path);
[DllImport(libgit2)]
public static extern int git_config_set_bool(
@@ -168,7 +168,7 @@ namespace LibGit2Sharp.Core
[DllImport(libgit2)]
public static extern int git_index_add(
IndexSafeHandle index,
- [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string path,
+ [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath path,
int stage = 0);
[DllImport(libgit2)]
@@ -182,7 +182,7 @@ namespace LibGit2Sharp.Core
[DllImport(libgit2)]
public static extern int git_index_find(
IndexSafeHandle index,
- [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string path);
+ [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath path);
[DllImport(libgit2)]
public static extern void git_index_free(IntPtr index);
@@ -316,9 +316,9 @@ namespace LibGit2Sharp.Core
public static extern int git_repository_discover(
byte[] repository_path, // NB: This is more properly a StringBuilder, but it's UTF8
int size,
- [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string start_path,
+ [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath start_path,
[MarshalAs(UnmanagedType.Bool)] bool across_fs,
- [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string ceiling_dirs);
+ [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath ceiling_dirs);
[DllImport(libgit2)]
public static extern void git_repository_free(IntPtr repository);
@@ -332,7 +332,7 @@ namespace LibGit2Sharp.Core
[DllImport(libgit2)]
public static extern int git_repository_init(
out RepositorySafeHandle repository,
- [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string path,
+ [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath path,
[MarshalAs(UnmanagedType.Bool)] bool isBare);
[DllImport(libgit2)]
@@ -344,15 +344,15 @@ namespace LibGit2Sharp.Core
[DllImport(libgit2)]
public static extern int git_repository_open(
out RepositorySafeHandle repository,
- [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string path);
+ [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath path);
[DllImport(libgit2)]
- [return : MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))]
- public static extern string git_repository_path(RepositorySafeHandle repository);
+ [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))]
+ public static extern FilePath git_repository_path(RepositorySafeHandle repository);
[DllImport(libgit2)]
- [return : MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))]
- public static extern string git_repository_workdir(RepositorySafeHandle repository);
+ [return : MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))]
+ public static extern FilePath git_repository_workdir(RepositorySafeHandle repository);
[DllImport(libgit2)]
public static extern void git_revwalk_free(IntPtr walker);
@@ -390,10 +390,10 @@ namespace LibGit2Sharp.Core
public static extern int git_status_file(
out FileStatus statusflags,
RepositorySafeHandle repo,
- [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string filepath);
+ [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath filepath);
internal delegate int status_callback(
- [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string statuspath,
+ [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath statuspath,
uint statusflags,
IntPtr payload);
@@ -460,7 +460,7 @@ namespace LibGit2Sharp.Core
[DllImport(libgit2)]
public static extern IntPtr git_tree_entry_byname(
IntPtr tree,
- [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string filename);
+ [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath filename);
[DllImport(libgit2)]
public static extern IntPtr git_tree_entry_id(IntPtr entry);
@@ -476,6 +476,7 @@ namespace LibGit2Sharp.Core
public static extern uint git_tree_entrycount(IntPtr tree);
[DllImport(libgit2)]
- public static extern int git_tree_get_subtree(out IntPtr tree, IntPtr root, string treeentry_path);
+ public static extern int git_tree_get_subtree(out IntPtr tree, IntPtr root,
+ [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath treeentry_path);
}
}
diff --git a/LibGit2Sharp/Index.cs b/LibGit2Sharp/Index.cs
index 16e9734c..41284cab 100644
--- a/LibGit2Sharp/Index.cs
+++ b/LibGit2Sharp/Index.cs
@@ -48,8 +48,6 @@ namespace LibGit2Sharp
{
get
{
- path = PosixPathHelper.ToPosix(path);
-
Ensure.ArgumentNotNullOrEmptyString(path, "path");
int res = NativeMethods.git_index_find(handle, path);
@@ -395,16 +393,12 @@ namespace LibGit2Sharp
private void AddToIndex(string relativePath)
{
- relativePath = PosixPathHelper.ToPosix(relativePath);
-
int res = NativeMethods.git_index_add(handle, relativePath);
Ensure.Success(res);
}
private void RemoveFromIndex(string relativePath)
{
- relativePath = PosixPathHelper.ToPosix(relativePath);
-
int res = NativeMethods.git_index_find(handle, relativePath);
Ensure.Success(res, true);
@@ -470,7 +464,7 @@ namespace LibGit2Sharp
FileStatus status;
- int res = NativeMethods.git_status_file(out status, repo.Handle, PosixPathHelper.ToPosix(relativePath));
+ int res = NativeMethods.git_status_file(out status, repo.Handle, relativePath);
if (res == (int)GitErrorCode.GIT_ENOTFOUND)
{
return FileStatus.Nonexistent;
diff --git a/LibGit2Sharp/IndexEntry.cs b/LibGit2Sharp/IndexEntry.cs
index 57d4a373..9126ed47 100644
--- a/LibGit2Sharp/IndexEntry.cs
+++ b/LibGit2Sharp/IndexEntry.cs
@@ -38,13 +38,13 @@ namespace LibGit2Sharp
internal static IndexEntry CreateFromPtr(Repository repo, IntPtr ptr)
{
var entry = (GitIndexEntry)Marshal.PtrToStructure(ptr, typeof(GitIndexEntry));
- var path = (string)marshaler.MarshalNativeToManaged(entry.Path);
+ FilePath path = (string)marshaler.MarshalNativeToManaged(entry.Path);
return new IndexEntry
{
- Path = PosixPathHelper.ToNative(path),
+ Path = path.Native,
Id = new ObjectId(entry.oid),
- state = () => repo.Index.RetrieveStatus(path)
+ state = () => repo.Index.RetrieveStatus(path.Native)
};
}
diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs
index d7189a15..2e793111 100644
--- a/LibGit2Sharp/Repository.cs
+++ b/LibGit2Sharp/Repository.cs
@@ -34,7 +34,7 @@ namespace LibGit2Sharp
{
Ensure.ArgumentNotNullOrEmptyString(path, "path");
- int res = NativeMethods.git_repository_open(out handle, PosixPathHelper.ToPosix(path));
+ int res = NativeMethods.git_repository_open(out handle, path);
Ensure.Success(res);
RegisterForCleanup(handle);
@@ -176,15 +176,13 @@ namespace LibGit2Sharp
Ensure.ArgumentNotNullOrEmptyString(path, "path");
RepositorySafeHandle repo;
- int res = NativeMethods.git_repository_init(out repo, PosixPathHelper.ToPosix(path), isBare);
+ int res = NativeMethods.git_repository_init(out repo, path, isBare);
Ensure.Success(res);
- string normalizedPath = NativeMethods.git_repository_path(repo);
+ FilePath repoPath = NativeMethods.git_repository_path(repo);
repo.SafeDispose();
- string nativePath = PosixPathHelper.ToNative(normalizedPath);
-
- return new Repository(nativePath);
+ return new Repository(repoPath.Native);
}
/// <summary>
@@ -285,7 +283,7 @@ namespace LibGit2Sharp
{
var buffer = new byte[NativeMethods.GIT_PATH_MAX];
- int result = NativeMethods.git_repository_discover(buffer, buffer.Length, PosixPathHelper.ToPosix(startingPath), false, null);
+ int result = NativeMethods.git_repository_discover(buffer, buffer.Length, startingPath, false, null);
if ((GitErrorCode)result == GitErrorCode.GIT_ENOTAREPO)
{
@@ -294,7 +292,9 @@ namespace LibGit2Sharp
Ensure.Success(result);
- return PosixPathHelper.ToNative(Utf8Marshaler.Utf8FromBuffer(buffer));
+ FilePath discoveredPath = Utf8Marshaler.Utf8FromBuffer(buffer);
+
+ return discoveredPath.Native;
}
/// <summary>
diff --git a/LibGit2Sharp/RepositoryInformation.cs b/LibGit2Sharp/RepositoryInformation.cs
index a001f9c0..a4d4fac6 100644
--- a/LibGit2Sharp/RepositoryInformation.cs
+++ b/LibGit2Sharp/RepositoryInformation.cs
@@ -15,11 +15,11 @@ namespace LibGit2Sharp
this.repo = repo;
IsBare = isBare;
- string posixPath = NativeMethods.git_repository_path(repo.Handle);
- string posixWorkingDirectoryPath = NativeMethods.git_repository_workdir(repo.Handle);
+ FilePath path = NativeMethods.git_repository_path(repo.Handle);
+ FilePath workingDirectoryPath = NativeMethods.git_repository_workdir(repo.Handle);
- Path = PosixPathHelper.ToNative(posixPath);
- WorkingDirectory = PosixPathHelper.ToNative(posixWorkingDirectoryPath);
+ Path = path.Native;
+ WorkingDirectory = workingDirectoryPath == null ? null : workingDirectoryPath.Native;
}
/// <summary>
diff --git a/LibGit2Sharp/RepositoryStatus.cs b/LibGit2Sharp/RepositoryStatus.cs
index 60806d6a..5b6964d3 100644
--- a/LibGit2Sharp/RepositoryStatus.cs
+++ b/LibGit2Sharp/RepositoryStatus.cs
@@ -43,12 +43,10 @@ namespace LibGit2Sharp
isDirty = statusEntries.Count != 0;
}
- private int StateChanged(string filePath, uint state, IntPtr payload)
+ private int StateChanged(FilePath filePath, uint state, IntPtr payload)
{
- filePath = PosixPathHelper.ToNative(filePath);
-
var gitStatus = (FileStatus)state;
- statusEntries.Add(new StatusEntry(filePath, gitStatus));
+ statusEntries.Add(new StatusEntry(filePath.Native, gitStatus));
foreach (KeyValuePair<FileStatus, Action<RepositoryStatus, string>> kvp in dispatcher)
{
@@ -57,7 +55,7 @@ namespace LibGit2Sharp
continue;
}
- kvp.Value(this, filePath);
+ kvp.Value(this, filePath.Native);
}
return 0;
diff --git a/LibGit2Sharp/Tree.cs b/LibGit2Sharp/Tree.cs
index 10d2694b..b6f5f2c5 100644
--- a/LibGit2Sharp/Tree.cs
+++ b/LibGit2Sharp/Tree.cs
@@ -30,12 +30,15 @@ namespace LibGit2Sharp
/// <returns><c>null</c> if nothing has been found, the <see cref = "TreeEntry" /> otherwise.</returns>
public TreeEntry this[string relativePath]
{
- get { return RetrieveFromPath(PosixPathHelper.ToPosix(relativePath)); }
+ get { return RetrieveFromPath(relativePath); }
}
- private TreeEntry RetrieveFromPath(string relativePath)
+ private TreeEntry RetrieveFromPath(FilePath relativePath)
{
- Ensure.ArgumentNotNullOrEmptyString(relativePath, "relativePath");
+ if (string.IsNullOrEmpty(relativePath.Posix))
+ {
+ return null;
+ }
using (var obj = new ObjectSafeWrapper(Id, repo))
{
@@ -50,7 +53,7 @@ namespace LibGit2Sharp
Ensure.Success(res);
- IntPtr e = NativeMethods.git_tree_entry_byname(objectPtr, relativePath.Split('/').Last());
+ IntPtr e = NativeMethods.git_tree_entry_byname(objectPtr, relativePath.Posix.Split('/').Last());
if (e == IntPtr.Zero)
{