Skip to content
This repository was archived by the owner on Feb 3, 2023. It is now read-only.

Commit dbea75e

Browse files
committed
updated to pass repository working directory
1 parent aa3cc65 commit dbea75e

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,11 @@ internal static extern int git_repository_state(
12611261
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(LaxFilePathNoCleanupMarshaler))]
12621262
internal static extern FilePath git_repository_workdir(RepositorySafeHandle repository);
12631263

1264+
[DllImport(libgit2)]
1265+
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(LaxFilePathNoCleanupMarshaler))]
1266+
internal static extern FilePath git_repository_workdir(IntPtr repository);
1267+
1268+
12641269
[DllImport(libgit2)]
12651270
internal static extern int git_reset(
12661271
RepositorySafeHandle repo,

LibGit2Sharp/Core/Proxy.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2488,6 +2488,11 @@ public static FilePath git_repository_workdir(RepositorySafeHandle repo)
24882488
return NativeMethods.git_repository_workdir(repo);
24892489
}
24902490

2491+
public static FilePath git_repository_workdir(IntPtr repo)
2492+
{
2493+
return NativeMethods.git_repository_workdir(repo);
2494+
}
2495+
24912496
public static void git_repository_set_head_detached(RepositorySafeHandle repo, ObjectId commitish,
24922497
Signature signature, string logMessage)
24932498
{

LibGit2Sharp/Filter.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,11 @@ protected virtual int Initialize()
8888
/// Clean the input stream and write to the output stream.
8989
/// </summary>
9090
/// <param name="path">The path of the file being filtered</param>
91+
/// <param name="workingDirectory"></param>
9192
/// <param name="input">The git buf input reader</param>
9293
/// <param name="output">The git buf output writer</param>
9394
/// <returns>0 if successful and <see cref="GitErrorCode.PassThrough"/> to skip and pass through</returns>
94-
protected virtual int Clean(string path, Stream input, Stream output)
95+
protected virtual int Clean(string path, string workingDirectory, Stream input, Stream output)
9596
{
9697
return (int)GitErrorCode.PassThrough;
9798
}
@@ -100,10 +101,11 @@ protected virtual int Clean(string path, Stream input, Stream output)
100101
/// Smudge the input stream and write to the output stream.
101102
/// </summary>
102103
/// <param name="path">The path of the file being filtered</param>
104+
/// <param name="repositoryWorkingDirectory"></param>
103105
/// <param name="input">The git buf input reader</param>
104106
/// <param name="output">The git buf output writer</param>
105107
/// <returns>0 if successful and <see cref="GitErrorCode.PassThrough"/> to skip and pass through</returns>
106-
protected virtual int Smudge(string path, Stream input, Stream output)
108+
protected virtual int Smudge(string path, string repositoryWorkingDirectory, Stream input, Stream output)
107109
{
108110
return (int)GitErrorCode.PassThrough;
109111
}
@@ -188,13 +190,14 @@ int ApplyCallback(GitFilter filter, IntPtr payload,
188190
IntPtr gitBufferToPtr, IntPtr gitBufferFromPtr, IntPtr filterSourcePtr)
189191
{
190192
var filterSource = FilterSource.FromNativePtr(filterSourcePtr);
193+
var workingDirectory = filterSource.GetRepositoryWorkingDirectory();
191194
using (var reader = new GitBufReadStream(gitBufferFromPtr))
192195
using (var writer = new GitBufWriteStream(gitBufferToPtr))
193196
using (var bufferedWriter = new BufferedStream(writer))
194197
{
195198
return filterSource.SourceMode == FilterMode.Clean ?
196-
Clean(filterSource.Path, reader, bufferedWriter) :
197-
Smudge(filterSource.Path, reader, bufferedWriter);
199+
Clean(filterSource.Path, workingDirectory, reader, bufferedWriter) :
200+
Smudge(filterSource.Path, workingDirectory, reader, bufferedWriter);
198201
}
199202
}
200203
}

LibGit2Sharp/FilterSource.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,27 @@ namespace LibGit2Sharp
88
/// </summary>
99
public class FilterSource
1010
{
11+
readonly GitFilterSource source;
12+
1113
/// <summary>
1214
/// Needed for mocking purposes
1315
/// </summary>
1416
protected FilterSource() { }
1517

1618
internal FilterSource(FilePath path, FilterMode mode, GitFilterSource source)
1719
{
20+
this.source = source;
1821
SourceMode = mode;
1922
ObjectId = new ObjectId(source.oid);
2023
Path = path.Native;
2124
}
2225

26+
internal string GetRepositoryWorkingDirectory()
27+
{
28+
var filePath = Proxy.git_repository_workdir(source.repository);
29+
return filePath.Native;
30+
}
31+
2332
/// <summary>
2433
/// Take an unmanaged pointer and convert it to filter source callback paramater
2534
/// </summary>

0 commit comments

Comments
 (0)