forked from Automattic/vip-go-ci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-repo.php
1862 lines (1631 loc) · 39 KB
/
git-repo.php
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
/**
* Local git repo functions.
*
* @package Automattic/vip-go-ci
*/
declare(strict_types=1);
/**
* Get version of git we are using
*
* @return string Git version number.
*/
function vipgoci_git_version(): string {
$cached_id = array(
__FUNCTION__,
);
$cached_data = vipgoci_cache( $cached_id );
$git_version_cmd = sprintf(
'%s %s',
escapeshellcmd( 'git' ),
escapeshellarg( '--version' )
);
vipgoci_log(
'Getting git version...' .
vipgoci_cached_indication_str( $cached_data ),
array(
'cmd' => $git_version_cmd,
)
);
if ( false !== $cached_data ) {
return $cached_data;
}
/*
* Actually execute
*/
$git_output = '';
$git_result_code = -255;
$git_version_results = vipgoci_runtime_measure_exec_with_retry(
$git_version_cmd,
array( 0 ),
$git_output,
$git_result_code,
'git_cli',
false
);
$log_detail = array(
'cmd' => $git_version_cmd,
'cmd_result_code' => $git_result_code,
'output' => $git_output,
);
if ( null === $git_version_results ) {
vipgoci_sysexit(
'Unable to run git due to error',
$log_detail,
VIPGOCI_EXIT_SYSTEM_PROBLEM
);
} elseif ( false === str_contains( $git_output, 'git version' ) ) {
vipgoci_sysexit(
'Unable to retrieve git version',
$log_detail,
VIPGOCI_EXIT_SYSTEM_PROBLEM
);
} else {
$git_version_results = $git_output;
}
$git_version_results = str_replace(
array( 'git', 'version', ' ', PHP_EOL ),
array( '', '', '', '' ),
$git_version_results
);
vipgoci_cache( $cached_id, $git_version_results );
return $git_version_results;
}
/**
* Determine if repository specified is in
* sync with the commit-ID specified.
*
* If it is not in sync, exit with error.
*
* @param string $commit_id Current commit-ID.
* @param string $local_git_repo Path to local git repository.
*
* @return void Exits with error if repository does not exist or is not in sync.
*/
function vipgoci_gitrepo_ok(
string $commit_id,
string $local_git_repo
) :void {
/*
* Check at what revision the local git repository is.
*
* We do this to make sure the local repository
* is actually checked out at the same commit
* as the one we are working with.
*/
$lgit_head = vipgoci_gitrepo_get_head(
$local_git_repo
);
/*
* Check if commit-ID and head are the same, and
* return with a status accordingly.
*/
if (
( false !== $commit_id ) &&
( $commit_id !== $lgit_head )
) {
vipgoci_sysexit(
'Can not use local Git repository, seems not to be in ' .
'sync with current commit or does not exist',
array(
'commit_id' => $commit_id,
'local_git_repo' => $local_git_repo,
'local_git_repo_head' => $lgit_head,
),
VIPGOCI_EXIT_USAGE_ERROR
);
}
}
/**
* Verify that given string is of valid commit-ID format.
* Does not verify that it exists.
*
* @param string $commit_id Git commit-ID.
*
* @return bool True when it is of valid format, else false.
*/
function vipgoci_gitrepo_commit_id_validate_format(
string $commit_id
) :bool {
return (
( ctype_xdigit( $commit_id ) ) &&
( 40 === strlen( $commit_id ) )
);
}
/**
* Get latest commit HEAD in the specified repository.
* Will return a commit-hash if successful. Note that
* this function will execute git.
*
* @param string $local_git_repo Path to local git repository.
*
* @return string Latest commit-ID in the repository's current branch.
*/
function vipgoci_gitrepo_get_head(
string $local_git_repo
) :string {
/*
* Prepare to execute git; ask git to
* operate within a certain path ( -C param ),
* to fetch log (one line), and print only
* the hash-ID. Catch anything returned to STDERR.
*/
$cmd = sprintf(
'%s -C %s log -n %s --pretty=format:"%s"',
escapeshellcmd( 'git' ),
escapeshellarg( $local_git_repo ),
escapeshellarg( (string) 1 ),
escapeshellarg( '%H' )
);
/*
* Actually execute
*/
$result_output = '';
$result_code = -255;
$result = vipgoci_runtime_measure_exec_with_retry(
$cmd,
array( 0 ),
$result_output,
$result_code,
'git_cli',
false
);
$log_detail = array(
'cmd' => $cmd,
'cmd_result_code' => $result_code,
'output' => $result,
'result_output' => $result_output,
);
if ( null === $result ) {
vipgoci_sysexit(
'Unable to run git due to error',
$log_detail,
VIPGOCI_EXIT_SYSTEM_PROBLEM
);
}
/*
* If string, trim any whitespace characters away.
* Validation is then performed.
*/
if ( is_string( $result_output ) ) {
$result_output = trim(
$result_output
);
$result_output = trim(
$result_output,
"'\""
);
}
/*
* Validate the outputted string. Exit if it does not validate.
*/
if (
( ! is_string( $result_output ) ) ||
( false === vipgoci_gitrepo_commit_id_validate_format( $result_output ) )
) {
vipgoci_sysexit(
'Unexpected git commit-ID retrieved',
$log_detail,
VIPGOCI_EXIT_SYSTEM_PROBLEM
);
}
return $result_output;
}
/**
* Get the current branch of git repository specified.
*
* @param string $local_git_repo Path to local git repository.
*
* @return null|string Current branch as string on success, null on failure.
*/
function vipgoci_gitrepo_branch_current_get(
string $local_git_repo
) :null|string {
$cmd = sprintf(
'%s -C %s branch',
escapeshellcmd( 'git' ),
escapeshellarg( $local_git_repo ),
);
/*
* Actually execute
*/
$results_output = '';
$results_result_code = -255;
$results = vipgoci_runtime_measure_exec_with_retry(
$cmd,
array( 0 ),
$results_output,
$results_result_code,
'git_cli',
true
);
if ( null === $results ) {
vipgoci_sysexit(
'Unable to run git due to error',
array(
'cmd' => $cmd,
'output' => $results,
),
VIPGOCI_EXIT_SYSTEM_PROBLEM
);
}
/*
* Split results into array
*/
$results = explode(
"\n",
$results
);
/*
* Filter away any branch-names that are not active.
*/
$results = array_filter(
$results,
function( $line ) {
if ( false === strpos(
$line,
'*'
) ) {
return false;
}
return true;
}
);
/*
* Remove spaces and "*" from
* the last branch-name, which is the
* active one if there at all.
*/
$results = array_map(
function( $line ) {
return str_replace(
array(
' ',
'*',
),
array(
'',
'',
),
$line
);
},
$results
);
/*
* Recreate array with
* new index keys.
*/
$results = array_values(
$results
);
if ( ! empty(
$results
) ) {
return $results[0];
} else {
return null;
}
}
/**
* Fetch "tree" of the repository; a tree
* of files that are part of the commit
* specified.
*
* Allows filtering out files that the
* caller does only want to see.
*
* @param array $options Options array for the program.
* @param string $commit_id Commit-ID of current commit.
* @param null|array $filter Filter to apply.
*
* @return array Array with files in repository as items.
*/
function vipgoci_gitrepo_fetch_tree(
array $options,
string $commit_id,
null|array $filter = null
) :array {
// Check for cached version.
$cached_id = array(
__FUNCTION__,
$options['repo-owner'],
$options['repo-name'],
$commit_id,
$options['token'],
$filter,
);
$cached_data = vipgoci_cache( $cached_id );
vipgoci_log(
'Fetching tree info' . vipgoci_cached_indication_str( $cached_data ),
array(
'repo_owner' => $options['repo-owner'],
'repo_name' => $options['repo-name'],
'commit_id' => $commit_id,
'filter' => $filter,
)
);
if ( false !== $cached_data ) {
return $cached_data;
}
vipgoci_gitrepo_ok(
$commit_id,
$options['local-git-repo']
);
// Actually get files.
$files_arr = vipgoci_scandir_git_repo(
$options['local-git-repo'],
true,
$filter
);
/*
* Cache the results and return
*/
vipgoci_cache(
$cached_id,
$files_arr
);
return $files_arr;
}
/**
* Fetch from the local git repository a particular file
* which is a part of a commit. Will return the file (raw),
* or false on error.
*
* @param string $repo_owner Repository owner.
* @param string $repo_name Repository name.
* @param string $github_token GitHub token to use to make GitHub API requests.
* @param string $commit_id Current commit-ID.
* @param string $file_name File name whose content to fetch.
* @param string $local_git_repo Path to local git repository.
*
* @return false|string String with file contents on success, false on failure.
*/
function vipgoci_gitrepo_fetch_committed_file(
string $repo_owner,
string $repo_name,
string $github_token,
string $commit_id,
string $file_name,
string $local_git_repo
) :false|string {
vipgoci_gitrepo_ok(
$commit_id,
$local_git_repo
);
vipgoci_log(
'Fetching file-contents from local Git repository',
array(
'repo_owner' => $repo_owner,
'repo_name' => $repo_name,
'commit_id' => $commit_id,
'filename' => $file_name,
'local_git_repo' => $local_git_repo,
)
);
/*
* If everything seems fine, return the file.
*/
vipgoci_runtime_measure( VIPGOCI_RUNTIME_START, 'git_repo_fetch_file' );
$file_contents_tmp = @file_get_contents( // phpcs:ignore WordPress.PHP.NoSilencedErrors
$local_git_repo . '/' . $file_name
);
vipgoci_runtime_measure( VIPGOCI_RUNTIME_STOP, 'git_repo_fetch_file' );
return $file_contents_tmp;
}
/**
* Get 'git blame' log for a particular file,
* using a local Git repository.
*
* @param string $commit_id Commit-ID to use.
* @param string $file_name File name whose 'git blame' to get.
* @param string $local_git_repo Path to local git repository.
*
* @return array Blame log entries, one line per array item.
*/
function vipgoci_gitrepo_blame_for_file(
string $commit_id,
string $file_name,
string $local_git_repo
): array {
vipgoci_gitrepo_ok(
$commit_id,
$local_git_repo
);
vipgoci_runtime_measure( VIPGOCI_RUNTIME_START, 'git_repo_blame_for_file' );
vipgoci_log(
'Fetching \'git blame\' log from Git repository for file',
array(
'commit_id' => $commit_id,
'file_name' => $file_name,
'local_git_repo' => $local_git_repo,
)
);
/*
* Compose command to get blame-log
*/
$cmd = sprintf(
'%s -C %s blame --line-porcelain %s',
escapeshellcmd( 'git' ),
escapeshellarg( $local_git_repo ),
escapeshellarg( $file_name )
);
/*
* Actually execute
*/
$result_output = '';
$result_code = -255;
$result = vipgoci_runtime_measure_exec_with_retry(
$cmd,
array( 0 ),
$result_output,
$result_code,
'git_cli',
true
);
if ( null === $result ) {
vipgoci_sysexit(
'Unable to run git due to error',
array(
'cmd' => $cmd,
'output' => $result,
),
VIPGOCI_EXIT_SYSTEM_PROBLEM
);
}
/*
* Process the output from git,
* split each line into an array.
*/
$blame_log = array();
$result = explode(
"\n",
$result
);
$current_commit = array();
foreach ( $result as $result_line ) {
/*
* First split the line into an array
*/
$result_line_arr = explode(
' ',
$result_line
);
/*
* Try to figure out if the line is contains
* a commit-ID and line-number, such as this:
*
* 6c85fe619e39cc7beefb1faf0102d9d872bc7bb2 3 3
*
* and if so, store them.
*/
if (
( count( $result_line_arr ) >= 3 ) &&
( true === vipgoci_gitrepo_commit_id_validate_format( $result_line_arr[0] ) )
) {
$current_commit = array(
'commit_id' => $result_line_arr[0], // Commit-ID field.
'number' => $result_line_arr[2], // Line number field.
);
} elseif (
( count( $result_line_arr ) >= 2 ) &&
( 'filename' === $result_line_arr[0] )
) {
/*
* When the first string on the line is 'filename',
* store the filename it self. Do so using
* a method that will save spaces and so forth in the
* filename.
*/
$tmp_file_arr = $result_line_arr;
unset( $tmp_file_arr[0] );
$current_commit['filename'] = implode( ' ', $tmp_file_arr );
unset( $tmp_file_arr );
} elseif (
( count( $result_line_arr ) >= 1 ) &&
( in_array(
$result_line_arr[0],
array(
'author',
'author-mail',
'author-time',
'author-tz',
'boundary',
'committer',
'committer-mail',
'committer-time',
'committer-tz',
'summary',
'previous',
),
true
) )
) {
/*
* If we see any of these keywords,
* ignore them.
*/
continue;
} elseif (
( isset( $result_line[0] ) ) &&
( ord( $result_line[0] ) === 9 )
) {
/*
* When line starts with a tab,
* this is our code -- save that.
*/
$tmp_content = substr(
$result_line,
1
);
$current_commit['content'] = $tmp_content;
}
/*
* If we have got commit-ID, line-number, content
* and filename, we can construct a return array
*/
if (
( isset( $current_commit['commit_id'] ) ) &&
( isset( $current_commit['number'] ) ) &&
( isset( $current_commit['filename'] ) ) &&
( isset( $current_commit['content'] ) )
) {
$blame_log[] = array(
'commit_id' => $current_commit['commit_id'],
'file_name' => $current_commit['filename'],
'line_no' => (int) $current_commit['number'],
'content' => $current_commit['content'],
);
$current_commit = array();
}
}
vipgoci_runtime_measure( VIPGOCI_RUNTIME_STOP, 'git_repo_blame_for_file' );
return $blame_log;
}
/**
* Get contents of a particular file at a
* particular commit-ID from the local git
* repository.
*
* @param string $commit_id Commit-ID to use.
* @param string $file_name File name whose content to get.
* @param string $local_git_repo Path to local git repository.
* @param string $local_git_repo_head_commit_id Commit-ID of HEAD of local git repository (for verification).
*
* @return null|string File contents as string on success, null on failure.
*/
function vipgoci_gitrepo_get_file_at_commit(
string $commit_id,
string $file_name,
string $local_git_repo,
string $local_git_repo_head_commit_id
) :null|string {
/*
* Check if repository is looking good.
*/
vipgoci_gitrepo_ok(
$local_git_repo_head_commit_id,
$local_git_repo
);
vipgoci_runtime_measure( VIPGOCI_RUNTIME_START, 'git_repo_get_file_at_commit' );
vipgoci_log(
'Fetching contents of a particular file from the local git repository',
array(
'commit_id' => $commit_id,
'file_name' => $file_name,
'local_git_repo' => $local_git_repo,
'local_git_repo_head_commit_id' => $local_git_repo_head_commit_id,
)
);
/*
* Compose command to get the file contents.
*/
$cmd = sprintf(
'%s -C %s show %s:%s',
escapeshellcmd( 'git' ),
escapeshellarg( $local_git_repo ),
escapeshellarg( $commit_id ),
escapeshellarg( $file_name )
);
/*
* Actually execute
*/
$result_output = '';
$result_code = -255;
$result = vipgoci_runtime_measure_exec_with_retry(
$cmd,
array( 0, 128 ),
$result_output,
$result_code,
'git_cli',
true
);
if ( null === $result ) {
vipgoci_sysexit(
'Unable to run git due to error',
array(
'cmd' => $cmd,
'output' => $result,
),
VIPGOCI_EXIT_SYSTEM_PROBLEM
);
}
vipgoci_runtime_measure( VIPGOCI_RUNTIME_STOP, 'git_repo_get_file_at_commit' );
/*
* If the file did not exist in
* this revision, return null.
*/
if ( strpos(
strtolower( $result ),
'fatal: path '
) === 0 ) {
return null;
}
return $result;
}
/**
* Initialise submodules for the given local git repository.
*
* @param string $local_git_repo Path to local git repository.
*
* @return string Result of running "submodule init" and
* "submodule update" on success. Will exit
* on failure.
*/
function vipgoci_gitrepo_submodules_setup(
string $local_git_repo
) :string {
$cmd = sprintf(
'( %s -C %s submodule init && %s -C %s submodule update )',
escapeshellcmd( 'git' ),
escapeshellarg( $local_git_repo ),
escapeshellcmd( 'git' ),
escapeshellarg( $local_git_repo )
);
/*
* Actually execute
*/
$result_output = '';
$result_code = -255;
$result = vipgoci_runtime_measure_exec_with_retry(
$cmd,
array( 0 ),
$result_output,
$result_code,
'git_cli',
true
);
if ( null === $result ) {
vipgoci_sysexit(
'Unable to run git due to error',
array(
'cmd' => $cmd,
'output' => $result,
),
VIPGOCI_EXIT_SYSTEM_PROBLEM
);
}
return $result;
}
/**
* Get submodules for the given local git repository.
*
* @param string $local_git_repo Path to local git repository.
*
* @return array Submodules present as array, each submodule as associative array.
*/
function vipgoci_gitrepo_submodules_list(
string $local_git_repo
) :array {
/* Check for cached version */
$cached_id = array(
__FUNCTION__,
$local_git_repo,
);
$cached_data = vipgoci_cache( $cached_id );
if ( false !== $cached_data ) {
/* Found cached version, return it. */
return $cached_data;
}
/*
* No cached version found, get submodule list,
* process and return.
*/
$cmd = sprintf(
'%s -C %s submodule',
escapeshellcmd( 'git' ),
escapeshellarg( $local_git_repo ),
);
/*
* Actually execute
*/
$result_output = '';
$result_code = -255;
$result = vipgoci_runtime_measure_exec_with_retry(
$cmd,
array( 0 ),
$result_output,
$result_code,
'git_cli',
true
);
if ( null === $result ) {
vipgoci_sysexit(
'Unable to run git due to error',
array(
'cmd' => $cmd,
'output' => $result,
),
VIPGOCI_EXIT_SYSTEM_PROBLEM
);
}
$result = explode(
"\n",
$result
);
/*
* Clean up results, remove whitespace etc.
*/
$result = array_map(
function( $str ) {
$str = trim(
$str
);
$arr = explode(
' ',
$str
);
if ( count( $arr ) !== 3 ) {
return array();
}
$arr[2] = trim(
$arr[2],
'()'
);
return array(
'commit_id' => $arr[0],
'submodule_path' => $arr[1],
'submodule_tag' => $arr[2],
);
},
$result
);
/*
* Remove any array items that seem invalid.
*/
$result = array_filter(
$result,
function( $arr_item ) {
if ( count( $arr_item ) === 3 ) {
return true;
}
return false;
}
);
/*
* Cache result.
*/
vipgoci_cache(
$cached_id,
$result
);
return $result;
}
/**
* Get submodule for the given path,
* if is a submodule.
*
* @param string $local_git_repo Path to local git repository.
* @param string $file_path Relative path to file.
*
* @return null|array Submodule array on success, null on failure.
*/
function vipgoci_gitrepo_submodule_file_path_get(
string $local_git_repo,
string $file_path
) :null|array {
$submodules_list = vipgoci_gitrepo_submodules_list(
$local_git_repo
);
foreach (
$submodules_list as $submodule_item
) {
if ( strpos(
$file_path,
$submodule_item['submodule_path'] . '/'
) === 0 ) {
return $submodule_item;
}
}
return null;
}
/**
* Get URL for submodule from repository config.
*
* @param string $local_git_repo Path to local git repository.
* @param string $submodule_path Relative path to submodule.
*
* @return null|string Submodule URL as string on success, null on failure.
*/
function vipgoci_gitrepo_submodule_get_url(
string $local_git_repo,
string $submodule_path
) :null|string {
/* Check for cached version */
$cached_id = array(
__FUNCTION__,
$local_git_repo,
$submodule_path,
);
$cached_data = vipgoci_cache( $cached_id );
vipgoci_log(
'Fetching GitHub repository URL for submodule' .
vipgoci_cached_indication_str( $cached_data ),
array(
'local-git-repo' => $local_git_repo,
'submodule_path' => $submodule_path,
)
);
if ( false !== $cached_data ) {
/* Found cached version, return it. */
return $cached_data;
}
$git_modules_parsed = parse_ini_file(
$local_git_repo . '/.gitmodules',
true
);
if ( false === $git_modules_parsed ) {
return null;
}
$ret_val = null;