unit ATBGit; {$mode ObjFPC}{$H+} interface uses CTypes, SysUtils, fpjson, jsonparser; // // public interface // procedure SetReposRootDirectory(const rootDir: UTF8String); function GetReposRootDirectory(): UTF8String; function GetLocalRepositoryPath(const localrepo: UTF8String): UTF8String; 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; // private c-interface procedure SetReposRootDirectoryInternal(const rootDir: PChar); stdcall; function GetReposRootDirectoryInternal(): PChar; stdcall; function GetLocalRepositoryPathInternal(const localRepo: PChar): PChar; stdcall; 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; implementation const DLLName = 'CalculatorCInterface.dll'; 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; /// 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; 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; end.