2024-03-25 16:12:02 +01:00
|
|
|
unit ATBGit;
|
|
|
|
|
|
|
|
{$mode ObjFPC}{$H+}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
2024-04-15 17:58:11 +02:00
|
|
|
uses CTypes, SysUtils, fpjson, jsonparser;
|
2024-03-25 16:12:02 +01:00
|
|
|
|
2024-03-26 17:02:59 +01:00
|
|
|
//
|
|
|
|
// public interface
|
|
|
|
//
|
|
|
|
procedure SetReposRootDirectory(const rootDir: UTF8String);
|
|
|
|
function GetReposRootDirectory(): UTF8String;
|
|
|
|
function GetLocalRepositoryPath(const localrepo: UTF8String): UTF8String;
|
|
|
|
|
2024-04-15 17:58:11 +02:00
|
|
|
function InitGitLibrary(): Integer;
|
|
|
|
function ShutdownGitLibrary(): Integer;
|
|
|
|
function CloneRepository(const url, localRepo: UTF8String): Integer;
|
|
|
|
function CheckoutRepository(const url, localRepo, branchName: UTF8String): Integer;
|
|
|
|
function CommitFile(const localRepoName, branchName, fName, commitMessage: UTF8String): Integer;
|
|
|
|
|
2024-03-26 17:02:59 +01:00
|
|
|
// private c-interface
|
|
|
|
procedure SetReposRootDirectoryInternal(const rootDir: PChar); stdcall;
|
|
|
|
function GetReposRootDirectoryInternal(): PChar; stdcall;
|
|
|
|
function GetLocalRepositoryPathInternal(const localRepo: PChar): PChar; stdcall;
|
2024-04-15 17:58:11 +02:00
|
|
|
function CloneRepositoryInternal(const url, localRepo: PChar): cint32; stdcall;
|
|
|
|
function CheckoutRepositoryInternal(const url, localRepo, branchName: PChar): cint32; stdcall;
|
|
|
|
function CommitFileInternal(const localRepoName, branchName, fName, commitMessage: PChar): cint32; stdcall;
|
|
|
|
function PushRepositoryInternal(const localRepoName, branchName, user, password: PChar): cint32; stdcall;
|
|
|
|
function PullRepositoryInternal(const localRepoName, remoteRepoName: PChar): cint32; stdcall;
|
|
|
|
|
|
|
|
function InitGitLibraryInternal: cint32; stdcall;
|
|
|
|
function ShutdownGitLibraryInternal: cint32; stdcall;
|
2024-03-25 16:12:02 +01:00
|
|
|
|
|
|
|
implementation
|
2024-04-15 17:58:11 +02:00
|
|
|
|
2024-03-25 16:12:02 +01:00
|
|
|
const DLLName = 'CalculatorCInterface.dll';
|
|
|
|
|
2024-04-15 17:58:11 +02:00
|
|
|
function InitGitLibrary(): Integer;
|
|
|
|
begin
|
|
|
|
Result := InitGitLibraryInternal();
|
|
|
|
end;
|
|
|
|
|
|
|
|
function ShutdownGitLibrary(): Integer;
|
|
|
|
begin
|
|
|
|
Result := ShutdownGitLibraryInternal();
|
|
|
|
end;
|
|
|
|
|
|
|
|
function CloneRepository(const url, localRepo: UTF8String): Integer;
|
|
|
|
begin
|
|
|
|
Result := CloneRepositoryInternal(PChar(Utf8toAnsi(url)),
|
|
|
|
PChar(Utf8toAnsi(localRepo)));
|
|
|
|
end;
|
|
|
|
|
|
|
|
function CheckoutRepository(const url, localRepo, branchName: UTF8String): Integer;
|
|
|
|
begin
|
|
|
|
Result := CheckoutRepositoryInternal(PChar(Utf8toAnsi(url)),
|
|
|
|
PChar(Utf8toAnsi(localRepo)),
|
|
|
|
PChar(Utf8toAnsi(branchName)));
|
|
|
|
end;
|
|
|
|
|
|
|
|
function CommitFile(const localRepoName, branchName, fName, commitMessage: UTF8String): Integer;
|
|
|
|
begin
|
|
|
|
Result := CommitFileInternal(PChar(Utf8toAnsi(localRepoName)),
|
|
|
|
PChar(Utf8toAnsi(branchName)),
|
|
|
|
PChar(Utf8toAnsi(fName)),
|
|
|
|
PChar(Utf8toAnsi(commitMessage)));
|
|
|
|
end;
|
|
|
|
|
|
|
|
function PushRepository(const localRepoName, branchName, user, password: UTF8String): Integer;
|
|
|
|
begin
|
|
|
|
Result := PushRepositoryInternal(PChar(Utf8toAnsi(localRepoName)),
|
|
|
|
PChar(Utf8toAnsi(branchName)),
|
|
|
|
PChar(Utf8toAnsi(user)),
|
|
|
|
PChar(Utf8toAnsi(password)));
|
|
|
|
end;
|
|
|
|
|
|
|
|
function PullRepository(const localRepoName, remoteRepoName: UTF8String): Integer;
|
|
|
|
begin
|
|
|
|
Result := PullRepositoryInternal(PChar(Utf8toAnsi(localRepoName)),
|
|
|
|
PChar(Utf8toAnsi(remoteRepoName)));
|
|
|
|
end;
|
|
|
|
|
2024-03-26 17:02:59 +01:00
|
|
|
///
|
|
|
|
procedure SetReposRootDirectory(const rootDir: UTF8String);
|
|
|
|
begin
|
|
|
|
try
|
|
|
|
SetReposRootDirectoryInternal(PChar(Utf8toAnsi(rootDir)));
|
|
|
|
finally
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
///
|
|
|
|
function GetReposRootDirectory(): UTF8String;
|
|
|
|
begin
|
|
|
|
try
|
|
|
|
Result := UTF8String(GetReposRootDirectoryInternal());
|
|
|
|
finally
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function GetLocalRepositoryPath(const localRepo: UTF8String): UTF8String;
|
|
|
|
begin
|
|
|
|
try
|
|
|
|
Result := UTF8String(GetLocalRepositoryPathInternal(PChar(Utf8toAnsi(localRepo))));
|
|
|
|
finally
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
//
|
|
|
|
// external c-interface
|
|
|
|
//
|
|
|
|
procedure SetReposRootDirectoryInternal(const rootDir: PChar); stdcall;
|
|
|
|
external DLLName;
|
|
|
|
|
|
|
|
function GetReposRootDirectoryInternal(): PChar; stdcall;
|
|
|
|
external DLLName;
|
|
|
|
|
|
|
|
function GetLocalRepositoryPathInternal(const localRepo: PChar): PChar; stdcall;
|
|
|
|
external DLLName;
|
|
|
|
|
2024-04-15 17:58:11 +02:00
|
|
|
function InitGitLibraryInternal: cint32; stdcall;
|
|
|
|
external DLLName;
|
|
|
|
|
|
|
|
function ShutdownGitLibraryInternal: cint32; stdcall;
|
|
|
|
external DLLName;
|
|
|
|
|
|
|
|
function CloneRepositoryInternal(const url, localRepo: PChar): cint32; stdcall;
|
|
|
|
external DLLName;
|
|
|
|
|
|
|
|
function CheckoutRepositoryInternal(const url, localRepo, branchName: PChar): cint32; stdcall;
|
|
|
|
external DLLName;
|
|
|
|
|
|
|
|
function CommitFileInternal(const localRepoName, branchName, fName, commitMessage: PChar): cint32; stdcall;
|
|
|
|
external DLLName;
|
|
|
|
|
|
|
|
function PushRepositoryInternal(const localRepoName, branchName, user, password: PChar): cint32; stdcall;
|
|
|
|
external DLLName;
|
|
|
|
|
|
|
|
function PullRepositoryInternal(const localRepoName, remoteRepoName: PChar): cint32; stdcall;
|
|
|
|
external DLLName;
|
|
|
|
|
2024-03-25 16:12:02 +01:00
|
|
|
end.
|
|
|
|
|