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:
Diffstat (limited to 'LibGit2Sharp')
-rw-r--r--LibGit2Sharp/GitObject.cs4
-rw-r--r--LibGit2Sharp/IBelongToARepository.cs26
-rw-r--r--LibGit2Sharp/LibGit2Sharp.csproj1
-rw-r--r--LibGit2Sharp/Reference.cs4
-rw-r--r--LibGit2Sharp/ReferenceWrapper.cs4
-rw-r--r--LibGit2Sharp/Remote.cs4
-rw-r--r--LibGit2Sharp/Submodule.cs4
7 files changed, 42 insertions, 5 deletions
diff --git a/LibGit2Sharp/GitObject.cs b/LibGit2Sharp/GitObject.cs
index ad4614dc..5e11489a 100644
--- a/LibGit2Sharp/GitObject.cs
+++ b/LibGit2Sharp/GitObject.cs
@@ -11,7 +11,7 @@ namespace LibGit2Sharp
/// A GitObject
/// </summary>
[DebuggerDisplay("{DebuggerDisplay,nq}")]
- public abstract class GitObject : IEquatable<GitObject>
+ public abstract class GitObject : IEquatable<GitObject>, IBelongToARepository
{
internal static IDictionary<Type, ObjectType> TypeToKindMap =
new Dictionary<Type, ObjectType>
@@ -154,5 +154,7 @@ namespace LibGit2Sharp
{
get { return Id.ToString(7); }
}
+
+ IRepository IBelongToARepository.Repository { get { return repo; } }
}
}
diff --git a/LibGit2Sharp/IBelongToARepository.cs b/LibGit2Sharp/IBelongToARepository.cs
new file mode 100644
index 00000000..f0297c6c
--- /dev/null
+++ b/LibGit2Sharp/IBelongToARepository.cs
@@ -0,0 +1,26 @@
+namespace LibGit2Sharp
+{
+ /// <summary>
+ /// Can be used to reference the <see cref="IRepository" /> from which
+ /// an instance was created.
+ /// <para>
+ /// While convenient in some situations (e.g. Checkout branch bound to UI element),
+ /// it is important to ensure instances created from an <see cref="IRepository" />
+ /// are not used after it is disposed.
+ /// </para>
+ /// <para>
+ /// It's generally better to create <see cref="IRepository" /> and dependant instances
+ /// on demand, with a short lifespan.
+ /// </para>
+ /// </summary>
+ public interface IBelongToARepository
+ {
+ /// <summary>
+ /// The <see cref="IRepository" /> from which this instance was created.
+ /// <para>
+ /// The returned value should not be disposed.
+ /// </para>
+ /// </summary>
+ IRepository Repository { get; }
+ }
+}
diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj
index 67929273..ad733e41 100644
--- a/LibGit2Sharp/LibGit2Sharp.csproj
+++ b/LibGit2Sharp/LibGit2Sharp.csproj
@@ -84,6 +84,7 @@
<Compile Include="Core\Handles\IndexNameEntrySafeHandle.cs" />
<Compile Include="Core\Handles\IndexReucEntrySafeHandle.cs" />
<Compile Include="EntryExistsException.cs" />
+ <Compile Include="IBelongToARepository.cs" />
<Compile Include="IndexNameEntryCollection.cs" />
<Compile Include="ContentChangeStats.cs" />
<Compile Include="BuiltInFeatures.cs" />
diff --git a/LibGit2Sharp/Reference.cs b/LibGit2Sharp/Reference.cs
index 94ac2f31..8ab7d1b7 100644
--- a/LibGit2Sharp/Reference.cs
+++ b/LibGit2Sharp/Reference.cs
@@ -10,7 +10,7 @@ namespace LibGit2Sharp
/// A Reference to another git object
/// </summary>
[DebuggerDisplay("{DebuggerDisplay,nq}")]
- public abstract class Reference : IEquatable<Reference>
+ public abstract class Reference : IEquatable<Reference>, IBelongToARepository
{
private static readonly LambdaEqualityHelper<Reference> equalityHelper =
new LambdaEqualityHelper<Reference>(x => x.CanonicalName, x => x.TargetIdentifier);
@@ -209,5 +209,7 @@ namespace LibGit2Sharp
"{0} => \"{1}\"", CanonicalName, TargetIdentifier);
}
}
+
+ IRepository IBelongToARepository.Repository { get { return repo; } }
}
}
diff --git a/LibGit2Sharp/ReferenceWrapper.cs b/LibGit2Sharp/ReferenceWrapper.cs
index aaf56070..583c68d4 100644
--- a/LibGit2Sharp/ReferenceWrapper.cs
+++ b/LibGit2Sharp/ReferenceWrapper.cs
@@ -10,7 +10,7 @@ namespace LibGit2Sharp
/// </summary>
/// <typeparam name="TObject">The type of the referenced Git object.</typeparam>
[DebuggerDisplay("{DebuggerDisplay,nq}")]
- public abstract class ReferenceWrapper<TObject> : IEquatable<ReferenceWrapper<TObject>> where TObject : GitObject
+ public abstract class ReferenceWrapper<TObject> : IEquatable<ReferenceWrapper<TObject>>, IBelongToARepository where TObject : GitObject
{
/// <summary>
/// The repository.
@@ -160,5 +160,7 @@ namespace LibGit2Sharp
(TargetObject != null) ? TargetObject.Id.ToString(7) : "?");
}
}
+
+ IRepository IBelongToARepository.Repository { get { return repo; } }
}
}
diff --git a/LibGit2Sharp/Remote.cs b/LibGit2Sharp/Remote.cs
index e999d08d..dfff15fe 100644
--- a/LibGit2Sharp/Remote.cs
+++ b/LibGit2Sharp/Remote.cs
@@ -12,7 +12,7 @@ namespace LibGit2Sharp
/// A remote repository whose branches are tracked.
/// </summary>
[DebuggerDisplay("{DebuggerDisplay,nq}")]
- public class Remote : IEquatable<Remote>
+ public class Remote : IEquatable<Remote>, IBelongToARepository
{
private static readonly LambdaEqualityHelper<Remote> equalityHelper =
new LambdaEqualityHelper<Remote>(x => x.Name, x => x.Url);
@@ -174,5 +174,7 @@ namespace LibGit2Sharp
"{0} => {1}", Name, Url);
}
}
+
+ IRepository IBelongToARepository.Repository { get { return repository; } }
}
}
diff --git a/LibGit2Sharp/Submodule.cs b/LibGit2Sharp/Submodule.cs
index 3d0b3562..c15e224d 100644
--- a/LibGit2Sharp/Submodule.cs
+++ b/LibGit2Sharp/Submodule.cs
@@ -9,7 +9,7 @@ namespace LibGit2Sharp
/// A Submodule.
/// </summary>
[DebuggerDisplay("{DebuggerDisplay,nq}")]
- public class Submodule : IEquatable<Submodule>
+ public class Submodule : IEquatable<Submodule>, IBelongToARepository
{
private static readonly LambdaEqualityHelper<Submodule> equalityHelper =
new LambdaEqualityHelper<Submodule>(x => x.Name, x => x.HeadCommitId);
@@ -155,5 +155,7 @@ namespace LibGit2Sharp
"{0} => {1}", Name, Url);
}
}
+
+ IRepository IBelongToARepository.Repository { get { return repo; } }
}
}