-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibgit2.pas
More file actions
217 lines (186 loc) · 4.82 KB
/
Copy pathlibgit2.pas
File metadata and controls
217 lines (186 loc) · 4.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
(*
* Copyright (C) 2021-2025 Today Software
* Distributed under the MIT licence see LICENCE file for more details
* https://opensource.org/licenses/MIT
*)
unit LibGit2;
{$IFDEF FPC}
{$MODE objfpc}{$H+}
{$ELSE}
{$IF RTLVersion >= 23}
{$DEFINE DOTTEDUNITS}
{$IFEND}
{$ENDIF}
{$DEFINE GIT_DEPRECATE_HARD}
{*$DEFINE GIT_EXPERIMENTAL_SHA256}
interface
uses
{$IF DEFINED(DOTTEDUNITS) OR DEFINED(FPC_DOTTEDUNITS)}
System.SysUtils;
{$ELSE}
SysUtils;
{$IFEND}
const
{$IF DEFINED(MSWINDOWS)}
libgit2_dll = 'git2.dll';
// Define if you want Windows to use delayed (e.g. on-demand) loading of the DLL.
{*$DEFINE LIBGIT2_DLL_DELAY_LOAD}
{$IF DEFINED(LIBGIT2_DLL_DELAY_LOAD)}
{$WARN SYMBOL_PLATFORM OFF}
{$IFEND}
{$ELSEIF DEFINED(MACOS)}
libgit2_dll = 'libgit2.dylib';
{$ELSE}
libgit2_dll = 'libgit2.so';
{$ENDIF}
type
PPByte = ^PByte;
{$I git2/stdint.inc}
{$IF NOT DECLARED(size_t)}
type
size_t = uintptr_t;
{$IFEND}
procedure InitLibgit2;
procedure ShutdownLibgit2;
// Headers sourced and converted from https://github.com/libgit2/libgit2 and where all under the following licence
(*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*
* https://github.com/libgit2/libgit2/blob/main/COPYING
*)
{$I git2/version.inc}
{$I git2/common.inc}
{$I git2/types.inc}
{$I git2/buffer.inc}
{$I git2/oid.inc}
{$I git2/oidarray.inc}
{$I git2/strarray.inc}
{$I git2/commit.inc}
{$I git2/repository.inc}
{$I git2/diff.inc}
{$I git2/object.inc}
{$I git2/annotated_commit.inc}
{$I git2/apply.inc}
{$I git2/attr.inc}
{$I git2/blame.inc}
{$I git2/blob.inc}
{$I git2/branch.inc}
{$I git2/cert.inc}
{$I git2/checkout.inc}
{$I git2/email.inc}
{$I git2/indexer.inc}
{$I git2/index.inc}
{$I git2/merge.inc}
{$I git2/cherrypick.inc}
{$I git2/pack.inc}
{$I git2/credential.inc}
{$I git2/credential_helpers.inc}
{$I git2/proxy.inc}
{$I git2/net.inc}
{$I git2/refspec.inc}
{$I git2/transport.inc}
{$I git2/remote.inc}
{$I git2/clone.inc}
{$I git2/config.inc}
{$I git2/describe.inc}
{$I git2/errors.inc}
{$I git2/filter.inc}
{$I git2/global.inc}
{$I git2/graph.inc}
{$I git2/ignore.inc}
{$I git2/mailmap.inc}
{$I git2/message.inc}
{$I git2/notes.inc}
{$I git2/odb_backend.inc}
{$I git2/odb.inc}
{$I git2/patch.inc}
{$I git2/pathspec.inc}
{$I git2/rebase.inc}
{$I git2/refdb.inc}
{$I git2/reflog.inc}
{$I git2/refs.inc}
{$I git2/reset.inc}
{$I git2/revert.inc}
{$I git2/revparse.inc}
{$I git2/revwalk.inc}
{$I git2/signature.inc}
{$I git2/stash.inc}
{$I git2/status.inc}
{$I git2/submodule.inc}
{$I git2/tag.inc}
{$I git2/trace.inc}
{$I git2/transaction.inc}
{$I git2/tree.inc}
{$I git2/worktree.inc}
implementation
var
Libgit2init: Boolean;
procedure InitLibgit2;
begin
if not Libgit2init then
begin
Libgit2init := True;
git_libgit2_init;
end;
end;
procedure ShutdownLibgit2;
begin
if Libgit2init then
begin
Libgit2init := False;
git_libgit2_shutdown;
end;
end;
{ attr }
function GIT_ATTR_IS_TRUE(attr: PAnsiChar): Boolean;
begin
Result := git_attr_value(attr) = GIT_ATTR_VALUE_TRUE;
end;
function GIT_ATTR_IS_FALSE(attr: PAnsiChar): Boolean;
begin
Result := git_attr_value(attr) = GIT_ATTR_VALUE_FALSE;
end;
function GIT_ATTR_IS_UNSPECIFIED(attr: PAnsiChar): Boolean;
begin
Result := git_attr_value(attr) = GIT_ATTR_VALUE_UNSPECIFIED;
end;
function GIT_ATTR_HAS_VALUE(attr: PAnsiChar): Boolean;
begin
Result := git_attr_value(attr) = GIT_ATTR_VALUE_STRING;
end;
{ index }
function GIT_INDEX_ENTRY_STAGE_GET(var E: git_index_entry): uint16_t;
begin
Result := (E.flags and GIT_INDEX_ENTRY_STAGEMASK) shr GIT_INDEX_ENTRY_STAGESHIFT;
end;
procedure GIT_INDEX_ENTRY_STAGE_SET(var E: git_index_entry; S: uint16_t);
begin
E.flags := (E.flags and not GIT_INDEX_ENTRY_STAGEMASK) or ((S and 3) shl GIT_INDEX_ENTRY_STAGESHIFT);
end;
{ submodule }
function GIT_SUBMODULE_STATUS_IS_UNMODIFIED(S: Integer): Boolean;
begin
Result := (S and not GIT_SUBMODULE_STATUS__IN_FLAGS) = 0;
end;
function GIT_SUBMODULE_STATUS_IS_INDEX_UNMODIFIED(S: Integer): Boolean;
begin
Result := (S and GIT_SUBMODULE_STATUS__INDEX_FLAGS) = 0;
end;
function GIT_SUBMODULE_STATUS_IS_WD_UNMODIFIED(S: Integer): Boolean;
begin
Result := (S and GIT_SUBMODULE_STATUS__WD_FLAGS and not GIT_SUBMODULE_STATUS_WD_UNINITIALIZED) = 0;
end;
function GIT_SUBMODULE_STATUS_IS_WD_DIRTY(S: Integer): Boolean;
begin
Result := (S and (GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED or GIT_SUBMODULE_STATUS_WD_WD_MODIFIED or
GIT_SUBMODULE_STATUS_WD_UNTRACKED)) = 0;
end;
{ version }
function LIBGIT2_VERSION_CHECK(major, minor, revision: Integer): Boolean;
begin
Result := LIBGIT2_VERSION_NUMBER >= ((major) * 1000000) + ((minor) * 10000) + ((revision) * 100);
end;
end.