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:
authornulltoken <emeric.fermas@gmail.com>2012-05-11 18:00:28 +0400
committernulltoken <emeric.fermas@gmail.com>2012-05-15 21:31:59 +0400
commit5c5b9c7e8937b9bcf80927dedd95f35abae2b903 (patch)
tree755107bc5f2aa83d0dfefc06ea486c509c0dd05f
parentaaa8c7ee5f7bb554b6817a3cde571b9607969fa1 (diff)
Delegate the creation and the moving of branches to libgit2 native methods
-rw-r--r--LibGit2Sharp/BranchCollection.cs21
-rw-r--r--LibGit2Sharp/Core/GitBranchType.cs11
-rw-r--r--LibGit2Sharp/Core/NativeMethods.cs15
-rw-r--r--LibGit2Sharp/LibGit2Sharp.csproj1
4 files changed, 41 insertions, 7 deletions
diff --git a/LibGit2Sharp/BranchCollection.cs b/LibGit2Sharp/BranchCollection.cs
index 22954329..6ffc0707 100644
--- a/LibGit2Sharp/BranchCollection.cs
+++ b/LibGit2Sharp/BranchCollection.cs
@@ -78,12 +78,20 @@ namespace LibGit2Sharp
/// </summary>
/// <param name = "name">The name of the branch.</param>
/// <param name = "shaOrReferenceName">The target which can be sha or a canonical reference name.</param>
+ /// <param name = "allowOverwrite">True to allow silent overwriting a potentially existing branch, false otherwise.</param>
/// <returns></returns>
- public Branch Create(string name, string shaOrReferenceName)
+ public Branch Create(string name, string shaOrReferenceName, bool allowOverwrite = false)
{
+ Ensure.ArgumentNotNullOrEmptyString(name, "name");
+
ObjectId commitId = repo.LookupCommit(shaOrReferenceName).Id;
- repo.Refs.Create(NormalizeToCanonicalName(name), commitId.Sha);
+ using (var osw = new ObjectSafeWrapper(commitId, repo))
+ {
+ GitOid oid;
+ Ensure.Success(NativeMethods.git_branch_create(out oid, repo.Handle, name, osw.ObjectPtr, allowOverwrite));
+ }
+
return this[name];
}
@@ -107,7 +115,7 @@ namespace LibGit2Sharp
}
///<summary>
- /// Rename an existing branch with a new name.
+ /// Rename an existing local branch with a new name.
///</summary>
///<param name = "currentName">The current branch name.</param>
///<param name = "newName">The new name of the existing branch should bear.</param>
@@ -115,13 +123,12 @@ namespace LibGit2Sharp
///<returns></returns>
public Branch Move(string currentName, string newName, bool allowOverwrite = false)
{
- Ensure.ArgumentNotNullOrEmptyString(currentName, "name");
+ Ensure.ArgumentNotNullOrEmptyString(currentName, "currentName");
Ensure.ArgumentNotNullOrEmptyString(newName, "name");
- Reference reference = repo.Refs.Move(NormalizeToCanonicalName(currentName), NormalizeToCanonicalName(newName),
- allowOverwrite);
+ Ensure.Success(NativeMethods.git_branch_move(repo.Handle, currentName, newName, allowOverwrite));
- return this[reference.CanonicalName];
+ return this[newName];
}
private static bool LooksLikeABranchName(string referenceName)
diff --git a/LibGit2Sharp/Core/GitBranchType.cs b/LibGit2Sharp/Core/GitBranchType.cs
new file mode 100644
index 00000000..6304715f
--- /dev/null
+++ b/LibGit2Sharp/Core/GitBranchType.cs
@@ -0,0 +1,11 @@
+using System;
+
+namespace LibGit2Sharp.Core
+{
+ [Flags]
+ internal enum GitBranchType
+ {
+ GIT_BRANCH_LOCAL = 1,
+ GIT_BRANCH_REMOTE = 2,
+ }
+}
diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs
index 92b92edf..24cebf42 100644
--- a/LibGit2Sharp/Core/NativeMethods.cs
+++ b/LibGit2Sharp/Core/NativeMethods.cs
@@ -81,6 +81,21 @@ namespace LibGit2Sharp.Core
public static extern int git_blob_rawsize(GitObjectSafeHandle blob);
[DllImport(libgit2)]
+ public static extern int git_branch_create(
+ out GitOid oid_out,
+ RepositorySafeHandle repo,
+ [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string branch_name,
+ GitObjectSafeHandle target,
+ [MarshalAs(UnmanagedType.Bool)] bool force);
+
+ [DllImport(libgit2)]
+ public static extern int git_branch_move(
+ RepositorySafeHandle repo,
+ [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string old_branch_name,
+ [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string new_branch_name,
+ [MarshalAs(UnmanagedType.Bool)] bool force);
+
+ [DllImport(libgit2)]
public static extern IntPtr git_commit_author(GitObjectSafeHandle commit);
[DllImport(libgit2)]
diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj
index d90faeb9..3372f8e6 100644
--- a/LibGit2Sharp/LibGit2Sharp.csproj
+++ b/LibGit2Sharp/LibGit2Sharp.csproj
@@ -60,6 +60,7 @@
<Compile Include="Core\DisposableEnumerable.cs" />
<Compile Include="Core\EnumExtensions.cs" />
<Compile Include="ChangeKind.cs" />
+ <Compile Include="Core\GitBranchType.cs" />
<Compile Include="Core\GitDiff.cs" />
<Compile Include="Core\GitError.cs" />
<Compile Include="Core\GitObjectExtensions.cs" />