10000 In memory fixes · kstrohminfor/libgit2sharp@ea0ed02 · GitHub
[go: up one dir, main page]

Skip to content

Commit ea0ed02

Browse files
committed
In memory fixes
1 parent efa481c commit ea0ed02

File tree

5 files changed

+38
-10
lines changed

5 files changed

+38
-10
lines changed

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,6 +1582,12 @@ internal static extern unsafe int git_repository_message(
15821582
internal static extern unsafe int git_repository_new(
15831583
out git_repository* repo);
15841584

1585+
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
1586+
internal static extern unsafe void git_repository_set_odb(git_repository* repo, git_odb* odb);
1587+
1588+
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
1589+
internal static extern unsafe int git_odb_new(out git_odb* odb);
1590+
15851591
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
15861592
internal static extern unsafe int git_repository_odb(out git_odb* odb, git_repository* repo);
15871593

LibGit2Sharp/Core/Proxy.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2573,6 +2573,20 @@ public static unsafe string git_repository_message(RepositoryHandle repo)
25732573
}
25742574
}
25752575

2576+
public static unsafe void git_repository_set_odb(RepositoryHandle repo, ObjectDatabaseHandle objectDatabase)
2577+
{
2578+
NativeMethods.git_repository_set_odb(repo, objectDatabase);
2579+
}
2580+
2581+
public static unsafe ObjectDatabaseHandle git_odb_new()
2582+
{
2583+
git_odb* handle;
2584+
var res = NativeMethods.git_odb_new(out handle);
2585+
Ensure.ZeroResult(res);
2586+
2587+
return new ObjectDatabaseHandle(handle, true);
2588+
}
2589+
25762590
public static unsafe ObjectDatabaseHandle git_repository_odb(RepositoryHandle repo)
25772591
{
25782592
git_odb* handle;

LibGit2Sharp/ObjectDatabase.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,20 @@ public class ObjectDatabase : IEnumerable<GitObject>
2525
protected ObjectDatabase()
2626
{ }
2727

28-
internal ObjectDatabase(Repository repo)
28+
internal ObjectDatabase(Repository repo, bool isInMemory)
2929
{
3030
this.repo = repo;
31-
handle = Proxy.git_repository_odb(repo.Handle);
31+
32+
if (isInMemory)
33+
{
34+
handle = Proxy.git_odb_new();
35+
36+
Proxy.git_repository_set_odb(repo.Handle, handle);
37+
}
38+
else
39+
{
40+
handle = Proxy.git_repository_odb(repo.Handle);
41+
}
3242

3343
repo.RegisterForCleanup(handle);
3444
}
@@ -1089,4 +1099,4 @@ public virtual MergeTreeResult RevertCommit(Commit revertCommit, Commit revertOn
10891099
}
10901100
}
10911101
}
1092-
}
1102+
}

LibGit2Sharp/RefdbBackend.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
using LibGit2Sharp.Core;
2-
using LibGit2Sharp.Core.Handles;
32
using System;
4-
using System.Collections;
53
using System.Collections.Generic;
64
using System.Globalization;
75
using System.Runtime.InteropServices;
8-
using System.Text;
96

107
namespace LibGit2Sharp
118
{

LibGit2Sharp/Repository.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ internal Repository(WorktreeHandle worktreeHandle)
125125
configurationGlobalFilePath,
126126
configurationXDGFilePath,
127127
configurationSystemFilePath)));
128-
odb = new Lazy<ObjectDatabase>(() => new ObjectDatabase(this));
128+
odb = new Lazy<ObjectDatabase>(() => new ObjectDatabase(this, true));
129129
diff = new Diff(this);
130130
notes = new NoteCollection(this);
131131
ignore = new Ignore(this);
@@ -164,7 +164,8 @@ private Repository(string path, RepositoryOptions options, RepositoryRequiredPar
164164
/* TODO: bug in libgit2, update when fixed by
165165
* https://github.com/libgit2/libgit2/pull/2970
166166
*/
167-
if (path == null)
167+
var isInMemory = path == null;
168+
if (isInMemory)
168169
{
169170
isBare = true;
170171
}
@@ -222,7 +223,7 @@ private Repository(string path, RepositoryOptions options, RepositoryRequiredPar
222223
configurationGlobalFilePath,
223224
configurationXDGFilePath,
224225
configurationSystemFilePath)));
225-
odb = new Lazy<ObjectDatabase>(() => new ObjectDatabase(this));
226+
odb = new Lazy<ObjectDatabase>(() => new ObjectDatabase(this, isInMemory));
226227
diff = new Diff(this);
227228
notes = new NoteCollection(this);
228229
ignore = new Ignore(this);
@@ -1797,4 +1798,4 @@ private string DebuggerDisplay
17971798
}
17981799
}
17991800
}
1800-
}
1801+
}

0 commit comments

Comments
 (0)
0