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:
authorEdward Thomson <ethomson@microsoft.com>2014-06-03 19:53:43 +0400
committernulltoken <emeric.fermas@gmail.com>2014-06-14 21:16:06 +0400
commit86e561dfaccad9c0efdd1bef71edcaa662466e1e (patch)
tree9e36a7cc686ee0383a24d4d8e2d10fad7e916bde /LibGit2Sharp
parent5151c4311d6c12d242424b24ff3988f2a5398035 (diff)
Introduce Index.Conflicts.ResolvedConflicts
Diffstat (limited to 'LibGit2Sharp')
-rw-r--r--LibGit2Sharp/ConflictCollection.cs14
-rw-r--r--LibGit2Sharp/Core/GitIndexReucEntry.cs17
-rw-r--r--LibGit2Sharp/Core/Handles/IndexReucEntrySafeHandle.cs12
-rw-r--r--LibGit2Sharp/Core/NativeMethods.cs12
-rw-r--r--LibGit2Sharp/Core/Proxy.cs20
-rw-r--r--LibGit2Sharp/IndexReucEntry.cs152
-rw-r--r--LibGit2Sharp/IndexReucEntryCollection.cs89
-rw-r--r--LibGit2Sharp/LibGit2Sharp.csproj6
8 files changed, 320 insertions, 2 deletions
diff --git a/LibGit2Sharp/ConflictCollection.cs b/LibGit2Sharp/ConflictCollection.cs
index ff54ee2e..c86d158b 100644
--- a/LibGit2Sharp/ConflictCollection.cs
+++ b/LibGit2Sharp/ConflictCollection.cs
@@ -40,7 +40,19 @@ namespace LibGit2Sharp
}
}
- #region IEnumerable<IndexEntry> Members
+ /// <summary>
+ /// Get the <see cref="IndexReucEntryCollection"/> that contains
+ /// the list of conflicts that have been resolved.
+ /// </summary>
+ public virtual IndexReucEntryCollection ResolvedConflicts
+ {
+ get
+ {
+ return new IndexReucEntryCollection(repo);
+ }
+ }
+
+ #region IEnumerable<Conflict> Members
private List<Conflict> AllConflicts()
{
diff --git a/LibGit2Sharp/Core/GitIndexReucEntry.cs b/LibGit2Sharp/Core/GitIndexReucEntry.cs
new file mode 100644
index 00000000..dfd684ed
--- /dev/null
+++ b/LibGit2Sharp/Core/GitIndexReucEntry.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Runtime.InteropServices;
+
+namespace LibGit2Sharp.Core
+{
+ [StructLayout(LayoutKind.Sequential)]
+ internal class GitIndexReucEntry
+ {
+ public uint AncestorMode;
+ public uint OurMode;
+ public uint TheirMode;
+ public GitOid AncestorId;
+ public GitOid OurId;
+ public GitOid TheirId;
+ public IntPtr Path;
+ }
+}
diff --git a/LibGit2Sharp/Core/Handles/IndexReucEntrySafeHandle.cs b/LibGit2Sharp/Core/Handles/IndexReucEntrySafeHandle.cs
new file mode 100644
index 00000000..ec006b39
--- /dev/null
+++ b/LibGit2Sharp/Core/Handles/IndexReucEntrySafeHandle.cs
@@ -0,0 +1,12 @@
+using System.Runtime.InteropServices;
+
+namespace LibGit2Sharp.Core.Handles
+{
+ internal class IndexReucEntrySafeHandle : NotOwnedSafeHandleBase
+ {
+ public GitIndexReucEntry MarshalAsGitIndexReucEntry()
+ {
+ return handle.MarshalAs<GitIndexReucEntry>();
+ }
+ }
+}
diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs
index 9b06c60f..e065284c 100644
--- a/LibGit2Sharp/Core/NativeMethods.cs
+++ b/LibGit2Sharp/Core/NativeMethods.cs
@@ -585,6 +585,18 @@ namespace LibGit2Sharp.Core
IndexSafeHandle index,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictFilePathMarshaler))] FilePath path);
+
+ [DllImport(libgit2)]
+ internal static extern uint git_index_reuc_entrycount(IndexSafeHandle handle);
+
+ [DllImport(libgit2)]
+ internal static extern IndexReucEntrySafeHandle git_index_reuc_get_byindex(IndexSafeHandle handle, UIntPtr n);
+
+ [DllImport(libgit2)]
+ internal static extern IndexReucEntrySafeHandle git_index_reuc_get_bypath(
+ IndexSafeHandle handle,
+ [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictFilePathMarshaler))] FilePath path);
+
[DllImport(libgit2)]
internal static extern int git_index_write(IndexSafeHandle index);
diff --git a/LibGit2Sharp/Core/Proxy.cs b/LibGit2Sharp/Core/Proxy.cs
index 096b0282..7d67aae3 100644
--- a/LibGit2Sharp/Core/Proxy.cs
+++ b/LibGit2Sharp/Core/Proxy.cs
@@ -928,6 +928,26 @@ namespace LibGit2Sharp.Core
}
}
+ public static int git_index_reuc_entrycount(IndexSafeHandle index)
+ {
+ uint count = NativeMethods.git_index_reuc_entrycount(index);
+ if ((long)count > int.MaxValue)
+ {
+ throw new LibGit2SharpException("Index REUC entry count exceeds size of int");
+ }
+ return (int)count;
+ }
+
+ public static IndexReucEntrySafeHandle git_index_reuc_get_byindex(IndexSafeHandle index, UIntPtr n)
+ {
+ return NativeMethods.git_index_reuc_get_byindex(index, n);
+ }
+
+ public static IndexReucEntrySafeHandle git_index_reuc_get_bypath(IndexSafeHandle index, string path)
+ {
+ return NativeMethods.git_index_reuc_get_bypath(index, path);
+ }
+
public static void git_index_write(IndexSafeHandle index)
{
using (ThreadAffinity())
diff --git a/LibGit2Sharp/IndexReucEntry.cs b/LibGit2Sharp/IndexReucEntry.cs
new file mode 100644
index 00000000..ffba71e0
--- /dev/null
+++ b/LibGit2Sharp/IndexReucEntry.cs
@@ -0,0 +1,152 @@
+using System;
+using System.Diagnostics;
+using System.Globalization;
+using LibGit2Sharp.Core;
+using LibGit2Sharp.Core.Handles;
+
+namespace LibGit2Sharp
+{
+ /// <summary>
+ /// A reference to a resolved <see cref="Conflict"/>,
+ /// known by the <see cref="Index"/>.
+ /// </summary>
+ [DebuggerDisplay("{DebuggerDisplay,nq}")]
+ public class IndexReucEntry : IEquatable<IndexReucEntry>
+ {
+ private static readonly LambdaEqualityHelper<IndexReucEntry> equalityHelper =
+ new LambdaEqualityHelper<IndexReucEntry>(x => x.Path,
+ x => x.AncestorId, x => x.AncestorMode,
+ x => x.OurId, x => x.OurMode,
+ x => x.TheirId, x => x.TheirMode);
+
+ /// <summary>
+ /// Needed for mocking purposes.
+ /// </summary>
+ protected IndexReucEntry()
+ { }
+
+ internal static IndexReucEntry BuildFromPtr(IndexReucEntrySafeHandle handle)
+ {
+ if (handle == null || handle.IsZero)
+ {
+ return null;
+ }
+
+ GitIndexReucEntry entry = handle.MarshalAsGitIndexReucEntry();
+
+ FilePath path = LaxFilePathMarshaler.FromNative(entry.Path);
+
+ return new IndexReucEntry
+ {
+ Path = path.Native,
+ AncestorId = entry.AncestorId,
+ AncestorMode = (Mode)entry.AncestorMode,
+ OurId = entry.OurId,
+ OurMode = (Mode)entry.OurMode,
+ TheirId = entry.TheirId,
+ TheirMode = (Mode)entry.TheirMode,
+ };
+ }
+
+ /// <summary>
+ /// Gets the path of this conflict.
+ /// </summary>
+ public virtual string Path { get; private set; }
+
+ /// <summary>
+ /// Gets the <see cref="ObjectId"/> that was the ancestor of this
+ /// conflict.
+ /// </summary>
+ public virtual ObjectId AncestorId { get; private set; }
+
+ /// <summary>
+ /// Gets the <see cref="Mode"/> of the file that was the ancestor of
+ /// conflict.
+ /// </summary>
+ public virtual Mode AncestorMode { get; private set; }
+
+ /// <summary>
+ /// Gets the <see cref="ObjectId"/> that was "our" side of this
+ /// conflict.
+ /// </summary>
+ public virtual ObjectId OurId { get; private set; }
+
+ /// <summary>
+ /// Gets the <see cref="Mode"/> of the file that was "our" side of
+ /// the conflict.
+ /// </summary>
+ public virtual Mode OurMode { get; private set; }
+
+ /// <summary>
+ /// Gets the <see cref="ObjectId"/> that was "their" side of this
+ /// conflict.
+ /// </summary>
+ public virtual ObjectId TheirId { get; private set; }
+
+ /// <summary>
+ /// Gets the <see cref="Mode"/> of the file that was "their" side of
+ /// the conflict.
+ /// </summary>
+ public virtual Mode TheirMode { get; private set; }
+
+ /// <summary>
+ /// Determines whether the specified <see cref="Object"/> is equal to the current <see cref="IndexReucEntry"/>.
+ /// </summary>
+ /// <param name="obj">The <see cref="Object"/> to compare with the current <see cref="IndexReucEntry"/>.</param>
+ /// <returns>True if the specified <see cref="Object"/> is equal to the current <see cref="IndexReucEntry"/>; otherwise, false.</returns>
+ public override bool Equals(object obj)
+ {
+ return Equals(obj as IndexReucEntry);
+ }
+
+ /// <summary>
+ /// Determines whether the specified <see cref="IndexReucEntry"/> is equal to the current <see cref="IndexReucEntry"/>.
+ /// </summary>
+ /// <param name="other">The <see cref="IndexReucEntry"/> to compare with the current <see cref="IndexReucEntry"/>.</param>
+ /// <returns>True if the specified <see cref="IndexReucEntry"/> is equal to the current <see cref="IndexReucEntry"/>; otherwise, false.</returns>
+ public bool Equals(IndexReucEntry other)
+ {
+ return equalityHelper.Equals(this, other);
+ }
+
+ /// <summary>
+ /// Returns the hash code for this instance.
+ /// </summary>
+ /// <returns>A 32-bit signed integer hash code.</returns>
+ public override int GetHashCode()
+ {
+ return equalityHelper.GetHashCode(this);
+ }
+
+ /// <summary>
+ /// Tests if two <see cref="IndexReucEntry"/> are equal.
+ /// </summary>
+ /// <param name="left">First <see cref="IndexReucEntry"/> to compare.</param>
+ /// <param name="right">Second <see cref="IndexReucEntry"/> to compare.</param>
+ /// <returns>True if the two objects are equal; false otherwise.</returns>
+ public static bool operator ==(IndexReucEntry left, IndexReucEntry right)
+ {
+ return Equals(left, right);
+ }
+
+ /// <summary>
+ /// Tests if two <see cref="IndexReucEntry"/> are different.
+ /// </summary>
+ /// <param name="left">First <see cref="IndexReucEntry"/> to compare.</param>
+ /// <param name="right">Second <see cref="IndexReucEntry"/> to compare.</param>
+ /// <returns>True if the two objects are different; false otherwise.</returns>
+ public static bool operator !=(IndexReucEntry left, IndexReucEntry right)
+ {
+ return !Equals(left, right);
+ }
+
+ private string DebuggerDisplay
+ {
+ get
+ {
+ return string.Format(CultureInfo.InvariantCulture,
+ "{0}: {1} {2} {3}", Path, AncestorId, OurId, TheirId);
+ }
+ }
+ }
+}
diff --git a/LibGit2Sharp/IndexReucEntryCollection.cs b/LibGit2Sharp/IndexReucEntryCollection.cs
new file mode 100644
index 00000000..7a81e3b4
--- /dev/null
+++ b/LibGit2Sharp/IndexReucEntryCollection.cs
@@ -0,0 +1,89 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Globalization;
+using LibGit2Sharp.Core;
+using LibGit2Sharp.Core.Handles;
+
+namespace LibGit2Sharp
+{
+ /// <summary>
+ /// The collection of <see cref="LibGit2Sharp.IndexReucEntry"/>s in a
+ /// <see cref="LibGit2Sharp.Repository"/> index that reflect the
+ /// resolved conflicts.
+ /// </summary>
+ public class IndexReucEntryCollection : IEnumerable<IndexReucEntry>
+ {
+ private readonly Repository repo;
+
+ /// <summary>
+ /// Needed for mocking purposes.
+ /// </summary>
+ protected IndexReucEntryCollection()
+ { }
+
+ internal IndexReucEntryCollection(Repository repo)
+ {
+ this.repo = repo;
+ }
+
+ /// <summary>
+ /// Gets the <see cref="IndexReucEntry"/> with the specified relative path.
+ /// </summary>
+ public virtual IndexReucEntry this[string path]
+ {
+ get
+ {
+ Ensure.ArgumentNotNullOrEmptyString(path, "path");
+
+ IndexReucEntrySafeHandle entryHandle = Proxy.git_index_reuc_get_bypath(repo.Index.Handle, path);
+ return IndexReucEntry.BuildFromPtr(entryHandle);
+ }
+ }
+
+ private IndexReucEntry this[int index]
+ {
+ get
+ {
+ IndexReucEntrySafeHandle entryHandle = Proxy.git_index_reuc_get_byindex(repo.Index.Handle, (UIntPtr)index);
+ return IndexReucEntry.BuildFromPtr(entryHandle);
+ }
+ }
+
+ #region IEnumerable<IndexReucEntry> Members
+
+ private List<IndexReucEntry> AllIndexReucs()
+ {
+ var list = new List<IndexReucEntry>();
+
+ int count = Proxy.git_index_reuc_entrycount(repo.Index.Handle);
+
+ for (int i = 0; i < count; i++)
+ {
+ list.Add(this[i]);
+ }
+
+ return list;
+ }
+
+ /// <summary>
+ /// Returns an enumerator that iterates through the collection.
+ /// </summary>
+ /// <returns>An <see cref="IEnumerator{T}"/> object that can be used to iterate through the collection.</returns>
+ public virtual IEnumerator<IndexReucEntry> GetEnumerator()
+ {
+ return AllIndexReucs().GetEnumerator();
+ }
+
+ /// <summary>
+ /// Returns an enumerator that iterates through the collection.
+ /// </summary>
+ /// <returns>An <see cref="IEnumerator"/> object that can be used to iterate through the collection.</returns>
+ IEnumerator IEnumerable.GetEnumerator()
+ {
+ return GetEnumerator();
+ }
+
+ #endregion
+ }
+}
diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj
index 869f5d02..c022c3b0 100644
--- a/LibGit2Sharp/LibGit2Sharp.csproj
+++ b/LibGit2Sharp/LibGit2Sharp.csproj
@@ -80,6 +80,8 @@
<Compile Include="CommitOptions.cs" />
<Compile Include="CommitSortStrategies.cs" />
<Compile Include="CompareOptions.cs" />
+ <Compile Include="Core\GitIndexReucEntry.cs" />
+ <Compile Include="Core\Handles\IndexReucEntrySafeHandle.cs" />
<Compile Include="ContentChangeStats.cs" />
<Compile Include="BuiltInFeatures.cs" />
<Compile Include="Core\GitCheckoutOptsWrapper.cs" />
@@ -93,6 +95,8 @@
<Compile Include="EmptyCommitException.cs" />
<Compile Include="FetchOptions.cs" />
<Compile Include="GlobalSettings.cs" />
+ <Compile Include="IndexReucEntry.cs" />
+ <Compile Include="IndexReucEntryCollection.cs" />
<Compile Include="MergeOptions.cs" />
<Compile Include="MergeResult.cs" />
<Compile Include="PatchEntryChanges.cs" />
@@ -343,4 +347,4 @@
</CreateItem>
<Copy SourceFiles="@(NativeBinaries)" DestinationFiles="@(NativeBinaries->'$(OutputPath)NativeBinaries\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
</Target>
-</Project> \ No newline at end of file
+</Project>