-
Notifications
You must be signed in to change notification settings - Fork 922
Added FindMergeBases on the ObjectDatabase class, equivalent to git merge-base --all.
#1149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ref: refs/heads/a |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| [core] | ||
| repositoryformatversion = 0 | ||
| filemode = false | ||
| bare = false | ||
| logallrefupdates = true | ||
| symlinks = false | ||
| ignorecase = true | ||
| hideDotFiles = dotGitOnly |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| x��K | ||
| �@@]�)rK�c�] �b&�Z�R#��W�n�Ń'��z1!�lQ� �Q��X� i$ն�0�ʔ���E'�B��^26Q�TU�g������z��<l�8��Nj�K'��V�������"��"�1#:���ӺCkڠt�4��,G8 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 152325a8a96b610627aaae41a00391c3644079e4 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| c9a20513b0648832b41b0f875ab16c92e4b7dae7 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| a69878c70d9cce9a1fbec1712d1fcd4f609e689b |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| using System; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| namespace LibGit2Sharp.Core | ||
| { | ||
| [StructLayout(LayoutKind.Sequential)] | ||
| internal struct GitOidArray | ||
| { | ||
| /// <summary> | ||
| /// A pointer to an array of ids. | ||
| /// </summary> | ||
| public IntPtr Ids; | ||
|
|
||
| /// <summary> | ||
| /// The number of ids in the array. | ||
| /// </summary> | ||
| public UIntPtr Length; | ||
|
|
||
| /// <summary> | ||
| /// Resets the GitOidArray to default values. | ||
| /// </summary> | ||
| public void Reset() | ||
| { | ||
| Ids = IntPtr.Zero; | ||
| Length = UIntPtr.Zero; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| using System; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| namespace LibGit2Sharp.Core | ||
| { | ||
| /// <summary> | ||
| /// A git_oidarray where the id array and ids themselves were allocated | ||
| /// with libgit2's allocator. Only libgit2 can free this git_oidarray. | ||
| /// </summary> | ||
| [StructLayout(LayoutKind.Sequential)] | ||
| internal class GitOidArrayNative : IDisposable | ||
| { | ||
| public GitOidArray Array; | ||
|
|
||
| /// <summary> | ||
| /// Reads each GitOid from the array. | ||
| /// </summary> | ||
| public GitOid[] ReadOids() | ||
| { | ||
| var count = checked((int)Array.Length.ToUInt32()); | ||
|
|
||
| GitOid[] toReturn = new GitOid[count]; | ||
|
|
||
| for (int i = 0; i < count; i++) | ||
| { | ||
| toReturn[i] = (Array.Ids + i * Marshal.SizeOf(typeof(GitOid))).MarshalAs<GitOid>(); | ||
| } | ||
|
|
||
| return toReturn; | ||
| } | ||
|
|
||
| public void Dispose() | ||
| { | ||
| if (Array.Ids != IntPtr.Zero) | ||
| { | ||
| NativeMethods.git_oidarray_free(ref Array); | ||
| } | ||
|
|
||
| // Now that we've freed the memory, zero out the structure. | ||
| Array.Reset(); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1126,6 +1126,29 @@ public static ObjectId git_merge_base_many(RepositorySafeHandle repo, GitOid[] c | |
| return ret; | ||
| } | ||
|
|
||
| public static ObjectId[] git_merge_bases_many(RepositorySafeHandle repo, GitOid[] commitIds) | ||
| { | ||
| var array = new GitOidArrayNative(); | ||
|
|
||
| try | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about switch to a more plain
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was following the example of various methods already in For example: https://github.com/libgit2/libgit2sharp/blob/vNext/LibGit2Sharp/Core/Proxy.cs#L2028 Now, I don't disagree with your recommendation, but I would suggest that this pull request should strive to match the style of the surrounding code, which it has done. If the surrounding code gets cleaned up before this pull request is merged in, I'd be happy to update it. If instead this code review gets pulled in first, I would be happy to submit another that cleans everything up.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Let's do this then. Thanks for the proposal! |
||
| { | ||
| int res = NativeMethods.git_merge_bases_many(out array.Array, repo, commitIds.Length, commitIds); | ||
|
|
||
| if (res == (int)GitErrorCode.NotFound) | ||
| { | ||
| return new ObjectId[0]; | ||
| } | ||
|
|
||
| Ensure.ZeroResult(res); | ||
|
|
||
| return Array.ConvertAll(array.ReadOids(), id => (ObjectId)id); | ||
| } | ||
| finally | ||
| { | ||
| array.Dispose(); | ||
| } | ||
| } | ||
|
|
||
| public static ObjectId git_merge_base_octopus(RepositorySafeHandle repo, GitOid[] commitIds) | ||
| { | ||
| GitOid ret; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please revert this? ^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made it align better; was it intentionally misaligned?
Or would you just rather not have that change in this pull request?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it was 😉
We tend to prefer beautification changes to live in their own commits. If you're ok with extracting it in a different commit, it'd be glorious.