Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 37.87 KB | None | 0 0
  1. unit ugit2;
  2.  
  3. (* Common configuration.
  4.  
  5.   This file is included by library units to configure the compiler.  It isn't
  6.   neccessary to include it in your projects. *)
  7.  
  8. {TODO: Detect MacOS and iOS}
  9. {TODO: Detect Android?}
  10. {TODO: Detect GNU/Pascal?}
  11.  
  12. (* Code to detect Delphi.
  13.  
  14.   Seems that old Delphi (i.e: Delphi6) defines DELPHI but newer ones
  15.   doesn't (or at least Tokio 10.2 doesn't) so some tweaking should be done.
  16.  
  17.   Note that this code was tested with Delphi Tokio 10.2 Starter Edition only.
  18.   I've tryed Delphi 6 proffesional and IT DOESN'T WORK AT ALL and I don't see
  19.   how to make it run.  Theoretically it should work with Delphi 7 (as I've
  20.   tryed to keep Cieslak's changes) but I haven't a copy so it isn't tested.
  21.  
  22.   Also I've used a table from Embarcadero's Delphi Wiki.
  23.   http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Conditional_compilation_(Delphi)
  24.  *)
  25. {$IFNDEF DELPHI}
  26.   {$IFDEF DCC}
  27.     {$DEFINE DELPHI}
  28.   {$ENDIF}
  29. {$ENDIF}
  30.  
  31. {$IFNDEF FPC}
  32.   {$IFNDEF DELPHI}
  33. {
  34.   This version wasn't tested with other compilers than Free Pascal and Delphi.
  35.   May be you want to help porting it to other systems and compilers, won't you?
  36. }
  37.     {$ERROR ugit2.pas wasn't tested with this compiler.  Do you want to help? }
  38.   {$ENDIF}
  39. {$ENDIF}
  40.  
  41. { Configure the compiler. }
  42.  
  43. {$IFDEF FPC}
  44. { Free Pascal. }
  45. { Checks platform. }
  46.   {$IFDEF UNIX}
  47.     {$IF DEFINED(DARWIN) OR DEFINED(QNX) OR DEFINED(BEOS)}
  48. {
  49.   This version wasn't tested on those systems.
  50.   May be you want to help porting it to other systems and compilers, won't you?
  51. }
  52.       {$ERROR ugit2.pas wasn't tested on your Operating System.  Do you want to help? }
  53.     {$ENDIF}
  54.   {$ELSE}
  55.     {$IFNDEF WINDOWS}
  56.       {$ERROR ugit2.pas wasn't tested on your Operating System.  Do you want to help? }
  57.     {$ENDIF}
  58.   {$ENDIF}
  59. { Sets dialect. }
  60.   {$IF NOT DEFINED(FPC_DELPHI)}
  61.     {$MODE DELPHI}
  62.   {$ENDIF}
  63.   {$MACRO ON}
  64.   {$LONGSTRINGS ON}
  65.   {$PACKRECORDS C}
  66.   {$PACKENUM 4}
  67.   {$IFNDEF DEBUGMODE}
  68.     {$SMARTLINK ON}
  69.   {$ELSE}
  70.     {$INLINE OFF}
  71.   {$ENDIF}
  72. {$ENDIF}
  73.  
  74. {$IFDEF DELPHI}
  75. { Delphi }
  76. { Checks platform }
  77.   {$IFDEF CONDITIONALEXPRESSIONS}
  78.     {$IF CompilerVersion >= 18.5}
  79.       {$DEFINE ISDELPHI2007ANDUP}
  80.     {$ENDIF}
  81.     {$IF CompilerVersion >= 20.0}
  82.       {$DEFINE ISDELPHI2009ANDUP}
  83.     {$ENDIF}
  84.   {$ENDIF}
  85.  
  86. { Delphi and Free Pascal have different ways to tell they're generating an
  87.   executable for Windows. }
  88.   {$IFNDEF WINDOWS}
  89.     {$IFDEF MSWINDOWS}
  90.       {$DEFINE WINDOWS}
  91.     {$ENDIF}
  92.   {$ENDIF}
  93. { CPU has some issues as well. }
  94.   {$IFNDEF CPU64}
  95.     {$IFDEF CPU64BITS}
  96.       {$DEFINE CPU64}
  97.     {$ENDIF}
  98.   {$ENDIF}
  99. { Set compiler options. }
  100.   {$LONGSTRINGS ON}
  101.   {TODO: Next directive works on 32bit, it wasn''t tested on 64bit.}
  102.   {$ALIGN 8}
  103.   {$MINENUMSIZE 4}
  104. {$ENDIF}
  105.  
  106. interface
  107.  
  108. uses ctypes, MultiLog;
  109.  
  110. (* Defines some constants to build the correct names of the library files. *)
  111. const
  112. {$IFDEF DEBUGMODE}
  113.   _DBG_ = '-debug';{<@exclude }
  114. {$ELSE}
  115.   _DBG_ = ''; {<@exclude }
  116. {$ENDIF}
  117.  
  118. {$IF DEFINED(LINUX)}
  119. (* @exclude Prefix for libraries. *)
  120.   _LG2_LIB_PREFIX_ = 'lib';
  121. (* @exclude Sufix/extension for libraries. *)
  122.   _LG2_LIB_EXT_    = '.so';
  123. {$ELSEIF DEFINED(UNIX)}
  124. (* @exclude Prefix for libraries. *)
  125.   _LG2_LIB_PREFIX_ = 'lib';
  126. (* @exclude Sufix/extension for libraries. *)
  127.   _LG2_LIB_EXT_    = '.so';
  128. {$ELSEIF DEFINED(WINDOWS)}
  129. (* @exclude Prefix for libraries. *)
  130.   _LG2_LIB_PREFIX_ = '';
  131. (* @exclude Sufix/extension for libraries. *)
  132.   _LG2_LIB_EXT_    = '.dll';
  133. {$ENDIF}
  134.  
  135. (* @exclude Builds main library name.  AFAIK it's not needed. *)
  136.   LIBGIT2_MAIN_LIB_NAME = _LG2_LIB_PREFIX_+'git2_main'+_DBG_+_LG2_LIB_EXT_;
  137.  
  138. (* @exclude Builds library name. *)
  139.   LIBGIT2_LIB_NAME = _LG2_LIB_PREFIX_+'git2'+_DBG_+_LG2_LIB_EXT_;
  140.  
  141. type
  142.  (* Generic pointer. *)
  143.    LG2_POINTER = POINTER;
  144.    LG2_DWORD = DWORD;
  145.  (* Signed 8bit integer values. *)
  146.    LG2_INT8 = SHORTINT;
  147.  (* Unsigned 8bit integer values. *)
  148.    LG2_UINT8 = BYTE;
  149.  (* Signed 16bit integer values. *)
  150.    LG2_INT16 = SMALLINT;
  151.  (* Unsigned 16bit integer values. *)
  152.    LG2_UINT16 = WORD;
  153.  (* Signed 32bit integer values. *)
  154.    LG2_INT32 = LONGINT;
  155.  (* Unsigned 32bit integer values. *)
  156.    LG2_UINT32 = LONGWORD;
  157.  (* Signed 64bit integer values. *)
  158.    LG2_INT64 = INT64;
  159.  (* Time frame. *)
  160.    LG2_TIME_T = INT64;
  161.    LG2_OFF_T = INT64;
  162. {$IFDEF FPC}
  163.  (* Unsigned 64bit integer values. *)
  164.    LG2_UINT64 = QWORD;
  165. {$ELSE}
  166.  {$IFDEF ISDELPHI2007ANDUP}
  167.  (* Unsigned 64bit integer values. *)
  168.    LG2_UINT64 = UINT64;
  169.  {$ELSE}
  170.  (* Unsigned 64bit integer values. *)
  171.    LG2_UINT64 = INT64;
  172.  {$ENDIF}
  173. {$ENDIF}
  174.  
  175. { TODO: Check wich boolean type does it uses. }
  176.   (* Boolean result. *)
  177.     LG2_BOOL = LONGBOOL;
  178.   (* Signed 8bit integer.
  179.     Note that it isn't Pascal's CHAR type! *)
  180.     LG2_CHAR = LG2_INT8;
  181.   (* Unsigned 8bit integer values. *)
  182.     LG2_UCHAR = LG2_UINT8;
  183.   (* Signed 16bit integer values. *)
  184.     LG2_SHORT = LG2_INT16;
  185.   (* Unsigned 16bit integer values. *)
  186.     LG2_USHORT = LG2_UINT16;
  187.   (* Signed 32bit integer values. *)
  188.     LG2_INT = LG2_INT32;
  189.   (* Unsigned 32bit integer values. *)
  190.     LG2_UINT = LG2_UINT32;
  191. {$IFDEF CPU64}
  192.   {$IFDEF WINDOWS}
  193.   (* Signed 32/64bit integer values. *)
  194.     LG2_LONG = LG2_INT32;
  195.   (* Unsigned 32/64bit integer values. *)
  196.     LG2_ULONG = LG2_UINT32;
  197.   {$ELSE}
  198.   (* Signed 32/64bit integer values. *)
  199.     LG2_LONG = LG2_INT64;
  200.   (* Unsigned 32/64bit integer values. *)
  201.     LG2_ULONG = LG2_UINT64;
  202.   {$ENDIF}
  203.   (* size_t equivalent. *)
  204.     LG2_SIZE_T = LG2_UINT64;
  205.   (* Fake pointer type.  It's needed to pass pointers as integer values in some
  206.      methods. *)
  207.     LG2_INTPTR_T = LG2_INT64;
  208.   (* Fake pointer type.  It's needed to pass pointers as integer values in some
  209.      methods. *)
  210.     LG2_UINTPTR_T = LG2_UINT64;
  211. {$ELSE}
  212.   (* Signed 32/64bit integer values. *)
  213.     LG2_LONG = LG2_INT32;
  214.   (* Unsigned 32/64bit integer values. *)
  215.     LG2_ULONG = LG2_UINT32;
  216.   (* size_t equivalent. *)
  217.     LG2_SIZE_T = LG2_UINT32;
  218.   (* Fake pointer type.  It's needed to pass pointers as integer values in some
  219.      methods. *)
  220.     LG2_INTPTR_T = LG2_INT32;
  221.   (* Fake pointer type.  It's needed to pass pointers as integer values in some
  222.      methods. *)
  223.     LG2_UINTPTR_T = LG2_UINT32;
  224. {$ENDIF}
  225.  
  226.   (* Float value. *)
  227.     LG2_FLOAT = SINGLE;
  228.   (* Double value. *)
  229.     LG2_DOUBLE = DOUBLE;
  230.   (* Strings.  Used in parameters to convert Pascal's @code(STRING) to C's
  231.     @code(char * )*)
  232.     LG2_STR = AnsiString;
  233.     LG2_STR_RAW = ^byte;
  234.     PLG2_STR = ^LG2_STR;
  235.  
  236.   (* Pointer. *)
  237.     LG2_VOIDptr = LG2_POINTER;
  238.   (* Pointer to text strings.  Used to convert Pascal's @code(STRING) to C
  239.     @code(char * ) *)
  240.     LG2_STRptr = PAnsiChar;
  241.     PPAnsiChar = ^PAnsiChar;
  242.   (* Pointer to integer. *)
  243.     LG2_INTptr = ^LG2_INT;
  244.   (* Pointer to float. *)
  245.     LG2_FLOATptr = ^LG2_FLOAT;
  246.  
  247. const
  248.   GIT_SUCCESS = 0;
  249.   GIT_ERROR = -1;
  250.   GIT_OID_RAWSZ = 20;
  251.   GIT_OID_HEXSZ  = GIT_OID_RAWSZ * 2;
  252.   GIT_OID_MINPREFIXLEN = 4;
  253.  
  254. type
  255.  
  256.   {enums}
  257.   git_repository_item_t = (
  258.     GIT_REPOSITORY_ITEM_GITDIR,
  259.     GIT_REPOSITORY_ITEM_WORKDIR,
  260.     GIT_REPOSITORY_ITEM_COMMONDIR,
  261.     GIT_REPOSITORY_ITEM_INDEX,
  262.     GIT_REPOSITORY_ITEM_OBJECTS,
  263.     GIT_REPOSITORY_ITEM_REFS,
  264.     GIT_REPOSITORY_ITEM_PACKED_REFS,
  265.     GIT_REPOSITORY_ITEM_REMOTES,
  266.     GIT_REPOSITORY_ITEM_CONFIG,
  267.     GIT_REPOSITORY_ITEM_INFO,
  268.     GIT_REPOSITORY_ITEM_HOOKS,
  269.     GIT_REPOSITORY_ITEM_LOGS,
  270.     GIT_REPOSITORY_ITEM_MODULES,
  271.     GIT_REPOSITORY_ITEM_WORKTREES
  272.   );
  273.  
  274.   git_object_t = (
  275.     GIT_OBJECT_ANY = -2,
  276.     GIT_OBJECT_BAD = -1,
  277.     GIT_OBJECT_COMMIT = 1,
  278.     GIT_OBJECT_TREE = 2,
  279.     GIT_OBJECT_BLOB = 3,
  280.     GIT_OBJECT_TAG = 4,
  281.     GIT_OBJECT_OFS_DELTA = 6,
  282.     GIT_OBJECT_REF_DELTA = 7
  283.   );
  284.  
  285.   git_repository_state_t = (
  286.     GIT_REPOSITORY_STATE_NONE,
  287.     GIT_REPOSITORY_STATE_MERGE,
  288.     GIT_REPOSITORY_STATE_REVERT,
  289.     GIT_REPOSITORY_STATE_REVERT_SEQUENCE,
  290.     GIT_REPOSITORY_STATE_CHERRYPICK,
  291.     GIT_REPOSITORY_STATE_CHERRYPICK_SEQUENCE,
  292.     GIT_REPOSITORY_STATE_BISECT,
  293.     GIT_REPOSITORY_STATE_REBASE,
  294.     GIT_REPOSITORY_STATE_REBASE_INTERACTIVE,
  295.     GIT_REPOSITORY_STATE_REBASE_MERGE,
  296.     GIT_REPOSITORY_STATE_APPLY_MAILBOX,
  297.     GIT_REPOSITORY_STATE_APPLY_MAILBOX_OR_REBASE
  298.   );
  299.  
  300.   git_blame_flag_t = (
  301.     GIT_BLAME_NORMAL = 0,
  302.     GIT_BLAME_TRACK_COPIES_SAME_FILE = 1 shl 0,
  303.     GIT_BLAME_TRACK_COPIES_SAME_COMMIT_MOVES = 1 shl 1,
  304.     GIT_BLAME_TRACK_COPIES_SAME_COMMIT_COPIES = 1 shl 2,
  305.     GIT_BLAME_TRACK_COPIES_ANY_COMMIT_COPIES = 1 shl 3,
  306.     GIT_BLAME_FIRST_PARENT = 1 shl 4
  307.   );
  308.  
  309.   git_branch_t = (
  310.     GIT_BRANCH_LOCAL = 1,
  311.     GIT_BRANCH_REMOTE = 2,
  312.     GIT_BRANCH_ALL = 1 or 2
  313.   );
  314.  
  315.   git_checkout_strategy_t = (
  316.     GIT_CHECKOUT_NONE = 0,
  317.     GIT_CHECKOUT_SAFE = 1 shl 0,
  318.     GIT_CHECKOUT_FORCE = 1 shl 1,
  319.     GIT_CHECKOUT_RECREATE_MISSING = 1 shl 2,
  320.     GIT_CHECKOUT_ALLOW_CONFLICTS = 1 shl 4,
  321.     GIT_CHECKOUT_REMOVE_UNTRACKED = 1 shl 5,
  322.     GIT_CHECKOUT_REMOVE_IGNORED = 1 shl 6,
  323.     GIT_CHECKOUT_UPDATE_ONLY = 1 shl 7,
  324.     GIT_CHECKOUT_DONT_UPDATE_INDEX = 1 shl 8,
  325.     GIT_CHECKOUT_NO_REFRESH = 1 shl 9,
  326.     GIT_CHECKOUT_SKIP_UNMERGED = 1 shl 10,
  327.     GIT_CHECKOUT_USE_OURS = 1 shl 11,
  328.     GIT_CHECKOUT_USE_THEIRS = 1 shl 12,
  329.     GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH = 1 shl 13,
  330.     GIT_CHECKOUT_SKIP_LOCKED_DIRECTORIES = 1 shl 18,
  331.     GIT_CHECKOUT_DONT_OVERWRITE_IGNORED = 1 shl 19,
  332.     GIT_CHECKOUT_CONFLICT_STYLE_MERGE = 1 shl 20,
  333.     GIT_CHECKOUT_CONFLICT_STYLE_DIFF3 = 1 shl 21,
  334.     GIT_CHECKOUT_DONT_REMOVE_EXISTING = 1 shl 22,
  335.     GIT_CHECKOUT_DONT_WRITE_INDEX = 1 shl 23,
  336.     GIT_CHECKOUT_UPDATE_SUBMODULES = 1 shl 16,
  337.     GIT_CHECKOUT_UPDATE_SUBMODULES_IF_CHANGED = 1 shl 17
  338.   );
  339.  
  340.   git_checkout_notify_t = (
  341.     GIT_CHECKOUT_NOTIFY_NONE = 0,
  342.     GIT_CHECKOUT_NOTIFY_CONFLICT = 1 shl 0,
  343.     GIT_CHECKOUT_NOTIFY_DIRTY = 1 shl 1,
  344.     GIT_CHECKOUT_NOTIFY_UPDATED = 1 shl 2,
  345.     GIT_CHECKOUT_NOTIFY_UNTRACKED = 1 shl 3,
  346.     GIT_CHECKOUT_NOTIFY_IGNORED = 1 shl 4,
  347.     GIT_CHECKOUT_NOTIFY_ALL = $0FFFF
  348.   );
  349.  
  350.   git_attr_t = (
  351.     GIT_ATTR_UNSPECIFIED_T = 0,
  352.     GIT_ATTR_TRUE_T,
  353.     GIT_ATTR_FALSE_T,
  354.     GIT_ATTR_VALUE_T
  355.   );
  356.  
  357.   {records}
  358.  
  359.   git_buf = record
  360.     ptr: ^LG2_CHAR;
  361.     asize: LG2_SIZE_T;
  362.     size: LG2_SIZE_T;
  363.   end;
  364.  
  365.   git_time = record
  366.     time: LG2_UINT64;
  367.     offset: LG2_UINT64;
  368.     sign: LG2_CHAR;
  369.   end;
  370.  
  371.   git_signature = record
  372.     name: ^LG2_CHAR;
  373.     email: ^LG2_CHAR;
  374.     when: git_time;
  375.   end;
  376.   Pgit_signature = ^git_signature;
  377.  
  378.   git_repository_init_options = record
  379.     version: LG2_UINT32;
  380.     flags: LG2_UINT32;
  381.     mode: LG2_UINT32;
  382.     workdir_path: LG2_STR;
  383.     description: LG2_STR;
  384.     template_path: LG2_STR;
  385.     initial_head: LG2_STR;
  386.     origin_url: LG2_STR;
  387.   end;
  388.  
  389.   git_oid = record
  390.     id: array[0..(GIT_OID_RAWSZ)-1] of byte;
  391.   end;
  392.  
  393.   git_blame_options = record
  394.     version: LG2_DWORD;
  395.     flags: LG2_UINT32;
  396.     min_match_characters: LG2_UINT16;
  397.     newest_commit: git_oid;
  398.     oldest_commit: git_oid;
  399.     min_line: LG2_SIZE_T;
  400.     max_line: LG2_SIZE_T;
  401.   end;
  402.  
  403.   git_diff_file = record
  404.     id: git_oid;
  405.     path: LG2_STR;
  406.     size: LG2_OFF_T;
  407.     flags: LG2_UINT32;
  408.     mode: LG2_UINT32;
  409.     id_abbrev: LG2_UINT32;
  410.   end;
  411.   Pgit_diff_file = ^git_diff_file;
  412.  
  413.   git_checkout_perfdata = record
  414.     mkdir_calls: LG2_SIZE_T;
  415.     stat_calls: LG2_SIZE_T;
  416.     chmod_calls: LG2_SIZE_T;
  417.   end;
  418.   Pgit_checkout_perfdata = ^git_checkout_perfdata;
  419.  
  420.   git_blame_hunk = record
  421.     lines_in_hunk: LG2_SIZE_T;
  422.     final_commit_id: git_oid;
  423.     final_start_line_number : LG2_SIZE_T;
  424.     final_signature : Pgit_signature;
  425.     orig_commit_id : git_oid;
  426.     orig_path : LG2_STR;
  427.     orig_start_line_number : LG2_SIZE_T;
  428.     orig_signature : Pgit_signature;
  429.     boundary: LG2_CHAR;
  430.   end;
  431.   Pgit_blame_hunk = ^git_blame_hunk;
  432.  
  433.   Pgit_annotated_commit = LG2_POINTER;
  434.   PPgit_annotated_commit = ^Pgit_annotated_commit;
  435.   Pgit_buf = ^git_buf;
  436.   Pgit_commit = LG2_POINTER;
  437.   PPgit_commit = ^Pgit_commit;
  438.   Pgit_config = LG2_POINTER;
  439.   PPgit_config = ^Pgit_config;
  440.   Pgit_oid = ^git_oid;
  441.   Pgit_object = LG2_POINTER;
  442.   Pgit_blob = LG2_POINTER;
  443.   PPgit_blob = ^Pgit_blob;
  444.   Pgit_reference = LG2_POINTER;
  445.   PPgit_reference = ^Pgit_reference;
  446.   Pgit_repository = LG2_POINTER;
  447.   PPgit_repository = ^Pgit_repository;
  448.   Pgit_repository_init_options = ^git_repository_init_options;
  449.   Pgit_tag = LG2_POINTER;
  450.   Pgit_worktree = LG2_POINTER;
  451.   Pgit_odb = LG2_POINTER;
  452.   PPgit_odb = ^Pgit_odb;
  453.   Pgit_refdb = LG2_POINTER;
  454.   PPgit_refdb = ^Pgit_refdb;
  455.   Pgit_index = LG2_POINTER;
  456.   PPgit_index = ^Pgit_index;
  457.   Pgit_tree = LG2_POINTER;
  458.   PPgit_tree = ^Pgit_tree;
  459.   Pgit_blame = LG2_POINTER;
  460.   PPgit_blame = ^Pgit_blame;
  461.   Pgit_blame_options = ^git_blame_options;
  462.   Pgit_oid_shorten = LG2_POINTER;
  463.   Pgit_branch_iterator = LG2_POINTER;
  464.   PPgit_branch_iterator = ^Pgit_branch_iterator;
  465.   Pgit_branch_t = ^git_branch_t;
  466.   Pgit_writestream = LG2_POINTER;
  467.   PPgit_writestream = ^Pgit_writestream;
  468.  
  469.   git_repository_fetchhead_foreach_cb = function(const ref_name: LG2_STR; const remote_url: LG2_STR; const oid: Pgit_oid; is_merge: LG2_UINT; payload: LG2_POINTER): LG2_INT; cdecl;
  470.   git_repository_mergehead_foreach_cb = function(const oid: Pgit_oid; payload: LG2_POINTER): LG2_INT; cdecl;
  471.  
  472.   git_checkout_notify_cb = function (why: git_checkout_notify_t; path: LG2_STR; baseline: Pgit_diff_file; target: Pgit_diff_file; workdir: Pgit_diff_file; payload:LG2_VOIDptr): LG2_INT; cdecl;
  473.   git_checkout_progress_cb = procedure (path: LG2_STR; completed_steps: LG2_SIZE_T; total_steps: LG2_SIZE_T; payload:LG2_VOIDptr); cdecl;
  474.   git_checkout_perfdata_cb = procedure (path: LG2_STR; completed_steps: LG2_SIZE_T; total_steps: LG2_SIZE_T; payload:LG2_VOIDptr); cdecl;
  475.  
  476.   git_checkout_options = record
  477.     version: LG2_DWORD;
  478.     checkout_strategy: LG2_DWORD;
  479.     disable_filters: LG2_INT32;
  480.     dir_mode: LG2_DWORD;
  481.     file_mode: LG2_DWORD;
  482.     file_open_flags: LG2_INT32;
  483.     notify_flags: LG2_DWORD;
  484.     notify_cb: git_checkout_notify_cb;
  485.     notify_payload: LG2_VOIDptr;
  486.     progress_cb: git_checkout_progress_cb;
  487.     progress_payload: LG2_VOIDptr;
  488.     {paths : git_strarray;}
  489.     baseline: Pgit_tree;
  490.     baseline_index: Pgit_index;
  491.     target_directory: LG2_STR;
  492.     ancestor_label: LG2_STR;
  493.     our_label: LG2_STR;
  494.     their_label: LG2_STR;
  495.     perfdata_cb: git_checkout_perfdata_cb;
  496.     perfdata_payload: LG2_VOIDptr;
  497.   end;
  498.   Pgit_checkout_options = ^git_checkout_options;
  499.  
  500. { global.h }
  501. procedure git_libgit2_init(); cdecl; external LIBGIT2_LIB_NAME;
  502. procedure git_libgit2_shutdown(); cdecl; external LIBGIT2_LIB_NAME;
  503.  
  504. { annotated_commit.h }
  505. function git_annotated_commit_from_ref(const commit_out: PPgit_annotated_commit; const repo: PPgit_repository; const ref: Pgit_reference): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  506. function git_annotated_commit_from_fetchhead(const commit_out: PPgit_annotated_commit; const repo: PPgit_repository; const branch_name: LG2_STR; const remote_url: LG2_STR; const id: Pgit_oid): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  507. function git_annotated_commit_lookup(const commit_out: PPgit_annotated_commit; const repo: PPgit_repository; const id: Pgit_oid): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  508. function git_annotated_commit_from_revspec(const commit_out: PPgit_annotated_commit; const repo: PPgit_repository; const revspec: LG2_STR): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  509. function git_annotated_commit_id(const commit: Pgit_annotated_commit): Pgit_oid; cdecl; external LIBGIT2_LIB_NAME;
  510. procedure git_annotated_commit_free(commit: Pgit_annotated_commit); cdecl; external LIBGIT2_LIB_NAME;
  511.  
  512. { attr.h }
  513. function git_attr_value(const attr: LG2_STR): git_attr_t; cdecl; external LIBGIT2_LIB_NAME;
  514. function git_attr_get(var value_out: PAnsiChar; const repo: Pgit_repository; const flags: LG2_UINT32; const path: LG2_STR; const name: LG2_STR): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  515.  
  516. { blame.h }
  517. function git_blame_init_options(const opts: Pgit_blame_options; version: LG2_UINT32): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  518. function git_blame_get_hunk_count(blame: Pgit_blame): LG2_UINT32; cdecl; external LIBGIT2_LIB_NAME;
  519. function git_blame_get_hunk_byindex(const blame: Pgit_blame; const index: LG2_UINT32): Pgit_blame_hunk; cdecl; external LIBGIT2_LIB_NAME;
  520. function git_blame_get_hunk_byline(const blame: Pgit_blame; const lineno: LG2_SIZE_T): Pgit_blame_hunk; cdecl; external LIBGIT2_LIB_NAME;
  521. function git_blame_file(const blame_out: PPgit_blame; const repo: PPgit_repository; const path: LG2_STR; const opts: Pgit_blame_options): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  522. function git_blame_buffer(const blame_out: PPgit_blame; const blame_reference: PPgit_blame; const buffer: LG2_STR; const buffer_len: LG2_SIZE_T): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  523. procedure git_blame_free(blame: PPgit_blame); cdecl; external LIBGIT2_LIB_NAME;
  524.  
  525. { blob.h }
  526. function git_blob_lookup(var blob: PPgit_blob; const repo: Pgit_repository; const id: Pgit_oid): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  527. function git_blob_lookup_prefix(var blob: PPgit_blob; const repo: Pgit_repository; const id: Pgit_oid; const len: LG2_SIZE_T): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  528. procedure git_blob_free(const blob: Pgit_blob); cdecl; external LIBGIT2_LIB_NAME;
  529. function git_blob_id(const blob: Pgit_blob): Pgit_oid; cdecl; external LIBGIT2_LIB_NAME;
  530. function git_blob_owner(const blob: Pgit_blob): Pgit_repository; cdecl; external LIBGIT2_LIB_NAME;
  531. function git_blob_rawcontent(const blob: Pgit_blob): LG2_VOIDptr; cdecl; external LIBGIT2_LIB_NAME;
  532. function git_blob_rawsize(const blob: Pgit_blob): LG2_OFF_T; cdecl; external LIBGIT2_LIB_NAME;
  533. function git_blob_filtered_content(const buf_out: Pgit_buf; const blob: Pgit_blob; const as_path: LG2_STR; const check_for_binary_data: LG2_INT): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  534. function git_blob_create_fromworkdir(const oid: Pgit_oid; const repo: Pgit_repository; const relative_path: LG2_STR): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  535. function git_blob_create_fromdisk(const oid: Pgit_oid; const repo: Pgit_repository; const path: LG2_STR): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  536. function git_blob_create_fromstream(const out_stream: PPgit_writestream; const repo: Pgit_repository; const hintpath: LG2_STR): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  537. function git_blob_create_fromstream_commit(const out_oid: Pgit_oid; const stream: Pgit_writestream): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  538. function git_blob_create_frombuffer(const out_oid: Pgit_oid; const repo: Pgit_repository; const buffer: LG2_VOIDptr; const len: LG2_SIZE_T): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  539. function git_blob_is_binary(const blob: Pgit_blob): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  540. function git_blob_dup(const blob_out: PPgit_blob; const source: Pgit_blob): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  541.  
  542. { branch.h }
  543. function git_branch_create(var ref_out: PPgit_reference; const repo: PPgit_repository; const branch_name: LG2_STR; const target: Pgit_commit; const force: LG2_INT): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  544. function git_branch_create_from_annotated(const ref_out: PPgit_reference; const repo: PPgit_repository; const branch_name: LG2_STR; const target: Pgit_annotated_commit; const force: LG2_INT): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  545. function git_branch_delete(var branch: PPgit_reference): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  546. function git_branch_iterator_new(var iterator_out: PPgit_branch_iterator; const repo: PPgit_repository; const list_flags: git_branch_t): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  547. function git_branch_next(var ref_out: PPgit_reference; const out_type: Pgit_branch_t; const iter: Pgit_branch_iterator): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  548. procedure git_branch_iterator_free(iter: Pgit_branch_iterator); cdecl; external LIBGIT2_LIB_NAME;
  549. function git_branch_move(var branch_out: PPgit_reference; const branch_in: PPgit_reference; const new_branch_name: LG2_STR; const force: LG2_INT): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  550. function git_branch_lookup(var branch_out: PPgit_reference; const branch_in: PPgit_reference; const branch_name: LG2_STR; const branch_type: git_branch_t): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  551. function git_branch_name(var branch_out: PPgit_reference; const ref: PPgit_reference): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  552. function git_branch_upstream(var branch_out: PPgit_reference; const branch: PPgit_reference): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  553. function git_branch_set_upstream(var branch: Pgit_reference; const upstream_name: LG2_STR): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  554. function git_branch_upstream_name(var buf_out: Pgit_buf; const repo: Pgit_repository; const refname: LG2_STR): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  555. function git_branch_is_head(var branch: Pgit_reference): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  556. function git_branch_is_checked_out(var branch: Pgit_reference): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  557. function git_branch_remote_name(const buf_out: Pgit_buf; const repo: Pgit_repository; const canonical_branch_name: LG2_STR): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  558. function git_branch_upstream_remote(const buf_out: Pgit_buf; const repo: Pgit_repository; const refname: LG2_STR): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  559.  
  560. { buffer.h }
  561. procedure git_buf_free(var buffer: Pgit_buf); cdecl; external LIBGIT2_LIB_NAME;
  562. function git_buf_grow(var buffer: Pgit_buf; const target_size: LG2_SIZE_T): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  563. function git_buf_set(var buffer: Pgit_buf; const data: LG2_VOIDptr; const datalen: LG2_SIZE_T): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  564. function git_buf_is_binary(const buffer: Pgit_buf): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  565. function git_buf_contains_nul(const buffer: Pgit_buf): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  566.  
  567. { checkout.h }
  568. function git_checkout_init_options(const opts: Pgit_checkout_options; const version: LG2_DWORD): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  569. function git_checkout_head(const repo: Pgit_repository; const opts: Pgit_checkout_options): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  570. function git_checkout_index(const repo: Pgit_repository; const index: Pgit_index; const opts: Pgit_checkout_options): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  571. function git_checkout_tree(const repo: Pgit_repository; const treeish: Pgit_object; const opts: Pgit_checkout_options): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  572.  
  573. { commit.h }
  574. function git_commit_lookup(const commit: PPgit_commit; repo: Pgit_repository; const id: Pgit_oid): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  575. function git_commit_lookup_prefix(const commit: PPgit_commit; repo: Pgit_repository; const id: Pgit_oid; len: LG2_SIZE_T): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  576. procedure git_commit_free(commit: Pgit_commit); cdecl; external LIBGIT2_LIB_NAME;
  577. function git_commit_id(const commit: Pgit_commit): Pgit_oid; cdecl; external LIBGIT2_LIB_NAME;
  578. function git_commit_owner(const commit: Pgit_commit): Pgit_repository; cdecl; external LIBGIT2_LIB_NAME;
  579. function git_commit_message_encoding(const commit: Pgit_commit): LG2_STR; cdecl; external LIBGIT2_LIB_NAME;
  580. function git_commit_message(const commit: Pgit_commit): LG2_STR; cdecl; external LIBGIT2_LIB_NAME;
  581. function git_commit_message_raw(const commit: Pgit_commit): LG2_STR; cdecl; external LIBGIT2_LIB_NAME;
  582. function git_commit_summary(const commit: Pgit_commit): LG2_STR; cdecl; external LIBGIT2_LIB_NAME;
  583. function git_commit_body(const commit: Pgit_commit): LG2_STR; cdecl; external LIBGIT2_LIB_NAME;
  584. function git_commit_time(const commit: Pgit_commit): LG2_TIME_T; cdecl; external LIBGIT2_LIB_NAME;
  585. function git_commit_time_offset(const commit: Pgit_commit): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  586. function git_commit_committer(const commit: Pgit_commit): Pgit_signature; cdecl; external LIBGIT2_LIB_NAME;
  587. function git_commit_author(const commit: Pgit_commit): Pgit_signature; cdecl; external LIBGIT2_LIB_NAME;
  588. function git_commit_raw_header(const commit: Pgit_commit): LG2_STR; cdecl; external LIBGIT2_LIB_NAME;
  589. function git_commit_tree(var tree_out: PPgit_tree; const commit: Pgit_commit): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  590. function git_commit_tree_id(const commit: Pgit_commit): Pgit_oid; cdecl; external LIBGIT2_LIB_NAME;
  591. function git_commit_parentcount(const commit: Pgit_commit): LG2_UINT; cdecl; external LIBGIT2_LIB_NAME;
  592. function git_commit_parent(var commit_out: PPgit_commit; const commit: Pgit_commit; n: LG2_UINT): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  593. function git_commit_parent_id(const commit: Pgit_commit; n: LG2_UINT): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  594. function git_commit_nth_gen_ancestor(var ancestor: PPgit_commit; const commit: Pgit_commit; n: LG2_UINT): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  595. function git_commit_header_field(var buf_out: Pgit_buf; const commit: Pgit_commit; const field: LG2_STR): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  596. function git_commit_extract_signature(const signature: Pgit_signature; const signed_data: Pgit_buf; const repo: Pgit_repository; const commit_id: Pgit_oid; const field: LG2_STR): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  597. function git_commit_create(const id: Pgit_oid; const repo: Pgit_repository; const update_ref: LG2_STR; const author: Pgit_signature; const commiter: Pgit_signature; const message_encoding: LG2_STR; const message: LG2_STR; const tree: Pgit_tree; const parent_count: LG2_SIZE_T; const parents: PPgit_commit): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  598. function git_commit_create_v(const id: Pgit_oid; const repo: Pgit_repository; const update_ref: LG2_STR; const author: Pgit_signature; const commiter: Pgit_signature; const message_encoding: LG2_STR; const message: LG2_STR; const tree: Pgit_tree; const parent_count: LG2_SIZE_T; const parents: PPgit_commit; args:array of const): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  599. function git_commit_amend(const id: Pgit_oid; const commit_to_amend: Pgit_commit; const update_ref: LG2_STR; const author: Pgit_signature; const commiter: Pgit_signature; const message_encoding: LG2_STR; const message: LG2_STR; const tree: Pgit_tree): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  600. function git_commit_create_buffer(var buf_out: Pgit_buf; const repo: Pgit_repository; const author: Pgit_signature; const commiter: Pgit_signature; const message_encoding: LG2_STR; const message: LG2_STR; const tree: Pgit_tree; const parent_count: LG2_SIZE_T; const parents: PPgit_commit): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  601. function git_commit_create_with_signature(const id: Pgit_oid; const repo: Pgit_repository; const commit_content: LG2_STR; const signature: LG2_STR; const signature_field: LG2_STR): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  602. function git_commit_dup(var commit_out: PPgit_commit; const source: Pgit_commit): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  603.  
  604. { oid.h }
  605. function git_oid_fromstr(const oid: Pgit_oid; str: LG2_STR): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  606. function git_oid_fromstrp(const oid: Pgit_oid; str: LG2_STR): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  607. function git_oid_fromstrn(const oid: Pgit_oid; str: LG2_STR; length: LG2_SIZE_T): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  608. procedure git_oid_fromraw(const oid: Pgit_oid; str: LG2_STR; raw: LG2_STR_RAW); cdecl; external LIBGIT2_LIB_NAME;
  609. procedure git_oid_fmt(var out_str: LG2_STR; const oid: Pgit_oid); cdecl; external LIBGIT2_LIB_NAME;
  610. procedure git_oid_nfmt(var out_str: LG2_STR; n: LG2_SIZE_T; const oid: Pgit_oid); cdecl; external LIBGIT2_LIB_NAME;
  611. procedure git_oid_pathfmt(var out_str: LG2_STR; const oid: Pgit_oid); cdecl; external LIBGIT2_LIB_NAME;
  612. function git_oid_tostr_s(const oid: Pgit_oid): LG2_STR; cdecl; external LIBGIT2_LIB_NAME;
  613. function git_oid_tostr(var out_str: LG2_STR; n: LG2_SIZE_T; const oid: Pgit_oid): LG2_STR; cdecl; external LIBGIT2_LIB_NAME;
  614. procedure git_oid_cpy(var out_oid: Pgit_oid; const src_oid: Pgit_oid); cdecl; external LIBGIT2_LIB_NAME;
  615. function git_oid_cmp(const a_oid: Pgit_oid; const b_oid: Pgit_oid): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  616. function git_oid_equal(const a_oid: Pgit_oid; const b_oid: Pgit_oid): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  617. function git_oid_ncmp(const a_oid: Pgit_oid; const b_oid: Pgit_oid; const len: LG2_SIZE_T): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  618. function git_oid_streq(const oid: Pgit_oid; const str: LG2_STR): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  619. function git_oid_strcmp(const oid: Pgit_oid; const str: LG2_STR): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  620. function git_oid_iszero(const oid: Pgit_oid): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  621. function git_oid_shorten_new(const min_length: LG2_SIZE_T): Pgit_oid_shorten; cdecl; external LIBGIT2_LIB_NAME;
  622. function git_oid_shorten_add(const os: Pgit_oid_shorten; text_id: LG2_STR): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  623. procedure git_oid_shorten_free(const os: Pgit_oid_shorten); cdecl; external LIBGIT2_LIB_NAME;
  624.  
  625. { repository.h }
  626. function git_repository_open(var repo_out: PPgit_repository; const path: LG2_STR): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  627. function git_repository_open_from_worktree(var repo_out: PPgit_repository; var wt: Pgit_worktree): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  628. function git_repository_wrap_odb(var repo_out: PPgit_repository; var repo_odb: Pgit_odb): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  629. function git_repository_discover(var buf_out: Pgit_buf; const start_path: LG2_STR; across_fs: LG2_INT; const ceiling_dirs: LG2_STR): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  630. function git_repository_open_ext(var repo_out: PPgit_repository; const path: LG2_STR; flags: LG2_UINT32; const ceiling_dirs: LG2_STR): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  631. function git_repository_open_bare(var repo_out: PPgit_repository; const bare_path: LG2_STR): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  632. procedure git_repository_free(var repo: Pgit_repository); cdecl; external LIBGIT2_LIB_NAME;
  633. function git_repository_init(var repo_out: PPgit_repository; const path: LG2_STR; is_bare: LG2_BOOL): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  634. function git_repository_init_init_options(var opts: Pgit_repository_init_options; version: LG2_UINT32): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  635. function git_repository_init_ext(var repo_out: PPgit_repository; const repo_path: LG2_STR; var opts: Pgit_repository_init_options): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  636. function git_repository_head(var ref_out: PPgit_reference; repo: Pgit_repository): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  637. function git_repository_head_for_worktree(var ref_out: PPgit_reference; repo: Pgit_repository; const name: LG2_STR): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  638. function git_repository_head_detached(const repo: Pgit_repository): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  639. function git_repository_head_detached_for_worktree(repo: Pgit_repository; const name: LG2_STR): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  640. function git_repository_head_unborn(repo: Pgit_repository): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  641. function git_repository_is_empty(repo: Pgit_repository): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  642. function git_repository_item_path(var buf_out: Pgit_buf; const repo: Pgit_repository; const item: git_repository_item_t): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  643. function git_repository_path(const repo: Pgit_repository): LG2_STR; cdecl; external LIBGIT2_LIB_NAME;
  644. function git_repository_workdir(const repo: Pgit_repository): LG2_STR; cdecl; external LIBGIT2_LIB_NAME;
  645. function git_repository_commondir(const repo: Pgit_repository): LG2_STR; cdecl; external LIBGIT2_LIB_NAME;
  646. function git_repository_set_workdir(const repo: Pgit_repository; const workdir: LG2_STR; update_gitlink: LG2_INT): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  647. function git_repository_is_bare(const repo: Pgit_repository): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  648. function git_repository_is_worktree(const repo: Pgit_repository): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  649. function git_repository_config(var config_out: PPgit_config; repo: Pgit_repository): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  650. function git_repository_config_snapshot(var config_out: PPgit_config; repo: Pgit_repository): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  651. function git_repository_odb(var odb_out: PPgit_odb; repo: Pgit_repository): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  652. function git_repository_refdb(var refdb_out: PPgit_refdb; repo: Pgit_repository): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  653. function git_repository_index(var index_out: PPgit_index; repo: Pgit_repository): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  654. function git_repository_message(var buf_out: Pgit_buf; repo: Pgit_repository): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  655. function git_repository_message_remove(repo: Pgit_repository): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  656. function git_repository_state_cleanup(repo: Pgit_repository): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  657. function git_repository_fetchhead_foreach(repo: Pgit_repository; callback: git_repository_fetchhead_foreach_cb; payload: LG2_POINTER): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  658. function git_repository_mergehead_foreach(repo: Pgit_repository; callback: git_repository_mergehead_foreach_cb; payload: LG2_POINTER): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  659. function git_repository_hashfile(oid: Pgit_oid; repo: Pgit_repository; const path: LG2_STR; obj_type: git_object_t; const as_path: LG2_STR): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  660. function git_repository_set_head(repo: Pgit_repository; refname: LG2_STR): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  661. function git_repository_set_head_detached(repo: Pgit_repository; const commitish: Pgit_oid): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  662. function git_repository_set_head_detached_from_annotated(repo: Pgit_repository): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  663. function git_repository_detach_head(repo: Pgit_repository; const commitish: Pgit_annotated_commit): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  664. function git_repository_state(repo: Pgit_repository): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  665. function git_repository_set_namespace(repo: Pgit_repository; const nmspace: LG2_STR): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  666. function git_repository_get_namespace(repo: Pgit_repository): LG2_STR; cdecl; external LIBGIT2_LIB_NAME;
  667. function git_repository_is_shallow(repo: Pgit_repository): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  668. function git_repository_ident(var name: PLG2_STR; var email: PLG2_STR; const repo: Pgit_repository): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  669. function git_repository_set_ident(repo: Pgit_repository; const name: LG2_STR; const email: LG2_STR): LG2_INT; cdecl; external LIBGIT2_LIB_NAME;
  670.  
  671. type
  672.  
  673.   { SDK }
  674.  
  675.   TGitRepository = Class(TObject)
  676.     private
  677.       repo: PPgit_repository;
  678.       function GetWorkDir: AnsiString;
  679.       function GetCommonDir: AnsiString;
  680.       function GetPath: AnsiString;
  681.       function GetNamespace: AnsiString;
  682.       function GetName: string;
  683.       function GetEmail: string;
  684.       procedure SetNamespace(const namespace: AnsiString);
  685.     public
  686.       constructor Create(const repository_path: string);
  687.       destructor Destroy; override;
  688.       { API }
  689.       function IsEmpty: Boolean;
  690.       function IsBare: Boolean;
  691.       function IsWorkTree: Boolean;
  692.       function IsShallow: Boolean;
  693.       property WorkDir: AnsiString read GetWorkDir;
  694.       property CommonDir: AnsiString read GetCommonDir;
  695.       property Path: AnsiString read GetPath;
  696.       property Namespace: AnsiString read GetNamespace write SetNamespace;
  697.       property Name: string read GetName;
  698.       property Email: string read GetEmail;
  699.   end;
  700.  
  701.  
  702. implementation
  703.  
  704. { declarations }
  705.  
  706. constructor TGitRepository.Create(const repository_path: String);
  707. var name: string;
  708.     email: string;
  709. begin
  710.   if git_repository_open(repo, PAnsiChar(repository_path)) = GIT_SUCCESS then
  711.   begin
  712.     // Path := git_repository_path(repo^);
  713.     // Workdir := git_repository_workdir(repo^);
  714.     // Commondir := git_repository_commondir(repo^);
  715.     // git_repository_ident(LG2_STRptr(name), LG2_STRptr(email), repo^);
  716.     Logger.Send('TGitRepository.Create(open+ident:success): ' + Path);
  717.   end
  718.   else
  719.   begin
  720.     Logger.SendError('TGitRepository.Create(open:error): ' + repository_path);
  721.   end;
  722. end;
  723.  
  724. destructor TGitRepository.Destroy;
  725. begin
  726.   if repo <> nil then
  727.   begin
  728.     git_repository_free(repo^);
  729.     Logger.Send('TGitRepository.Destroy(free:success)');
  730.   end;
  731. end;
  732.  
  733. function TGitRepository.GetWorkDir(): AnsiString;
  734. begin
  735.   Result := git_repository_workdir(self.repo^);
  736. end;
  737.  
  738. function TGitRepository.GetCommonDir(): AnsiString;
  739. begin
  740.   Result := git_repository_commondir(self.repo^);
  741. end;
  742.  
  743. function TGitRepository.GetPath(): AnsiString;
  744. begin
  745.   Result := git_repository_path(self.repo^);
  746. end;
  747.  
  748. function TGitRepository.IsEmpty: boolean;
  749. begin
  750.   Result := git_repository_is_empty(repo^) = 1;
  751. end;
  752.  
  753. function TGitRepository.IsBare: boolean;
  754. begin
  755.   Result := git_repository_is_bare(repo^) = 1;
  756. end;
  757.  
  758. function TGitRepository.IsWorkTree: boolean;
  759. begin
  760.   Result := git_repository_is_worktree(repo^) = 1;
  761. end;
  762.  
  763. function TGitRepository.IsShallow: boolean;
  764. begin
  765.   Result := git_repository_is_shallow(repo^) = 1;
  766. end;
  767.  
  768. function TGitRepository.GetNamespace: AnsiString;
  769. begin
  770.   Result := git_repository_get_namespace(repo^);
  771. end;
  772. procedure TGitRepository.SetNamespace(const namespace: AnsiString);
  773. begin
  774.   git_repository_set_namespace(repo^, namespace);
  775. end;
  776.  
  777. function TGitRepository.GetName: string;
  778. var name: string;
  779.     email: string;
  780. begin
  781.   Result := name;
  782. end;
  783.  
  784. function TGitRepository.GetEmail: string;
  785. var name: string;
  786.     email: string;
  787. begin
  788.   Result := email;
  789. end;
  790.  
  791. initialization
  792. { Delphi forces an INITIALIZATION section if FINALIZATION is used. }
  793.   ;
  794. { Next code suggested by FPC mailing list user.  This should fix some issues
  795.   with memory.  Removed as it seems to be fixed by Allegro itself. }
  796.  
  797. { $if defined(cpui386) or defined(cpux86_64)}
  798. { SetExceptionMask(GetExceptionMask + [exZeroDivide, exInvalidOp]); }
  799. { $ENDIF}
  800.   git_libgit2_init;
  801.  
  802. finalization
  803.   git_libgit2_shutdown;
  804.  
  805. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement