forked from RogerGee/php-git2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DOCS.txt
3144 lines (1763 loc) · 69.9 KB
/
DOCS.txt
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
PHP libgit2 bindings API documentation
--------------------------------------------------------------------------------
The API is divided (roughly) by the kind of libgit2 object on which the API
function operates (e.g. git_repository, git_reference, ETC.). In most cases the
PHP API uses resource values for the major libgit2 opaque data types.
Since PHP has native exception handling, most API calls are reworked to return
the main result value and throw an exception on error. For example,
git_repository_new() returns a resource to the repository (originally assigned
to the first by-reference parameter). We also rework the structure of some
library calls due to inherent difficulties porting the C interface to PHP
(e.g. when pointers are used). Sometimes this requires adding API routines not
originally in the libgit2 specification.
Please consult the official libgit2 documentation for descriptions of the
behavior of the functions and their arguments. This section only details the PHP
interface.
--------------------------------------------------------------------------------
API Structure Reference
The following structures are represented as resources in the PHP API. They
generally represent opaque structures from the C API (but not necessarily).
Note that the PHP resource type names (which are really just diagnostic in
purpose) are determined by the C++ compiler via 'typeid'.
git2 type
---------
git_annotated_commit
git_blame
git_blob
git_branch_iterator
git_commit
git_config
git_config_iterator
git_cred
git_describe_result
git_diff
git_diff_stats
git_index
git_index_conflict_iterator
git_indexer
git_note
git_note_iterator
git_object
git_odb
git_odb_object
git_packbuilder
git_patch
git_rebase
git_refdb
git_reference
git_reference_iterator
git_reflog
git_refspec
git_remote
git_repository
git_revwalk
git_signature
git_status_list
git_submodule
git_tag
git_tree
git_tree_entry
git_treebuilder
The following structures are not represented as resources in the PHP
API. Instead a scalar, array or object type is used:
git2 type PHP type
--------- --------
git_blame_hunk array
git_buf string
git_cherrypick_options array
git_config_backend \GitConfigBackend
git_config_entry array
git_describe_format_options array
git_describe_options array
git_diff_binary array
git_diff_binary_file array
git_diff_delta array
git_diff_file array
git_diff_format_email_options array
git_diff_hunk array
git_diff_line array
git_diff_options array
git_index_entry array
git_merge_file_input array
git_merge_file_options array
git_merge_file_result array
git_merge_options array
git_odb_backend \GitODBBackend
git_odb_stream \GitODBStream
git_odb_writepack \GitODBWritepack
git_oid string
git_refdb_backend \GitRefDBBackend
git_reflog_entry array
git_revspec array
git_status_entry array
git_status_options array
git_writestream \GitWritestream
For objects, see the later section regarding Classes.
Enumeration types are treated as integers in PHP userspace. A global constant is
generally defined for enumerator. If an enumerator is missing, then it is
acceptable to define it yourself using "define(...)" or by just using the
correct constant value from the git2 headers.
--------------------------------------------------------------------------------
Error Handling
When an underlying libgit2 function fails with an error code, the extension will
throw an exception of type Git2Exception (see declaration below). The error code
returned is accessible via the $code property on the thrown exception.
Example:
function render_reference($repo,string $refName) {
try {
$oid = git_reference_name_to_id($repo,$refName);
echo "<p>The OID for <code>$refName</code> is <code>$oid</code></p>";
} catch (\Git2Exception $ex) {
if ($ex->getCode() == GIT_ENOTFOUND) {
echo '<p>Not Found</p>';
}
else {
throw $ex;
}
}
}
Declaration of exception class Git2Exception:
class Git2Exception extends RuntimeException
--------------------------------------------------------------------------------
Function API Reference
Core API routines operate on opaque, resource values. They try to conform to the
original, C library calls they wrap. Most if not all of these functions have the
prefix "git_".
Functions provided by the extension that are not git2 wrappers have the prefix
'git2_*'. These are provided as supplements or additions where appropriate.
----------------------------------------
[misc]
----------------------------------------
git2_version()
Gets a string representing the php-git2 and libgit2 version.
Returns string
git_libgit2_version()
Gets the libgit2 version string. The version string has the form "%1.%2.%3"
where %1, %2 and %3 are the respective major, minor and revision numbers
returned from the underlying call to git_libgit2_version().
Returns string
git_libgit2_features()
Returns int
----------------------------------------
[git_repository]
----------------------------------------
git_repository_init(string,bool)
Returns git_repository resource
git_repository_new()
Returns git_repository resource
git_repository_free(resource)
git_repository_open(string)
Returns git_repository resource
git_repository_open_bare(string)
Returns git_repository resource
git_repository__cleanup(resource)
git_repository_detach_head(resource)
Returns int
git_repository_fetchhead_foreach(resource,callable,mixed)
Callback signature: void callback(string $refName,string $remoteUrl,string $oid,bool $isMerge,mixed $payload)
git_repository_mergehead_foreach(resource,callable,mixed)
Callback signature: void callback(string $oid,mixed $payload)
git_repository_discover(string,bool,string)
Returns string
git_repository_get_namespace(resource)
Returns string
git_repository_hashfile(resource,string,long,string)
Returns string
git_repository_path(resource)
Returns string
git_repository_odb(resource)
Returns git_odb resource
git_repository_set_odb(resource,resource)
git_repository_set_head(resource,string)
git_repository_set_head_detached(resource,string)
Returns bool
git_repository_head(resource)
Returns git_reference resource
git_repository_is_empty(resource)
Returns bool
git_repository_is_bare(resource)
Returns bool
git_repository_is_shallow(resource)
Returns bool
git_repository_head_detached(resource)
Returns bool
git_repository_head_unborn(resource)
Returns bool
git_repository_ident(&string,repo)
** The returned string is the name. The assigned out-parameter is the
email. **
Returns string
git_repository_init_ext(string,array|null)
The final parameter is an array of options with keys corresponding to the
git_repository_init_options struct. If you do not specify an option key, it
will be filled in with the default value supplied via
git_repository_init_init_options. It may be null if you want to purely use
the defaults.
NOTE: the git2 extension does not implement
git_repository_init_init_options(). Just use an array to pass in init
options and it will be initialized for you behind-the-scenes.
Returns git_repository resource
git_repository_message(resource)
Returns string or false
git_repository_message_remove(resource)
git_repository_open_ext(string|null,int,string)
Returns git_repository resource
git_repository_reinit_filesystem(resource,bool)
git_repository_set_bare(resource)
git_repository_set_head_detached_from_annotated(resource,resource)
Returns bool
git_repository_set_ident(resource,string,string)
git_repository_set_namespace(resource,string)
git_repository_set_workdir(resource,string,bool)
git_repository_state(resource)
Returns int
git_repository_state_cleanup(resource)
git_repository_workdir(resource)
Returns string
git_repository_wrap_odb(resource)
Returns git_repository resource
git_repository_config(resource)
Returns git_config resource
git_repository_config_snapshot(resource)
Returns git_config resource
git_repository_set_config(resource,resource)
git_repository_index(resource)
Returns git_index resource
git_repository_set_index(resource,resource)
git_repository_refdb(resource)
Returns git_refdb resource
git_repository_set_refdb(resource,resource)
----------------------------------------
[git_reference]
----------------------------------------
git_reference_list(resource)
Returns array of string
git_reference_lookup(resource,string)
Returns git_reference resource
git_reference_free(resource)
git_reference_peel(resource,long)
Returns git_reference resource
git_reference_name_to_id(resource,string)
Returns string
git_reference_create(resource,string,string,bool,string)
Returns git_reference resource
git_reference_create_matching(resource,string,string,bool,string,string)
Returns git_reference resource
git_reference_target(resource)
Returns string
git_reference_target_peel(resource)
Returns string
git_reference_name(resource)
Returns string
int git_reference_cmp(resource $ref1,resource $ref2)
Returns the same return value as underlying library call.
git_reference__alloc(string,string,string)
Returns git_reference resource
git_reference__alloc_symbolic(string,string)
Returns git_reference resource
git_reference_delete(resource)
git_reference_dup(resource)
Returns git_reference resource
git_reference_ensure_log(resource,string)
git_reference_has_log(resource,string)
Returns bool
git_reference_is_branch(resource)
Returns bool
git_reference_is_note(resource)
Returns bool
git_reference_is_remote(resource)
Returns bool
git_reference_is_tag(resource)
Returns bool
git_reference_is_valid_name(string)
Returns bool
git_reference_iterator_new(resource)
Returns git_reference_iterator resource
git_reference_iterator_glob_new(resource)
Returns git_reference_iterator resource
git_reference_next(resource)
Returns git_reference resource or false if iteration is over
git_reference_next_name(resource)
Returns string or false if iteration is over
git_reference_normalize_name(string,int)
Returns string
git_reference_owner(resource)
Returns git_repository resource
git_reference_remove(resource,string)
git_reference_rename(resource,string,bool,string)
Returns git_reference resource
git_reference_resolve(resource)
Returns git_reference resource
git_reference_set_target(resource,string,string)
Returns git_reference resource
git_reference_shorthand(resource)
Returns string
git_reference_type(resource)
Returns int
git_reference_foreach(resource,callable,mixed)
Callback signature: void callback(resource $ref,mixed $payload)
The callback should throw on error.
git_reference_foreach_name(resource,callable,mixed)
Callback signature: void callback(string $name,mixed $payload)
The callback should throw on error.
git_reference_foreach_glob(resource,string,callable,mixed)
git_reference_symbolic_create(resource,string,string,bool,string)
Returns git_reference resource
git_reference_symbolic_create_matching(resource,string,string,bool,string,string)
Returns git_reference resource
git_reference_symbolic_set_target(resource,string,string)
Returns git_reference resource
git_reference_symbolic_target(resource)
Returns string
----------------------------------------
[git_object]
----------------------------------------
git_object_id(resource)
Returns string
git_object_lookup(resource,string,int)
Returns resource
git_object_free(resource)
git_object_peel(resource,int)
Returns git_object resource
git_object_dup(resource)
Returns git_object resource
git_object_lookup_bypath(resource,string,int)
Returns git_object resource
git_object_lookup_prefix(resource,string,int)
Returns git_object resource
git_object_owner(resource)
Returns git_repository resource
git_object_short_id(resource)
Returns string
git_object_string2type(string)
Returns int
git_object_type(resource)
Returns int
git_object_type2string(int)
Returns string
git_object_typeisloose(int)
Returns bool
----------------------------------------
[git_revwalk]
----------------------------------------
git_revwalk_new(resource)
git_revwalk_push(resource,string)
git_revwalk_next(resource)
Returns string or false when on iterover
git_revwalk_hide(resource,string)
git_revwalk_sorting(resource,int)
git_revwalk_reset(resource)
git_revwalk_free(resource)
git_revwalk_add_hide_cb(resource,callable,mixed)
Callback signature: void callback(string $commitId,mixed $payload)
The function should throw on error.
git_revwalk_hide_glob(resource,string)
git_revwalk_hide_head(resource)
git_revwalk_hide_ref(resource,string)
git_revwalk_push_glob(resource,string)
git_revwalk_push_head(resource)
git_revwalk_push_range(resource,string)
git_revwalk_push_ref(resource,string)
git_revwalk_repository(resource)
git_revwalk_simplify_first_parent(resource)
----------------------------------------
[git_packbuilder]
----------------------------------------
git_packbuilder_new(resource)
Returns git_packbuilder resource
git_packbuilder_free(resource)
git_packbuilder_hash(resource)
Returns string
git_packbuilder_insert_commit(resource,string)
git_packbuilder_insert_walk(resource,resource)
git_packbuilder_insert_recur(resource,string,string|null)
git_packbuilder_insert_tree(resource,string)
git_packbuilder_insert(resource,string,string|null)
git_packbuilder_foreach(resource,callable,mixed)
If the 3rd parameter is a stream and the 2nd parameter is null, then each
call will write the data to the stream.
Callback signature: void callback(string $data,int $length,mixed $payload)
The callback should return false to cancel the transaction.
The callback should throw on error.
git_packbuilder_set_threads(resource,int)
git_packbuilder_set_callbacks(resource,callable,mixed)
Callback signature: void callback(int $stage,int $current,int $total,mixed $payload)
The callback should throw on error.
git_packbuilder_object_count(resource)
Returns int
git_packbuilder_write(resource,string,int,callable,mixed)
Callback signature: callback(array $stats)
The $stats array has properties of the libgit2 git_transfer_progress
struct.
git_packbuilder_written(resource)
Returns int
----------------------------------------
[git_indexer]
----------------------------------------
resource git_indexer_new(string $path,int $mode,?resource $odb,?array $options)
$options: [
'progress_cb' => callable: void callback(array $stats,mixed $payload),
'progress_cb_payload' => mixed,
'verify' => bool,
]
Return git_indexer resource
git_indexer_hash(resource)
Returns string
git_indexer_append(resource,string)
** Transfer progress is stored in the resource. As such it is not passed to
this function. **
git_indexer_commit(resource)
** Transfer progress is stored in the resource. As such it is not passed to
this function. **
git_indexer_free(resource)
git2_indexer_stats(resource)
** To avoid the expense of translating a stats object every time and indexer
operation is performed, the user may call this to get the indexer
transfer progress stats at any time. The transfer progress structure is
stored in the indexer resource object. **
Returns array, associative array with git_transfer_progress fields
----------------------------------------
[git_odb]
[git_odb_object]
----------------------------------------
git_odb_new()
Return git_odb resource
git_odb_free(resource)
git_odb_write_pack(resource,callable,mixed)
** The 3rd parameter may be null. **
Returns object instance of type GitODBWritepack_Internal
git_odb_backend_pack(string)
Returns object instance of type GitODBBackend
git_odb_backend_loose(string,int,bool,int,int)
Returns object instance of type GitODBBackend
git_odb_backend_one_pack(string)
Returns object instance of type GitODBBackend
git_odb_open(string)
Returns git_odb resource
git_odb_write(resource,string,int)
Returns string
git_odb_read(resource,string)
Returns git_odb_object resource
git_odb_read_header(&int,resource,string)
Returns int (the size of the object)
git_odb_read_prefix(resource,string)
Returns git_odb_object resource
git_odb_object_free(resource)
git_odb_object_data(resource)
Returns string
git_odb_object_id(resource)
Returns string
git_odb_object_size(resource)
Returns int
git_odb_object_type(resource)
Returns int
git_odb_object_dup(resource)
Returns git_odb_object resource
GitODBStream git_odb_open_rstream(int &$len,int &$type,resource $odb,string $oid)
Returns object instance of type GitODBStream
git_odb_open_wstream(resource,int,int)
Returns object instance of type GitODBStream
git_odb_stream_read(GitODBStream,int)
** The 2nd parameter is the length of the buffer to allocate. **
Returns string
git_odb_stream_write(GitODBStream,string)
git_odb_stream_finalize_write(GitODBStream)
Returns string
git_odb_add_alternate(resource,GitODBBackend,int)
git_odb_add_disk_alternate(resource,string)
git_odb_add_backend(resource,GitODBBackend,int)
git_odb_exists(resource,string)
Returns bool
git_odb_exists_prefix(resource,string)
** This function throws when not found or ambiguous. It returns a string
when the object is found. **
Returns string
void git_odb_expand_ids(resource $odb,array &$ids)
Note: this function will return results in the $ids parameter. While this
parameter employs reference semantics, it is not technically passed by
reference in the implementation.
git_odb_foreach(resource,callable,mixed)
Callback signature: bool callback(string $oid,mixed $payload)
To stop iteration, the callback should return false.
The callback should throw on error.
git_odb_refresh(resource)
git_odb_get_backend(resource,int)
Returns object of type GitODBBackend
git_odb_num_backends(resource)
Returns int
git_odb_hash(string,int)
Returns string
git_odb_hashfile(string,int)
Returns string
----------------------------------------
[git_commit]
----------------------------------------
git_commit_lookup(resource,string)
Returns git_commit resource
git_commit_lookup_prefix(resource,string)
Returns git_commit resource
git_commit_parentcount(resource)
Returns int
git_commit_parent_id(resource,int)
Returns string
git_commit_parent(resource,int)
Returns git_commit resource
git_commit_nth_gen_ancestor(resource,int)
Returns git_commit resource
git_commit_id(resource)
Returns string
git_commit_free(resource)
git_commit_owner(resource)
Returns git_repository resource
git_commit_tree(resource)
Returns git_tree resource
git_commit_tree_id(resource)
Returns string
git_commit_time(resource)
Returns int
git_commit_time_offset(resource)
Returns int
git_commit_summary(resource)
Returns string
git_commit_raw_header(resource)
Returns string
git_commit_body(resource)
Returns string
git_commit_message(resource)
Returns string
git_commit_message_encoding(resource)
Returns string
git_commit_message_raw(resource)
Returns string
git_commit_author(resource)
Returns git_signature resource
git_commit_committer(resource)
Returns git_signature resource
git_commit_create(resource,string|null,resource,resource,string|null,string,resource,array)
Example:
$oid = git_commit_create($repo,$ref,$author,$committer,
$encoding,$message,$tree,$parents);
** The final parameter should be an array of git_commit resources; the size
is not previously passed in the PHP userspace version. **
Returns string containing the new commit's OID
git_commit_create_from_callback(resource,string|null,resource,resource,string|null,string,string,callable,mixed)
Example
$oid = git_commit_from_callback($repo,$ref,$author,$committer,$encoding,
$message,$treeId,$callable,$payload);
Callback signature: string callback(int $idx,mixed $payload)
This callback is not designed to report errors. If an error occures,
then the calling function will finish and the error will be logged as a
warning.
Returns string containing the new commit's OID
git_commit_create_from_ids(resource,string|null,resource,resource,string|null,string,string,array)
Example
$oid = git_commit_from_ids($repo,$ref,$author,$committer,$encoding,
$message,$treeId,$parents)
** The array should be a list of strings representing the parent commit
OIDs. **
Returns string containing the new commit's OID
git_commit_create_buffer(resource,resource,resource,string|null,string,resource,array)
Example:
$data = git_commit_create_buffer($repo,$author,$committer,
$encoding,$message,$tree,$parents);
** The final parameter should be an array of git_commit resources; the size
is not previously passed in the PHP userspace version. **
Returns string containing the commit object
git_commit_create_with_signature(resource,string,string,string)
Returns string
git_commit_amend(resource,string|null,resource|null,resource|null,string|null,string|null,resource|null)
** The arguments behavior like the C function in that NULL's are disregarded
when amending the commit. **
Returns string
git_commit_dup(resource)
Returns git_commit resource
git_commit_extract_signature(&string,resource,string,string|null)
** The signed data is written to the string out parameter. The signature is
returned. **
Returns string
git_commit_header_field(resource,string)
Returns string
----------------------------------------
[git_blob]
----------------------------------------
git_blob_create_frombuffer(resource,string)
Returns string