diff --git a/LibGit2Sharp.Tests/CheckoutFixture.cs b/LibGit2Sharp.Tests/CheckoutFixture.cs index 132cb68ec..80cb9727d 100644 --- a/LibGit2Sharp.Tests/CheckoutFixture.cs +++ b/LibGit2Sharp.Tests/CheckoutFixture.cs @@ -1029,23 +1029,6 @@ public void CanCheckoutPathFromCurrentBranch(string fileName) } } - [Fact] - public void CanCatchDeprecatedException() - { - bool caught = false; - - try - { - throw new CheckoutConflictException(); - } - catch (MergeConflictException) - { - caught = true; - } - - Assert.True(caught); - } - /// /// Helper method to populate a simple repository with /// a single file and two branches. diff --git a/LibGit2Sharp.Tests/RefSpecFixture.cs b/LibGit2Sharp.Tests/RefSpecFixture.cs index dc82a5fc3..094547160 100644 --- a/LibGit2Sharp.Tests/RefSpecFixture.cs +++ b/LibGit2Sharp.Tests/RefSpecFixture.cs @@ -190,5 +190,43 @@ public void SettingInvalidRefSpecsThrows(string refSpec) Assert.Equal(oldRefSpecs, newRemote.RefSpecs.Select(r => r.Specification).ToList()); } } + + [Theory] + [InlineData("refs/heads/master", true, false)] + [InlineData("refs/heads/some/master", true, false)] + [InlineData("refs/remotes/foo/master", false, true)] + [InlineData("refs/tags/foo", false, false)] + public void CanCheckForMatches(string reference, bool shouldMatchSource, bool shouldMatchDest) + { + var path = SandboxStandardTestRepo(); + using (var repo = InitIsolatedRepository(path)) + { + var remote = repo.Network.Remotes.Add("foo", "blahblah", "refs/heads/*:refs/remotes/foo/*"); + var refspec = remote.RefSpecs.Single(); + + Assert.Equal(shouldMatchSource, refspec.SourceMatches(reference)); + Assert.Equal(shouldMatchDest, refspec.DestinationMatches(reference)); + } + } + + [Theory] + [InlineData("refs/heads/master", "refs/remotes/foo/master")] + [InlineData("refs/heads/bar/master", "refs/remotes/foo/bar/master")] + [InlineData("refs/heads/master", "refs/remotes/foo/master")] + public void CanTransformRefspecs(string lhs, string rhs) + { + var path = SandboxStandardTestRepo(); + using (var repo = InitIsolatedRepository(path)) + { + var remote = repo.Network.Remotes.Add("foo", "blahblah", "refs/heads/*:refs/remotes/foo/*"); + var refspec = remote.RefSpecs.Single(); + + var actualTransformed = refspec.Transform(lhs); + var actualReverseTransformed = refspec.ReverseTransform(rhs); + + Assert.Equal(rhs, actualTransformed); + Assert.Equal(lhs, actualReverseTransformed); + } + } } } diff --git a/LibGit2Sharp/CheckoutConflictException.cs b/LibGit2Sharp/CheckoutConflictException.cs index 811e2183a..a06360afb 100644 --- a/LibGit2Sharp/CheckoutConflictException.cs +++ b/LibGit2Sharp/CheckoutConflictException.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.Serialization; using LibGit2Sharp.Core; namespace LibGit2Sharp @@ -9,7 +10,7 @@ namespace LibGit2Sharp /// in the working directory. /// [Serializable] - public class CheckoutConflictException : MergeConflictException + public class CheckoutConflictException : LibGit2SharpException { /// /// Initializes a new instance of the class. @@ -17,6 +18,41 @@ public class CheckoutConflictException : MergeConflictException public CheckoutConflictException() { } + /// + /// Initializes a new instance of the class with a specified error message. + /// + /// A message that describes the error. + public CheckoutConflictException(string message) + : base(message) + { } + + /// + /// Initializes a new instance of the class with a specified error message. + /// + /// A composite format string for use in . + /// An object array that contains zero or more objects to format. + public CheckoutConflictException(string format, params object[] args) + : base(format, args) + { } + + /// + /// Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. + /// + /// The error message that explains the reason for the exception. + /// The exception that is the cause of the current exception. If the parameter is not a null reference, the current exception is raised in a catch block that handles the inner exception. + public CheckoutConflictException(string message, Exception innerException) + : base(message, innerException) + { } + + /// + /// Initializes a new instance of the class with a serialized data. + /// + /// The that holds the serialized object data about the exception being thrown. + /// The that contains contextual information about the source or destination. + protected CheckoutConflictException(SerializationInfo info, StreamingContext context) + : base(info, context) + { } + internal CheckoutConflictException(string message, GitErrorCode code, GitErrorCategory category) : base(message, code, category) { } diff --git a/LibGit2Sharp/CommitFilter.cs b/LibGit2Sharp/CommitFilter.cs index fe0bfd127..56b23389c 100644 --- a/LibGit2Sharp/CommitFilter.cs +++ b/LibGit2Sharp/CommitFilter.cs @@ -28,22 +28,6 @@ public CommitFilter() /// public CommitSortStrategies SortBy { get; set; } - /// - /// A pointer to a commit object or a list of pointers to consider as starting points. - /// - /// Can be either a containing the sha or reference canonical name to use, - /// a , a , a , a , - /// a , an or even a mixed collection of all of the above. - /// By default, the will be used as boundary. - /// - /// - [Obsolete("This property will be removed in the next release. Please use IncludeReachableFrom instead.")] - public object Since - { - get { return IncludeReachableFrom; } - set { IncludeReachableFrom = value; } - } - /// /// A pointer to a commit object or a list of pointers to consider as starting points. /// @@ -60,21 +44,6 @@ internal IList SinceList get { return ToList(IncludeReachableFrom); } } - /// - /// A pointer to a commit object or a list of pointers which will be excluded (along with ancestors) from the enumeration. - /// - /// Can be either a containing the sha or reference canonical name to use, - /// a , a , a , a , - /// a , an or even a mixed collection of all of the above. - /// - /// - [Obsolete("This property will be removed in the next release. Please use ExcludeReachableFrom instead.")] - public object Until - { - get { return ExcludeReachableFrom; } - set { ExcludeReachableFrom = value; } - } - /// /// A pointer to a commit object or a list of pointers which will be excluded (along with ancestors) from the enumeration. /// diff --git a/LibGit2Sharp/CommitLog.cs b/LibGit2Sharp/CommitLog.cs index 7568181d3..f21af0da7 100644 --- a/LibGit2Sharp/CommitLog.cs +++ b/LibGit2Sharp/CommitLog.cs @@ -105,30 +105,6 @@ public IEnumerable QueryBy(string path, FollowFilter filter) return new FileHistory(repo, path, new CommitFilter { SortBy = filter.SortBy }); } - /// - /// Find the best possible merge base given two s. - /// - /// The first . - /// The second . - /// The merge base or null if none found. - [Obsolete("This method will be removed in the next release. Please use ObjectDatabase.FindMergeBase() instead.")] - public Commit FindMergeBase(Commit first, Commit second) - { - return repo.ObjectDatabase.FindMergeBase(first, second); - } - - /// - /// Find the best possible merge base given two or more according to the . - /// - /// The s for which to find the merge base. - /// The strategy to leverage in order to find the merge base. - /// The merge base or null if none found. - [Obsolete("This method will be removed in the next release. Please use ObjectDatabase.FindMergeBase() instead.")] - public Commit FindMergeBase(IEnumerable commits, MergeBaseFindingStrategy strategy) - { - return repo.ObjectDatabase.FindMergeBase(commits, strategy); - } - private class CommitEnumerator : IEnumerator { private readonly Repository repo; diff --git a/LibGit2Sharp/CompareOptions.cs b/LibGit2Sharp/CompareOptions.cs index 6b3acdfe6..fbd147c79 100644 --- a/LibGit2Sharp/CompareOptions.cs +++ b/LibGit2Sharp/CompareOptions.cs @@ -39,12 +39,6 @@ public CompareOptions() /// public bool IncludeUnmodified { get; set; } - /// - /// Use the "patience diff" algorithm. - /// - [Obsolete("This property will be removed in the next release. Please use Algorithm instead.")] - public bool UsePatienceAlgorithm { get; set; } - /// /// Algorithm to be used when performing a Diff. /// By default, will be used. diff --git a/LibGit2Sharp/Configuration.cs b/LibGit2Sharp/Configuration.cs index 4dbab2412..5a2f2be18 100644 --- a/LibGit2Sharp/Configuration.cs +++ b/LibGit2Sharp/Configuration.cs @@ -195,36 +195,6 @@ public static Configuration BuildFrom( return new Configuration(null, repositoryConfigurationFileLocation, globalConfigurationFileLocation, xdgConfigurationFileLocation, systemConfigurationFileLocation); } - /// - /// Access configuration values without a repository. Generally you want to access configuration via an instance of instead. - /// - /// Path to a Global configuration file. If null, the default path for a global configuration file will be probed. - [Obsolete("This method will be removed in the next release. Please use Configuration.BuildFrom(string, string) instead.")] - public Configuration(string globalConfigurationFileLocation) - : this(null, null, globalConfigurationFileLocation, null, null) - { } - - /// - /// Access configuration values without a repository. Generally you want to access configuration via an instance of instead. - /// - /// Path to a Global configuration file. If null, the default path for a global configuration file will be probed. - /// Path to a XDG configuration file. If null, the default path for a XDG configuration file will be probed. - [Obsolete("This method will be removed in the next release. Please use Configuration.BuildFrom(string, string, string) instead.")] - public Configuration(string globalConfigurationFileLocation, string xdgConfigurationFileLocation) - : this(null, null, globalConfigurationFileLocation, xdgConfigurationFileLocation, null) - { } - - /// - /// Access configuration values without a repository. Generally you want to access configuration via an instance of instead. - /// - /// Path to a Global configuration file. If null, the default path for a global configuration file will be probed. - /// Path to a XDG configuration file. If null, the default path for a XDG configuration file will be probed. - /// Path to a System configuration file. If null, the default path for a system configuration file will be probed. - [Obsolete("This method will be removed in the next release. Please use Configuration.BuildFrom(string, string, string, string) instead.")] - public Configuration(string globalConfigurationFileLocation, string xdgConfigurationFileLocation, string systemConfigurationFileLocation) - : this(null, null, globalConfigurationFileLocation, xdgConfigurationFileLocation, systemConfigurationFileLocation) - { } - /// /// Determines which configuration file has been found. /// diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs index 8978abda4..94cbe7c27 100644 --- a/LibGit2Sharp/Core/NativeMethods.cs +++ b/LibGit2Sharp/Core/NativeMethods.cs @@ -1112,6 +1112,12 @@ internal static extern IntPtr git_reflog_entry_committer( [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(LaxUtf8NoCleanupMarshaler))] internal static extern string git_reflog_entry_message(SafeHandle entry); + [DllImport(libgit2)] + internal static extern int git_refspec_transform( + GitBuf buf, + GitRefSpecHandle refspec, + [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string name); + [DllImport(libgit2)] internal static extern int git_refspec_rtransform( GitBuf buf, @@ -1139,6 +1145,16 @@ internal static extern string git_refspec_src( [DllImport(libgit2)] internal static extern bool git_refspec_force(GitRefSpecHandle refSpec); + [DllImport(libgit2)] + internal static extern bool git_refspec_src_matches( + GitRefSpecHandle resfpec, + [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string reference); + + [DllImport(libgit2)] + internal static extern bool git_refspec_dst_matches( + GitRefSpecHandle resfpec, + [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string reference); + [DllImport(libgit2)] internal static extern int git_remote_autotag(RemoteSafeHandle remote); diff --git a/LibGit2Sharp/Core/Proxy.cs b/LibGit2Sharp/Core/Proxy.cs index 35371d886..b19fa6499 100644 --- a/LibGit2Sharp/Core/Proxy.cs +++ b/LibGit2Sharp/Core/Proxy.cs @@ -2017,6 +2017,17 @@ public static string git_reflog_entry_message(SafeHandle entry) #region git_refspec + public static string git_refspec_transform(GitRefSpecHandle refSpecPtr, string name) + { + using (var buf = new GitBuf()) + { + int res = NativeMethods.git_refspec_transform(buf, refSpecPtr, name); + Ensure.ZeroResult(res); + + return LaxUtf8Marshaler.FromNative(buf.ptr) ?? string.Empty; + } + } + public static string git_refspec_rtransform(GitRefSpecHandle refSpecPtr, string name) { using (var buf = new GitBuf()) @@ -2053,6 +2064,16 @@ public static bool git_refspec_force(GitRefSpecHandle refSpec) return NativeMethods.git_refspec_force(refSpec); } + public static bool git_refspec_src_matches(GitRefSpecHandle refspec, string reference) + { + return NativeMethods.git_refspec_src_matches(refspec, reference); + } + + public static bool git_refspec_dst_matches(GitRefSpecHandle refspec, string reference) + { + return NativeMethods.git_refspec_dst_matches(refspec, reference); + } + #endregion #region git_remote_ diff --git a/LibGit2Sharp/FileStatus.cs b/LibGit2Sharp/FileStatus.cs index b07323449..fbd32affd 100644 --- a/LibGit2Sharp/FileStatus.cs +++ b/LibGit2Sharp/FileStatus.cs @@ -18,34 +18,16 @@ public enum FileStatus /// Unaltered = 0, /* GIT_STATUS_CURRENT */ - /// - /// New file has been added to the Index. It's unknown from the Head. - /// - [Obsolete("This enum member will be removed in the next release. Please use NewInIndex instead.")] - Added = (1 << 0), /* GIT_STATUS_INDEX_NEW */ - /// /// New file has been added to the Index. It's unknown from the Head. /// NewInIndex = (1 << 0), /* GIT_STATUS_INDEX_NEW */ - /// - /// New version of a file has been added to the Index. A previous version exists in the Head. - /// - [Obsolete("This enum member will be removed in the next release. Please use ModifiedInIndex instead.")] - Staged = (1 << 1), /* GIT_STATUS_INDEX_MODIFIED */ - /// /// New version of a file has been added to the Index. A previous version exists in the Head. /// ModifiedInIndex = (1 << 1), /* GIT_STATUS_INDEX_MODIFIED */ - /// - /// The deletion of a file has been promoted from the working directory to the Index. A previous version exists in the Head. - /// - [Obsolete("This enum member will be removed in the next release. Please use DeletedFromIndex instead.")] - Removed = (1 << 2), /* GIT_STATUS_INDEX_DELETED */ - /// /// The deletion of a file has been promoted from the working directory to the Index. A previous version exists in the Head. /// @@ -56,56 +38,26 @@ public enum FileStatus /// RenamedInIndex = (1 << 3), /* GIT_STATUS_INDEX_RENAMED */ - /// - /// A change in type for a file has been promoted from the working directory to the Index. A previous version exists in the Head. - /// - [Obsolete("This enum member will be removed in the next release. Please use TypeChangeInIndex instead.")] - StagedTypeChange = (1 << 4), /* GIT_STATUS_INDEX_TYPECHANGE */ - /// /// A change in type for a file has been promoted from the working directory to the Index. A previous version exists in the Head. /// TypeChangeInIndex = (1 << 4), /* GIT_STATUS_INDEX_TYPECHANGE */ - /// - /// New file in the working directory, unknown from the Index and the Head. - /// - [Obsolete("This enum member will be removed in the next release. Please use NewInWorkdir instead.")] - Untracked = (1 << 7), /* GIT_STATUS_WT_NEW */ - /// /// New file in the working directory, unknown from the Index and the Head. /// NewInWorkdir = (1 << 7), /* GIT_STATUS_WT_NEW */ - /// - /// The file has been updated in the working directory. A previous version exists in the Index. - /// - [Obsolete("This enum member will be removed in the next release. Please use ModifiedInWorkdir instead.")] - Modified = (1 << 8), /* GIT_STATUS_WT_MODIFIED */ - /// /// The file has been updated in the working directory. A previous version exists in the Index. /// ModifiedInWorkdir = (1 << 8), /* GIT_STATUS_WT_MODIFIED */ - /// - /// The file has been deleted from the working directory. A previous version exists in the Index. - /// - [Obsolete("This enum member will be removed in the next release. Please use DeletedFromWorkdir instead.")] - Missing = (1 << 9), /* GIT_STATUS_WT_DELETED */ - /// /// The file has been deleted from the working directory. A previous version exists in the Index. /// DeletedFromWorkdir = (1 << 9), /* GIT_STATUS_WT_DELETED */ - /// - /// The file type has been changed in the working directory. A previous version exists in the Index. - /// - [Obsolete("This enum member will be removed in the next release. Please use TypeChangeInWorkdir instead.")] - TypeChanged = (1 << 10), /* GIT_STATUS_WT_TYPECHANGE */ - /// /// The file type has been changed in the working directory. A previous version exists in the Index. /// diff --git a/LibGit2Sharp/IQueryableCommitLog.cs b/LibGit2Sharp/IQueryableCommitLog.cs index 457ad2fa6..4a57dd3b3 100644 --- a/LibGit2Sharp/IQueryableCommitLog.cs +++ b/LibGit2Sharp/IQueryableCommitLog.cs @@ -29,23 +29,5 @@ public interface IQueryableCommitLog : ICommitLog /// The options used to control which commits will be returned. /// A list of file history entries, ready to be enumerated. IEnumerable QueryBy(string path, FollowFilter filter); - - /// - /// Find the best possible merge base given two s. - /// - /// The first . - /// The second . - /// The merge base or null if none found. - [Obsolete("This method will be removed in the next release. Please use ObjectDatabase.FindMergeBase() instead.")] - Commit FindMergeBase(Commit first, Commit second); - - /// - /// Find the best possible merge base given two or more according to the . - /// - /// The s for which to find the merge base. - /// The strategy to leverage in order to find the merge base. - /// The merge base or null if none found. - [Obsolete("This method will be removed in the next release. Please use ObjectDatabase.FindMergeBase() instead.")] - Commit FindMergeBase(IEnumerable commits, MergeBaseFindingStrategy strategy); } } diff --git a/LibGit2Sharp/IRepository.cs b/LibGit2Sharp/IRepository.cs index 317a0e76b..1bd921a51 100644 --- a/LibGit2Sharp/IRepository.cs +++ b/LibGit2Sharp/IRepository.cs @@ -174,18 +174,6 @@ public interface IRepository : IDisposable /// Collection of parameters controlling checkout behavior. void Reset(ResetMode resetMode, Commit commit, CheckoutOptions options); - /// - /// Replaces entries in the with entries from the specified commit. - /// - /// The target commit object. - /// The list of paths (either files or directories) that should be considered. - /// - /// If set, the passed will be treated as explicit paths. - /// Use these options to determine how unmatched explicit paths should be handled. - /// - [Obsolete("This method will be removed in the next release. Please use Index.Replace() instead.")] - void Reset(Commit commit, IEnumerable paths, ExplicitPathsOptions explicitPathsOptions); - /// /// Clean the working tree by removing files that are not under version control. /// diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj index 72afcc658..c9d8b2aac 100644 --- a/LibGit2Sharp/LibGit2Sharp.csproj +++ b/LibGit2Sharp/LibGit2Sharp.csproj @@ -23,7 +23,6 @@ TRACE;DEBUG;NET40 prompt 4 - false true AllRules.ruleset bin\Debug\LibGit2Sharp.xml @@ -36,7 +35,6 @@ prompt 4 true - false bin\Release\LibGit2Sharp.xml @@ -255,7 +253,6 @@ - diff --git a/LibGit2Sharp/MergeConflictException.cs b/LibGit2Sharp/MergeConflictException.cs deleted file mode 100644 index d95124dc0..000000000 --- a/LibGit2Sharp/MergeConflictException.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System; -using System.Runtime.Serialization; -using LibGit2Sharp.Core; - -namespace LibGit2Sharp -{ - /// - /// The exception that is thrown when a checkout cannot be performed - /// because of a conflicting change staged in the index, or unstaged - /// in the working directory. - /// - [Serializable] - [Obsolete("This type will be removed in the next release. Please use CheckoutConflictException instead.")] - public class MergeConflictException : LibGit2SharpException - { - /// - /// Initializes a new instance of the class. - /// - public MergeConflictException() - { } - - /// - /// Initializes a new instance of the class with a specified error message. - /// - /// A message that describes the error. - public MergeConflictException(string message) - : base(message) - { } - - /// - /// Initializes a new instance of the class with a specified error message. - /// - /// A composite format string for use in . - /// An object array that contains zero or more objects to format. - public MergeConflictException(string format, params object[] args) - : base(format, args) - { } - - /// - /// Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - /// - /// The error message that explains the reason for the exception. - /// The exception that is the cause of the current exception. If the parameter is not a null reference, the current exception is raised in a catch block that handles the inner exception. - public MergeConflictException(string message, Exception innerException) - : base(message, innerException) - { } - - /// - /// Initializes a new instance of the class with a serialized data. - /// - /// The that holds the serialized object data about the exception being thrown. - /// The that contains contextual information about the source or destination. - protected MergeConflictException(SerializationInfo info, StreamingContext context) - : base(info, context) - { } - - internal MergeConflictException(string message, GitErrorCode code, GitErrorCategory category) - : base(message, code, category) - { } - } -} diff --git a/LibGit2Sharp/MergeOptions.cs b/LibGit2Sharp/MergeOptions.cs index c36e6ddca..b57d955e4 100644 --- a/LibGit2Sharp/MergeOptions.cs +++ b/LibGit2Sharp/MergeOptions.cs @@ -37,12 +37,6 @@ public enum FastForwardStrategy /// Default = 0, - /// - /// Do not fast-forward. Always creates a merge commit. - /// - [Obsolete("This enum member will be removed in the next release. Please use NoFastForward instead.")] - NoFastFoward = 1, /* GIT_MERGE_NO_FASTFORWARD */ - /// /// Do not fast-forward. Always creates a merge commit. /// diff --git a/LibGit2Sharp/NoteCollection.cs b/LibGit2Sharp/NoteCollection.cs index 7c8c8ecc8..c9f083835 100644 --- a/LibGit2Sharp/NoteCollection.cs +++ b/LibGit2Sharp/NoteCollection.cs @@ -163,22 +163,6 @@ internal static string UnCanonicalizeName(string name) return name.Substring(Reference.NotePrefix.Length); } - /// - /// Creates or updates a on the specified object, and for the given namespace. - /// Both the Author and Committer will be guessed from the Git configuration. An exception will be raised if no configuration is reachable. - /// - /// The target , for which the note will be created. - /// The note message. - /// The namespace on which the note will be created. It can be either a canonical namespace or an abbreviated namespace ('refs/notes/myNamespace' or just 'myNamespace'). - /// The note which was just saved. - [Obsolete("This method will be removed in the next release. Please use Add(ObjectId, string, Signature, Signature, string) instead.")] - public virtual Note Add(ObjectId targetId, string message, string @namespace) - { - Signature author = repo.Config.BuildSignatureOrThrow(DateTimeOffset.Now); - - return Add(targetId, message, author, author, @namespace); - } - /// /// Creates or updates a on the specified object, and for the given namespace. /// @@ -205,20 +189,6 @@ public virtual Note Add(ObjectId targetId, string message, Signature author, Sig return this[canonicalNamespace, targetId]; } - /// - /// Deletes the note on the specified object, and for the given namespace. - /// Both the Author and Committer will be guessed from the Git configuration. An exception will be raised if no configuration is reachable. - /// - /// The target , for which the note will be created. - /// The namespace on which the note will be removed. It can be either a canonical namespace or an abbreviated namespace ('refs/notes/myNamespace' or just 'myNamespace'). - [Obsolete("This method will be removed in the next release. Please use Remove(ObjectId, Signature, Signature, string) instead.")] - public virtual void Remove(ObjectId targetId, string @namespace) - { - Signature author = repo.Config.BuildSignatureOrThrow(DateTimeOffset.Now); - - Remove(targetId, author, author, @namespace); - } - /// /// Deletes the note on the specified object, and for the given namespace. /// diff --git a/LibGit2Sharp/Properties/AssemblyInfo.cs b/LibGit2Sharp/Properties/AssemblyInfo.cs index b848dc65a..34c8f06bd 100644 --- a/LibGit2Sharp/Properties/AssemblyInfo.cs +++ b/LibGit2Sharp/Properties/AssemblyInfo.cs @@ -42,6 +42,6 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.22.0")] -[assembly: AssemblyFileVersion("0.22.0")] -[assembly: AssemblyInformationalVersion("0.22.0-dev00000000000000")] +[assembly: AssemblyVersion("0.23.0")] +[assembly: AssemblyFileVersion("0.23.0")] +[assembly: AssemblyInformationalVersion("0.23.0-dev00000000000000")] diff --git a/LibGit2Sharp/RefSpec.cs b/LibGit2Sharp/RefSpec.cs index 9c811c5f9..aeeabb75e 100644 --- a/LibGit2Sharp/RefSpec.cs +++ b/LibGit2Sharp/RefSpec.cs @@ -1,4 +1,5 @@ -using System.Diagnostics; +using System; +using System.Diagnostics; using System.Globalization; using LibGit2Sharp.Core; using LibGit2Sharp.Core.Handles; @@ -11,17 +12,13 @@ namespace LibGit2Sharp [DebuggerDisplay("{DebuggerDisplay,nq}")] public class RefSpec { - private RefSpec(string refSpec, RefSpecDirection direction, string source, string destination, bool forceUpdate) - { - Ensure.ArgumentNotNullOrEmptyString(refSpec, "refSpec"); - Ensure.ArgumentNotNull(source, "source"); - Ensure.ArgumentNotNull(destination, "destination"); + readonly Remote remote; + readonly GitRefSpecHandle handle; - Specification = refSpec; - Direction = direction; - Source = source; - Destination = destination; - ForceUpdate = forceUpdate; + internal RefSpec(Remote remote, GitRefSpecHandle handle) + { + this.remote = remote; + this.handle = handle; } /// @@ -30,38 +27,100 @@ private RefSpec(string refSpec, RefSpecDirection direction, string source, strin protected RefSpec() { } - internal static RefSpec BuildFromPtr(GitRefSpecHandle handle) - { - Ensure.ArgumentNotNull(handle, "handle"); - - return new RefSpec(Proxy.git_refspec_string(handle), Proxy.git_refspec_direction(handle), - Proxy.git_refspec_src(handle), Proxy.git_refspec_dst(handle), Proxy.git_refspec_force(handle)); - } - /// /// Gets the pattern describing the mapping between remote and local references /// - public virtual string Specification { get; private set; } + public virtual string Specification + { + get + { + return Proxy.git_refspec_string(this.handle); + } + } /// /// Indicates whether this is intended to be used during a Push or Fetch operation /// - public virtual RefSpecDirection Direction { get; private set; } + public virtual RefSpecDirection Direction + { + get + { + return Proxy.git_refspec_direction(this.handle); + } + } /// /// The source reference specifier /// - public virtual string Source { get; private set; } + public virtual string Source + { + get + { + return Proxy.git_refspec_src(this.handle); + } + } /// /// The target reference specifier /// - public virtual string Destination { get; private set; } + public virtual string Destination + { + get + { + return Proxy.git_refspec_dst(this.handle); + } + } /// /// Indicates whether the destination will be force-updated if fast-forwarding is not possible /// - public virtual bool ForceUpdate { get; private set; } + public virtual bool ForceUpdate + { + get + { + return Proxy.git_refspec_force(this.handle); + } + } + + /// + /// Check whether the given reference matches the source (lhs) part of + /// this refspec. + /// + /// The reference name to check + public virtual bool SourceMatches(string reference) + { + return Proxy.git_refspec_src_matches(handle, reference); + } + + /// + /// Check whether the given reference matches the target (rhs) part of + /// this refspec. + /// + /// The reference name to check + public virtual bool DestinationMatches(string reference) + { + return Proxy.git_refspec_dst_matches(handle, reference); + } + + /// + /// Perform the transformation described by this refspec on the given + /// reference name (from source to destination). + /// + /// The reference name to transform + public virtual string Transform(string reference) + { + return Proxy.git_refspec_transform(handle, reference); + } + + /// + /// Perform the reverse of the transformation described by this refspec + /// on the given reference name (from destination to source). + /// + /// The reference name to transform + public virtual string ReverseTransform(string reference) + { + return Proxy.git_refspec_rtransform(handle, reference); + } private string DebuggerDisplay { diff --git a/LibGit2Sharp/RefSpecCollection.cs b/LibGit2Sharp/RefSpecCollection.cs index 163281a12..46b1c4360 100644 --- a/LibGit2Sharp/RefSpecCollection.cs +++ b/LibGit2Sharp/RefSpecCollection.cs @@ -1,4 +1,5 @@ -using System.Collections; +using System; +using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; @@ -14,7 +15,9 @@ namespace LibGit2Sharp [DebuggerDisplay("{DebuggerDisplay,nq}")] public class RefSpecCollection : IEnumerable { - readonly IList refspecs; + readonly Remote remote; + readonly RemoteSafeHandle handle; + readonly Lazy> refspecs; /// /// Needed for mocking purposes. @@ -22,28 +25,27 @@ public class RefSpecCollection : IEnumerable protected RefSpecCollection() { } - internal RefSpecCollection(RemoteSafeHandle handle) + internal RefSpecCollection(Remote remote, RemoteSafeHandle handle) { Ensure.ArgumentNotNull(handle, "handle"); - refspecs = RetrieveRefSpecs(handle); + this.remote = remote; + this.handle = handle; + + refspecs = new Lazy>(() => RetrieveRefSpecs(remote, handle)); } - static IList RetrieveRefSpecs(RemoteSafeHandle remoteHandle) + static IList RetrieveRefSpecs(Remote remote, RemoteSafeHandle remoteHandle) { int count = Proxy.git_remote_refspec_count(remoteHandle); List refSpecs = new List(); for (int i = 0; i < count; i++) { - using (GitRefSpecHandle handle = Proxy.git_remote_get_refspec(remoteHandle, i)) - { - refSpecs.Add(RefSpec.BuildFromPtr(handle)); - } + refSpecs.Add(new RefSpec(remote, Proxy.git_remote_get_refspec(remoteHandle, i))); } return refSpecs; - } /// @@ -52,7 +54,7 @@ static IList RetrieveRefSpecs(RemoteSafeHandle remoteHandle) /// An object that can be used to iterate through the collection. public virtual IEnumerator GetEnumerator() { - return refspecs.GetEnumerator(); + return refspecs.Value.GetEnumerator(); } /// diff --git a/LibGit2Sharp/ReferenceWrapper.cs b/LibGit2Sharp/ReferenceWrapper.cs index 471dc1ede..9b5f151d3 100644 --- a/LibGit2Sharp/ReferenceWrapper.cs +++ b/LibGit2Sharp/ReferenceWrapper.cs @@ -59,15 +59,6 @@ public virtual string FriendlyName get { return Shorten(); } } - /// - /// Gets the name of this reference. - /// - [Obsolete("This property will be removed in the next release. Please use FriendlyName instead.")] - public virtual string Name - { - get { return FriendlyName; } - } - /// /// Returns the , a representation of the current reference. /// diff --git a/LibGit2Sharp/ReflogEntry.cs b/LibGit2Sharp/ReflogEntry.cs index f783b11cf..38387e1d7 100644 --- a/LibGit2Sharp/ReflogEntry.cs +++ b/LibGit2Sharp/ReflogEntry.cs @@ -57,15 +57,6 @@ public virtual Signature Committer get { return _committer; } } - /// - /// of the committer of this reference update - /// - [Obsolete("This property will be removed in the next release. Please use Committer instead.")] - public virtual Signature Commiter - { - get { return Committer; } - } - /// /// the message assiocated to this reference update /// diff --git a/LibGit2Sharp/Remote.cs b/LibGit2Sharp/Remote.cs index 137208198..f92b4aa10 100644 --- a/LibGit2Sharp/Remote.cs +++ b/LibGit2Sharp/Remote.cs @@ -12,7 +12,7 @@ namespace LibGit2Sharp /// A remote repository whose branches are tracked. /// [DebuggerDisplay("{DebuggerDisplay,nq}")] - public class Remote : IEquatable, IBelongToARepository + public class Remote : IEquatable, IBelongToARepository, IDisposable { private static readonly LambdaEqualityHelper equalityHelper = new LambdaEqualityHelper(x => x.Name, x => x.Url, x => x.PushUrl); @@ -22,29 +22,58 @@ public class Remote : IEquatable, IBelongToARepository private readonly RefSpecCollection refSpecs; private string pushUrl; + readonly RemoteSafeHandle handle; + /// /// Needed for mocking purposes. /// protected Remote() { } - private Remote(RemoteSafeHandle handle, Repository repository) + internal Remote(RemoteSafeHandle handle, Repository repository) { this.repository = repository; + this.handle = handle; Name = Proxy.git_remote_name(handle); Url = Proxy.git_remote_url(handle); PushUrl = Proxy.git_remote_pushurl(handle); TagFetchMode = Proxy.git_remote_autotag(handle); - refSpecs = new RefSpecCollection(handle); + refSpecs = new RefSpecCollection(this, handle); + } + + ~Remote() + { + Dispose(false); + } + + #region IDisposable + + bool disposedValue = false; // To detect redundant calls + + /// + /// Release the unmanaged remote object + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); } - internal static Remote BuildFromPtr(RemoteSafeHandle handle, Repository repo) + void Dispose(bool disposing) { - var remote = new Remote(handle, repo); + if (!disposedValue) + { + if (handle != null) + { + handle.Dispose(); + } - return remote; + disposedValue = true; + } } + #endregion + /// /// Gets the alias of this remote repository. /// diff --git a/LibGit2Sharp/RemoteCollection.cs b/LibGit2Sharp/RemoteCollection.cs index 6ab1a3faf..86bb41331 100644 --- a/LibGit2Sharp/RemoteCollection.cs +++ b/LibGit2Sharp/RemoteCollection.cs @@ -43,10 +43,8 @@ internal Remote RemoteForName(string name, bool shouldThrowIfNotFound = true) { Ensure.ArgumentNotNull(name, "name"); - using (RemoteSafeHandle handle = Proxy.git_remote_lookup(repository.Handle, name, shouldThrowIfNotFound)) - { - return handle == null ? null : Remote.BuildFromPtr(handle, this.repository); - } + RemoteSafeHandle handle = Proxy.git_remote_lookup(repository.Handle, name, shouldThrowIfNotFound); + return handle == null ? null : new Remote(handle, this.repository); } /// @@ -102,10 +100,8 @@ public virtual Remote Add(string name, string url) Ensure.ArgumentNotNull(name, "name"); Ensure.ArgumentNotNull(url, "url"); - using (RemoteSafeHandle handle = Proxy.git_remote_create(repository.Handle, name, url)) - { - return Remote.BuildFromPtr(handle, this.repository); - } + RemoteSafeHandle handle = Proxy.git_remote_create(repository.Handle, name, url); + return new Remote(handle, this.repository); } /// @@ -121,10 +117,8 @@ public virtual Remote Add(string name, string url, string fetchRefSpec) Ensure.ArgumentNotNull(url, "url"); Ensure.ArgumentNotNull(fetchRefSpec, "fetchRefSpec"); - using (RemoteSafeHandle handle = Proxy.git_remote_create_with_fetchspec(repository.Handle, name, url, fetchRefSpec)) - { - return Remote.BuildFromPtr(handle, this.repository); - } + RemoteSafeHandle handle = Proxy.git_remote_create_with_fetchspec(repository.Handle, name, url, fetchRefSpec); + return new Remote(handle, this.repository); } /// diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs index bf96c206d..bfb551f9f 100644 --- a/LibGit2Sharp/Repository.cs +++ b/LibGit2Sharp/Repository.cs @@ -1030,21 +1030,6 @@ public void CheckoutPaths(string committishOrBranchSpec, IEnumerable pat CheckoutTree(commit.Tree, listOfPaths, checkoutOptions ?? new CheckoutOptions()); } - /// - /// Replaces entries in the with entries from the specified commit. - /// - /// The target commit object. - /// The list of paths (either files or directories) that should be considered. - /// - /// If set, the passed will be treated as explicit paths. - /// Use these options to determine how unmatched explicit paths should be handled. - /// - [Obsolete("This method will be removed in the next release. Please use Index.Replace() instead.")] - public void Reset(Commit commit, IEnumerable paths, ExplicitPathsOptions explicitPathsOptions) - { - Index.Replace(commit, paths, explicitPathsOptions); - } - /// /// Stores the content of the as a new into the repository. /// The tip of the will be used as the parent of this new Commit. diff --git a/LibGit2Sharp/RepositoryExtensions.cs b/LibGit2Sharp/RepositoryExtensions.cs index d3754caa3..447470bac 100644 --- a/LibGit2Sharp/RepositoryExtensions.cs +++ b/LibGit2Sharp/RepositoryExtensions.cs @@ -178,31 +178,6 @@ public static void Reset(this IRepository repository, ResetMode resetMode, strin repository.Reset(resetMode, commit); } - /// - /// Replaces entries in the with entries from the specified commit. - /// - /// The being worked with. - /// A revparse spec for the target commit object. - /// The list of paths (either files or directories) that should be considered. - /// - /// If set, the passed will be treated as explicit paths. - /// Use these options to determine how unmatched explicit paths should be handled. - /// - [Obsolete("This method will be removed in the next release. Please use Index.Replace() instead.")] - public static void Reset(this IRepository repository, string committish = "HEAD", IEnumerable paths = null, ExplicitPathsOptions explicitPathsOptions = null) - { - if (repository.Info.IsBare) - { - throw new BareRepositoryException("Reset is not allowed in a bare repository"); - } - - Ensure.ArgumentNotNullOrEmptyString(committish, "committish"); - - Commit commit = LookUpCommit(repository, committish); - - repository.Index.Replace(commit, paths, explicitPathsOptions); - } - private static Commit LookUpCommit(IRepository repository, string committish) { GitObject obj = repository.Lookup(committish); @@ -210,74 +185,6 @@ private static Commit LookUpCommit(IRepository repository, string committish) return obj.DereferenceToCommit(true); } - /// - /// Stores the content of the as a new into the repository. - /// The tip of the will be used as the parent of this new Commit. - /// Once the commit is created, the will move forward to point at it. - /// Both the Author and Committer will be guessed from the Git configuration. An exception will be raised if no configuration is reachable. - /// - /// The being worked with. - /// The description of why a change was made to the repository. - /// The generated . - [Obsolete("This method will be removed in the next release. Please use Commit(string, Signature, Signature) instead.")] - public static Commit Commit(this IRepository repository, string message) - { - return repository.Commit(message, (CommitOptions)null); - } - - /// - /// Stores the content of the as a new into the repository. - /// The tip of the will be used as the parent of this new Commit. - /// Once the commit is created, the will move forward to point at it. - /// Both the Author and Committer will be guessed from the Git configuration. An exception will be raised if no configuration is reachable. - /// - /// The being worked with. - /// The description of why a change was made to the repository. - /// The that specify the commit behavior. - /// The generated . - [Obsolete("This method will be removed in the next release. Please use Commit(string, Signature, Signature, CommitOptions) instead.")] - public static Commit Commit(this IRepository repository, string message, CommitOptions options) - { - Signature author = repository.Config.BuildSignatureOrThrow(DateTimeOffset.Now); - - return repository.Commit(message, author, options); - } - - /// - /// Stores the content of the as a new into the repository. - /// The tip of the will be used as the parent of this new Commit. - /// Once the commit is created, the will move forward to point at it. - /// The Committer will be guessed from the Git configuration. An exception will be raised if no configuration is reachable. - /// - /// The being worked with. - /// The of who made the change. - /// The description of why a change was made to the repository. - /// The generated . - [Obsolete("This method will be removed in the next release. Please use Commit(string, Signature, Signature) instead.")] - public static Commit Commit(this IRepository repository, string message, Signature author) - { - return repository.Commit(message, author, (CommitOptions)null); - } - - /// - /// Stores the content of the as a new into the repository. - /// The tip of the will be used as the parent of this new Commit. - /// Once the commit is created, the will move forward to point at it. - /// The Committer will be guessed from the Git configuration. An exception will be raised if no configuration is reachable. - /// - /// The being worked with. - /// The of who made the change. - /// The description of why a change was made to the repository. - /// The that specify the commit behavior. - /// The generated . - [Obsolete("This method will be removed in the next release. Please use Commit(string, Signature, Signature, CommitOptions) instead.")] - public static Commit Commit(this IRepository repository, string message, Signature author, CommitOptions options) - { - Signature committer = repository.Config.BuildSignatureOrThrow(DateTimeOffset.Now); - - return repository.Commit(message, author, committer, options); - } - /// /// Stores the content of the as a new into the repository. /// The tip of the will be used as the parent of this new Commit. @@ -597,29 +504,6 @@ public static void Reset(this IRepository repository, ResetMode resetMode, Commi repository.Reset(resetMode, commit); } - /// - /// Replaces entries in the with entries from the specified commit. - /// - /// The being worked with. - /// The target commit object. - /// The list of paths (either files or directories) that should be considered. - [Obsolete("This method will be removed in the next release. Please use Index.Replace() instead.")] - public static void Reset(this IRepository repository, Commit commit, IEnumerable paths) - { - repository.Index.Replace(commit, paths, null); - } - - /// - /// Replaces entries in the with entries from the specified commit. - /// - /// The being worked with. - /// The target commit object. - [Obsolete("This method will be removed in the next release. Please use Index.Replace() instead.")] - public static void Reset(this IRepository repository, Commit commit) - { - repository.Index.Replace(commit, null, null); - } - /// /// Find where each line of a file originated. /// diff --git a/appveyor.yml b/appveyor.yml index c7a8f9fd2..dd4c82f1e 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -16,7 +16,7 @@ environment: secure: nuzUT+HecXGIi3KaPd/1hgFEZJan/j6+oNbPV75JKjk= coverity_email: secure: eGVilNg1Yuq+Xj+SW8r3WCtjnzhoDV0sNJkma4NRq7A= - version : 0.22.0 + version : 0.23.0 matrix: - xunit_runner: xunit.console.x86.exe Arch: 32