Skip to content
This repository was archived by the owner on Mar 31, 2025. It is now read-only.

Commit 5089193

Browse files
committed
Fix more mappings for git_repository and revwalk
1 parent 47b8556 commit 5089193

File tree

5 files changed

+93
-32
lines changed

5 files changed

+93
-32
lines changed

src/LibGit2.CodeGen/Program.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,24 @@ public void Run()
6262
// Mappings for repository.h
6363
e => e.MapMacroToConst("GIT_REPOSITORY_INIT_OPTIONS_VERSION", "unsigned int"),
6464
e => e.Map<CppParameter>("git_repository_open_ext::flags").Type("git_repository_open_flag_t"),
65-
e => e.Map<CppParameter>("git_repository_init::is_bare").Type("bool").MarshalAs(CSharpUnmanagedKind.I4),
66-
e => e.Map<CppParameter>("git_repository_discover::across_fs").Type("bool").MarshalAs(CSharpUnmanagedKind.I4),
65+
e => e.Map<CppParameter>("git_repository_init::is_bare").Type("bool").MarshalAs(CSharpUnmanagedKind.Bool),
66+
e => e.Map<CppParameter>("git_repository_discover::across_fs").Type("bool").MarshalAs(CSharpUnmanagedKind.Bool),
6767
e => e.Map<CppParameter>("git_repository_init_init_options::version").InitValue("GIT_REPOSITORY_INIT_OPTIONS_VERSION"),
68-
e => e.Map<CppParameter>("git_repository_set_workdir::update_gitlink").Type("bool").MarshalAs(CSharpUnmanagedKind.I4),
68+
e => e.Map<CppParameter>("git_repository_set_workdir::update_gitlink").Type("bool").MarshalAs(CSharpUnmanagedKind.Bool),
6969
e => e.Map<CppField>("git_repository_init_options::flags").Type("git_repository_init_flag_t"),
7070
e => e.Map<CppField>("git_repository_init_options::mode").Type("git_repository_init_mode_t"),
7171
e => e.Map<CppFunction>("git_repository_state").Type("git_repository_state_t"),
72-
e => e.Map<CppFunction>("git_repository_is_shallow").Type("bool").MarshalAs(CSharpUnmanagedKind.I4),
7372
e => e.Map<CppFunction>("git_repository_ident").Type("git_result"),
7473
e => e.Map<CppFunction>("git_repository_set_ident").Type("git_result"),
74+
e => e.Map<CppFunction>("git_repository_fetchhead_foreach").Type("git_result"),
75+
e => e.Map<CppFunction>("git_repository_is_shallow").Type("bool").MarshalAs(CSharpUnmanagedKind.Bool),
76+
e => e.Map<CppFunction>("git_repository_is_bare").Type("bool").MarshalAs(CSharpUnmanagedKind.Bool),
77+
e => e.Map<CppFunction>("git_repository_is_worktree").Type("bool").MarshalAs(CSharpUnmanagedKind.Bool),
78+
e => e.Map<CppFunction>("git_repository_is_empty").Type("bool").MarshalAs(CSharpUnmanagedKind.Bool),
79+
80+
// Mappings for revwalk.h
81+
e => e.Map<CppParameter>("git_revwalk_sorting::sort_mode").Type("git_sort_t"),
82+
e => e.Map<CppFunction>("git_revwalk_next").Type("bool").MarshalAs(CSharpUnmanagedKind.Bool),
7583

7684
e => e.Map<CppField>("git_strarray::strings").Private(),
7785
e => e.Map<CppField>("git_strarray::count").Private(),
@@ -259,6 +267,7 @@ private void ProcessCppFunctions(CSharpConverter converter, CppElement cppFuncti
259267
(returnText.Contains("0 on success") && returnText.Contains("0 on failure")) ||
260268
(returnText.StartsWith("0") && (
261269
returnText.Contains("or an error") ||
270+
returnText.Contains("error code") ||
262271
returnText.Contains("-1 on error") ||
263272
returnText.Contains("or error") ||
264273
returnText.Contains("error code otherwise") ||

src/LibGit2/generated/branch.generated.cs

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,14 @@ public static git_result git_branch_move(out git_reference @out, git_reference b
176176
/// The generated reference must be freed by the user.The branch name will be checked for validity.
177177
/// See `git_tag_create()` for rules about valid names.
178178
/// </remarks>
179-
[DllImport(LibGit2Name, CallingConvention = CallingConvention.Cdecl)]
180-
public static extern int git_branch_lookup(out git_reference @out, git_repository repo, [MarshalAs(UnmanagedType.LPUTF8Str)] string branch_name, git_branch_t branch_type);
179+
public static git_result git_branch_lookup(out git_reference @out, git_repository repo, [MarshalAs(UnmanagedType.LPUTF8Str)] string branch_name, git_branch_t branch_type)
180+
{
181+
var __result__ = git_branch_lookup__(out @out, repo, branch_name, branch_type).Check();
182+
return __result__;
183+
}
184+
185+
[DllImport(LibGit2Name, EntryPoint = "git_branch_lookup", CallingConvention = CallingConvention.Cdecl)]
186+
private static extern git_result git_branch_lookup__(out git_reference @out, git_repository repo, [MarshalAs(UnmanagedType.LPUTF8Str)] string branch_name, git_branch_t branch_type);
181187

182188
/// <summary>
183189
/// Return the name of the given local or remote branch.
@@ -193,8 +199,14 @@ public static git_result git_branch_move(out git_reference @out, git_reference b
193199
/// to git_branch_lookup() then the reference is returned that
194200
/// was given to this function.
195201
/// </remarks>
196-
[DllImport(LibGit2Name, CallingConvention = CallingConvention.Cdecl)]
197-
public static extern int git_branch_name(out string @out, git_reference @ref);
202+
public static git_result git_branch_name(out string @out, git_reference @ref)
203+
{
204+
var __result__ = git_branch_name__(out @out, @ref).Check();
205+
return __result__;
206+
}
207+
208+
[DllImport(LibGit2Name, EntryPoint = "git_branch_name", CallingConvention = CallingConvention.Cdecl)]
209+
private static extern git_result git_branch_name__(out string @out, git_reference @ref);
198210

199211
/// <summary>
200212
/// Return the reference supporting the remote tracking branch,
@@ -205,8 +217,14 @@ public static git_result git_branch_move(out git_reference @out, git_reference b
205217
/// <param name="branch">Current underlying reference of the branch.</param>
206218
/// <returns>0 on success; GIT_ENOTFOUND when no remote tracking
207219
/// reference exists, otherwise an error code.</returns>
208-
[DllImport(LibGit2Name, CallingConvention = CallingConvention.Cdecl)]
209-
public static extern int git_branch_upstream(out git_reference @out, git_reference branch);
220+
public static git_result git_branch_upstream(out git_reference @out, git_reference branch)
221+
{
222+
var __result__ = git_branch_upstream__(out @out, branch).Check();
223+
return __result__;
224+
}
225+
226+
[DllImport(LibGit2Name, EntryPoint = "git_branch_upstream", CallingConvention = CallingConvention.Cdecl)]
227+
private static extern git_result git_branch_upstream__(out git_reference @out, git_reference branch);
210228

211229
/// <summary>
212230
/// Set the upstream configuration for a given local branch
@@ -234,8 +252,14 @@ public static git_result git_branch_set_upstream(git_reference branch, [MarshalA
234252
/// <param name="refname">reference name of the local branch.</param>
235253
/// <returns>0, GIT_ENOTFOUND when no remote tracking reference exists,
236254
/// otherwise an error code.</returns>
237-
[DllImport(LibGit2Name, CallingConvention = CallingConvention.Cdecl)]
238-
public static extern int git_branch_upstream_name(out git_buf @out, git_repository repo, [MarshalAs(UnmanagedType.LPUTF8Str)] string refname);
255+
public static git_result git_branch_upstream_name(out git_buf @out, git_repository repo, [MarshalAs(UnmanagedType.LPUTF8Str)] string refname)
256+
{
257+
var __result__ = git_branch_upstream_name__(out @out, repo, refname).Check();
258+
return __result__;
259+
}
260+
261+
[DllImport(LibGit2Name, EntryPoint = "git_branch_upstream_name", CallingConvention = CallingConvention.Cdecl)]
262+
private static extern git_result git_branch_upstream_name__(out git_buf @out, git_repository repo, [MarshalAs(UnmanagedType.LPUTF8Str)] string refname);
239263

240264
/// <summary>
241265
/// Determine if the current local branch is pointed at by HEAD.
@@ -266,8 +290,14 @@ public static git_result git_branch_set_upstream(git_reference branch, [MarshalA
266290
/// when no remote matching remote was found,
267291
/// GIT_EAMBIGUOUS when the branch maps to several remotes,
268292
/// otherwise an error code.</returns>
269-
[DllImport(LibGit2Name, CallingConvention = CallingConvention.Cdecl)]
270-
public static extern int git_branch_remote_name(out git_buf @out, git_repository repo, [MarshalAs(UnmanagedType.LPUTF8Str)] string canonical_branch_name);
293+
public static git_result git_branch_remote_name(out git_buf @out, git_repository repo, [MarshalAs(UnmanagedType.LPUTF8Str)] string canonical_branch_name)
294+
{
295+
var __result__ = git_branch_remote_name__(out @out, repo, canonical_branch_name).Check();
296+
return __result__;
297+
}
298+
299+
[DllImport(LibGit2Name, EntryPoint = "git_branch_remote_name", CallingConvention = CallingConvention.Cdecl)]
300+
private static extern git_result git_branch_remote_name__(out git_buf @out, git_repository repo, [MarshalAs(UnmanagedType.LPUTF8Str)] string canonical_branch_name);
271301

272302
/// <summary>
273303
/// Retrieve the name of the upstream remote of a local branch

src/LibGit2/generated/refs.generated.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -726,8 +726,14 @@ public static git_result git_reference_foreach_glob(git_repository repo, [Marsha
726726
/// <param name="refname">the reference's name</param>
727727
/// <returns>0 when no reflog can be found, 1 when it exists;
728728
/// otherwise an error code.</returns>
729-
[DllImport(LibGit2Name, CallingConvention = CallingConvention.Cdecl)]
730-
public static extern int git_reference_has_log(git_repository repo, [MarshalAs(UnmanagedType.LPUTF8Str)] string refname);
729+
public static git_result git_reference_has_log(git_repository repo, [MarshalAs(UnmanagedType.LPUTF8Str)] string refname)
730+
{
731+
var __result__ = git_reference_has_log__(repo, refname).Check();
732+
return __result__;
733+
}
734+
735+
[DllImport(LibGit2Name, EntryPoint = "git_reference_has_log", CallingConvention = CallingConvention.Cdecl)]
736+
private static extern git_result git_reference_has_log__(git_repository repo, [MarshalAs(UnmanagedType.LPUTF8Str)] string refname);
731737

732738
/// <summary>
733739
/// Ensure there is a reflog for a particular reference.

src/LibGit2/generated/repository.generated.cs

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -460,14 +460,14 @@ public static git_result git_repository_wrap_odb(out git_repository @out, git_od
460460
/// The method will automatically detect if the repository is bare
461461
/// (if there is a repository).
462462
/// </remarks>
463-
public static git_result git_repository_discover(out git_buf @out, [MarshalAs(UnmanagedType.LPUTF8Str)] string start_path, [MarshalAs(UnmanagedType.I4)] bool across_fs, [MarshalAs(UnmanagedType.LPUTF8Str)] string ceiling_dirs)
463+
public static git_result git_repository_discover(out git_buf @out, [MarshalAs(UnmanagedType.LPUTF8Str)] string start_path, [MarshalAs(UnmanagedType.Bool)] bool across_fs, [MarshalAs(UnmanagedType.LPUTF8Str)] string ceiling_dirs)
464464
{
465465
var __result__ = git_repository_discover__(out @out, start_path, across_fs, ceiling_dirs).Check();
466466
return __result__;
467467
}
468468

469469
[DllImport(LibGit2Name, EntryPoint = "git_repository_discover", CallingConvention = CallingConvention.Cdecl)]
470-
private static extern git_result git_repository_discover__(out git_buf @out, [MarshalAs(UnmanagedType.LPUTF8Str)] string start_path, [MarshalAs(UnmanagedType.I4)] bool across_fs, [MarshalAs(UnmanagedType.LPUTF8Str)] string ceiling_dirs);
470+
private static extern git_result git_repository_discover__(out git_buf @out, [MarshalAs(UnmanagedType.LPUTF8Str)] string start_path, [MarshalAs(UnmanagedType.Bool)] bool across_fs, [MarshalAs(UnmanagedType.LPUTF8Str)] string ceiling_dirs);
471471

472472
/// <summary>
473473
/// Find and open a repository with extended controls.
@@ -537,14 +537,14 @@ public static git_result git_repository_open_bare(out git_repository @out, [Mars
537537
/// TODO:
538538
/// - Reinit the repository
539539
/// </remarks>
540-
public static git_result git_repository_init(out git_repository @out, [MarshalAs(UnmanagedType.LPUTF8Str)] string path, [MarshalAs(UnmanagedType.I4)] bool is_bare)
540+
public static git_result git_repository_init(out git_repository @out, [MarshalAs(UnmanagedType.LPUTF8Str)] string path, [MarshalAs(UnmanagedType.Bool)] bool is_bare)
541541
{
542542
var __result__ = git_repository_init__(out @out, path, is_bare).Check();
543543
return __result__;
544544
}
545545

546546
[DllImport(LibGit2Name, EntryPoint = "git_repository_init", CallingConvention = CallingConvention.Cdecl)]
547-
private static extern git_result git_repository_init__(out git_repository @out, [MarshalAs(UnmanagedType.LPUTF8Str)] string path, [MarshalAs(UnmanagedType.I4)] bool is_bare);
547+
private static extern git_result git_repository_init__(out git_repository @out, [MarshalAs(UnmanagedType.LPUTF8Str)] string path, [MarshalAs(UnmanagedType.Bool)] bool is_bare);
548548

549549
/// <summary>
550550
/// Initialize git_repository_init_options structure
@@ -669,7 +669,8 @@ public static git_result git_repository_head(out git_reference @out, git_reposit
669669
/// apart from HEAD, which must be pointing to the unborn master branch.
670670
/// </remarks>
671671
[DllImport(LibGit2Name, CallingConvention = CallingConvention.Cdecl)]
672-
public static extern int git_repository_is_empty(git_repository repo);
672+
[return:MarshalAs(UnmanagedType.Bool)]
673+
public static extern bool git_repository_is_empty(git_repository repo);
673674

674675
/// <summary>
675676
/// Get the location of a specific repository file or directory
@@ -748,30 +749,32 @@ public static git_result git_repository_item_path(out git_buf @out, git_reposito
748749
/// all the common workdir operations (checkout, status, index
749750
/// manipulation, etc).
750751
/// </remarks>
751-
public static git_result git_repository_set_workdir(git_repository repo, [MarshalAs(UnmanagedType.LPUTF8Str)] string workdir, [MarshalAs(UnmanagedType.I4)] bool update_gitlink)
752+
public static git_result git_repository_set_workdir(git_repository repo, [MarshalAs(UnmanagedType.LPUTF8Str)] string workdir, [MarshalAs(UnmanagedType.Bool)] bool update_gitlink)
752753
{
753754
var __result__ = git_repository_set_workdir__(repo, workdir, update_gitlink).Check();
754755
return __result__;
755756
}
756757

757758
[DllImport(LibGit2Name, EntryPoint = "git_repository_set_workdir", CallingConvention = CallingConvention.Cdecl)]
758-
private static extern git_result git_repository_set_workdir__(git_repository repo, [MarshalAs(UnmanagedType.LPUTF8Str)] string workdir, [MarshalAs(UnmanagedType.I4)] bool update_gitlink);
759+
private static extern git_result git_repository_set_workdir__(git_repository repo, [MarshalAs(UnmanagedType.LPUTF8Str)] string workdir, [MarshalAs(UnmanagedType.Bool)] bool update_gitlink);
759760

760761
/// <summary>
761762
/// Check if a repository is bare
762763
/// </summary>
763764
/// <param name="repo">Repo to test</param>
764765
/// <returns>1 if the repository is bare, 0 otherwise.</returns>
765766
[DllImport(LibGit2Name, CallingConvention = CallingConvention.Cdecl)]
766-
public static extern int git_repository_is_bare(git_repository repo);
767+
[return:MarshalAs(UnmanagedType.Bool)]
768+
public static extern bool git_repository_is_bare(git_repository repo);
767769

768770
/// <summary>
769771
/// Check if a repository is a linked work tree
770772
/// </summary>
771773
/// <param name="repo">Repo to test</param>
772774
/// <returns>1 if the repository is a linked work tree, 0 otherwise.</returns>
773775
[DllImport(LibGit2Name, CallingConvention = CallingConvention.Cdecl)]
774-
public static extern int git_repository_is_worktree(git_repository repo);
776+
[return:MarshalAs(UnmanagedType.Bool)]
777+
public static extern bool git_repository_is_worktree(git_repository repo);
775778

776779
/// <summary>
777780
/// Get the configuration file for this repository.
@@ -936,8 +939,14 @@ public static git_result git_repository_state_cleanup(git_repository repo)
936939
/// <remarks>
937940
/// Return a non-zero value from the callback to stop the loop.
938941
/// </remarks>
939-
[DllImport(LibGit2Name, CallingConvention = CallingConvention.Cdecl)]
940-
public static extern int git_repository_fetchhead_foreach(git_repository repo, git_repository_fetchhead_foreach_cb callback, IntPtr payload);
942+
public static git_result git_repository_fetchhead_foreach(git_repository repo, git_repository_fetchhead_foreach_cb callback, IntPtr payload)
943+
{
944+
var __result__ = git_repository_fetchhead_foreach__(repo, callback, payload).Check();
945+
return __result__;
946+
}
947+
948+
[DllImport(LibGit2Name, EntryPoint = "git_repository_fetchhead_foreach", CallingConvention = CallingConvention.Cdecl)]
949+
private static extern git_result git_repository_fetchhead_foreach__(git_repository repo, git_repository_fetchhead_foreach_cb callback, IntPtr payload);
941950

942951
/// <summary>
943952
/// If a merge is in progress, invoke 'callback' for each commit ID in the
@@ -951,8 +960,14 @@ public static git_result git_repository_state_cleanup(git_repository repo)
951960
/// <remarks>
952961
/// Return a non-zero value from the callback to stop the loop.
953962
/// </remarks>
954-
[DllImport(LibGit2Name, CallingConvention = CallingConvention.Cdecl)]
955-
public static extern int git_repository_mergehead_foreach(git_repository repo, git_repository_mergehead_foreach_cb callback, IntPtr payload);
963+
public static git_result git_repository_mergehead_foreach(git_repository repo, git_repository_mergehead_foreach_cb callback, IntPtr payload)
964+
{
965+
var __result__ = git_repository_mergehead_foreach__(repo, callback, payload).Check();
966+
return __result__;
967+
}
968+
969+
[DllImport(LibGit2Name, EntryPoint = "git_repository_mergehead_foreach", CallingConvention = CallingConvention.Cdecl)]
970+
private static extern git_result git_repository_mergehead_foreach__(git_repository repo, git_repository_mergehead_foreach_cb callback, IntPtr payload);
956971

957972
/// <summary>
958973
/// Calculate hash of file using repository filtering rules.
@@ -1107,7 +1122,7 @@ public static git_result git_repository_set_namespace(git_repository repo, [Mars
11071122
/// <param name="repo">The repository</param>
11081123
/// <returns>1 if shallow, zero if not</returns>
11091124
[DllImport(LibGit2Name, CallingConvention = CallingConvention.Cdecl)]
1110-
[return:MarshalAs(UnmanagedType.I4)]
1125+
[return:MarshalAs(UnmanagedType.Bool)]
11111126
public static extern bool git_repository_is_shallow(git_repository repo);
11121127

11131128
/// <summary>

src/LibGit2/generated/revwalk.generated.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ public static git_result git_revwalk_hide_ref(git_revwalk walk, [MarshalAs(Unman
287287
/// times at 0.3s on the git.git repo).The revision walker is reset when the walk is over.
288288
/// </remarks>
289289
[DllImport(LibGit2Name, CallingConvention = CallingConvention.Cdecl)]
290-
public static extern int git_revwalk_next(out git_oid @out, git_revwalk walk);
290+
[return:MarshalAs(UnmanagedType.Bool)]
291+
public static extern bool git_revwalk_next(out git_oid @out, git_revwalk walk);
291292

292293
/// <summary>
293294
/// Change the sorting mode when iterating through the
@@ -299,7 +300,7 @@ public static git_result git_revwalk_hide_ref(git_revwalk walk, [MarshalAs(Unman
299300
/// Changing the sorting mode resets the walker.
300301
/// </remarks>
301302
[DllImport(LibGit2Name, CallingConvention = CallingConvention.Cdecl)]
302-
public static extern void git_revwalk_sorting(git_revwalk walk, uint sort_mode);
303+
public static extern void git_revwalk_sorting(git_revwalk walk, git_sort_t sort_mode);
303304

304305
/// <summary>
305306
/// Push and hide the respective endpoints of the given range.

0 commit comments

Comments
 (0)