@@ -777,96 +777,59 @@ export interface Submodule {
777
777
}
778
778
779
779
export function parseGitmodules ( raw : string ) : Submodule [ ] {
780
- const result : Submodule [ ] = [ ] ;
781
-
782
- for ( const submoduleSection of parseGitConfig ( raw , 'submodule' ) ) {
783
- if ( submoduleSection . label && submoduleSection . properties [ 'path' ] && submoduleSection . properties [ 'url' ] ) {
784
- result . push ( {
785
- name : submoduleSection . label ,
786
- path : submoduleSection . properties [ 'path' ] ,
787
- url : submoduleSection . properties [ 'url' ]
788
- } ) ;
789
- }
790
- }
791
-
792
- return result ;
793
- }
794
-
795
- interface GitConfigSection {
796
- label ?: string ;
797
- properties : { [ key : string ] : string } ;
798
- }
799
-
800
- function parseGitConfig ( raw : string , section : string ) : Iterable < GitConfigSection > {
801
- const sections : GitConfigSection [ ] = [ ] ;
802
-
803
- const sectionHeaderRegex = / ^ \[ .+ \] $ / gm;
804
- const sectionRegex = new RegExp ( `^\\s*\\[\\s*${ section } \\s*("[^"]+")*\\]$` , 'm' ) ;
780
+ const regex = / \r ? \n / g;
781
+ let position = 0 ;
782
+ let match : RegExpExecArray | null = null ;
805
783
806
- const parseSectionProperties = ( sectionRaw : string ) : { [ key : string ] : string } => {
807
- const properties : { [ key : string ] : string } = { } ;
784
+ const result : Submodule [ ] = [ ] ;
785
+ let submodule : Partial < Submodule > = { } ;
808
786
809
- for ( const propertyLine of sectionRaw . split ( / \r ? \n / ) ) {
810
- const propertyMatch = / ^ \s * ( \w + ) \s * = \s * ( . * ) $ / . exec ( propertyLine ) ;
787
+ function parseLine ( line : string ) : void {
788
+ const sectionMatch = / ^ \s * \[ s u b m o d u l e " ( [ ^ " ] + ) " \] \s * $ / . exec ( line ) ;
811
789
812
- if ( ! propertyMatch ) {
813
- continue ;
790
+ if ( sectionMatch ) {
791
+ if ( submodule . name && submodule . path && submodule . url ) {
792
+ result . push ( submodule as Submodule ) ;
814
793
}
815
794
816
- const [ , key , value ] = propertyMatch ;
795
+ const name = sectionMatch [ 1 ] ;
817
796
818
- if ( properties [ key ] ) {
819
- continue ;
797
+ if ( name ) {
798
+ submodule = { name } ;
799
+ return ;
820
800
}
821
- properties [ key ] = value ;
822
801
}
823
802
824
- return properties ;
825
- } ;
826
-
827
- const parseSection = ( sectionRaw : string ) => {
828
- const sectionMatch = sectionRegex . exec ( sectionRaw ) ;
829
- if ( ! sectionMatch ) {
803
+ if ( ! submodule ) {
830
804
return ;
831
805
}
832
806
833
- sections . push ( {
834
- label : sectionMatch . length === 2 ? sectionMatch [ 1 ] . replaceAll ( '"' , '' ) : undefined ,
835
- properties : parseSectionProperties ( sectionRaw . substring ( sectionMatch [ 0 ] . length ) )
836
- } ) ;
837
- } ;
807
+ const propertyMatch = / ^ \s * ( \w + ) \s * = \s * ( .* ) $ / . exec ( line ) ;
838
808
839
- let position = 0 ;
840
- let match : RegExpExecArray | null = null ;
809
+ if ( ! propertyMatch ) {
810
+ return ;
811
+ }
841
812
842
- while ( match = sectionHeaderRegex . exec ( raw ) ) {
843
- parseSection ( raw . substring ( position , match . index ) ) ;
844
- position = match . index ;
845
- }
846
- parseSection ( raw . substring ( position ) ) ;
813
+ const [ , key , value ] = propertyMatch ;
847
814
848
- return sections ;
849
- }
815
+ switch ( key ) {
816
+ case 'path' : submodule . path = value ; break ;
817
+ case 'url' : submodule . url = value ; break ;
818
+ }
819
+ }
850
820
851
- export function parseGitRemotes ( raw : string ) : Remote [ ] {
852
- const remotes : Remote [ ] = [ ] ;
821
+ while ( match = regex . exec ( raw ) ) {
822
+ parseLine ( raw . substring ( position , match . index ) ) ;
823
+ position = match . index + match [ 0 ] . length ;
824
+ }
853
825
854
- // Remote sections
855
- for ( const remoteSection of parseGitConfig ( raw , 'remote' ) ) {
856
- if ( ! remoteSection . label ) {
857
- continue ;
858
- }
826
+ parseLine ( raw . substring ( position ) ) ;
859
827
860
- remotes . push ( {
861
- name : remoteSection . label ,
862
- fetchUrl : remoteSection . properties [ 'url' ] ,
863
- pushUrl : remoteSection . properties [ 'pushurl' ] ?? remoteSection . properties [ 'url' ] ,
864
- // https://github.com/microsoft/vscode/issues/45271
865
- isReadOnly : remoteSection . properties [ 'pushurl' ] === 'no_push'
866
- } ) ;
828
+ if ( submodule . name && submodule . path && submodule . url ) {
829
+ result . push ( submodule as Submodule ) ;
867
830
}
868
831
869
- return remotes ;
832
+ return result ;
870
833
}
871
834
872
835
const commitRegex = / ( [ 0 - 9 a - f ] { 40 } ) \n ( .* ) \n ( .* ) \n ( .* ) \n ( .* ) \n ( .* ) \n ( .* ) (?: \n ( [ ^ ] * ?) ) ? (?: \x00 ) / gm;
@@ -2201,20 +2164,6 @@ export class Repository {
2201
2164
}
2202
2165
2203
2166
async getRemotes ( ) : Promise < Remote [ ] > {
2204
- try {
2205
- // Attempt to parse the config file
2206
- const remotes = await this . getRemotesFS ( ) ;
2207
- if ( remotes . length === 0 ) {
2208
- throw new Error ( 'No remotes found in the git config file.' ) ;
2209
- }
2210
-
2211
- return remotes ;
2212
- }
2213
- catch ( err ) {
2214
- this . logger . warn ( err . message ) ;
2215
- }
2216
-
2217
- // Fallback to using git to determine remotes
2218
2167
const result = await this . exec ( [ 'remote' , '--verbose' ] ) ;
2219
2168
const lines = result . stdout . trim ( ) . split ( '\n' ) . filter ( l => ! ! l ) ;
2220
2169
const remotes : MutableRemote [ ] = [ ] ;
@@ -2246,10 +2195,6 @@ export class Repository {
2246
2195
return remotes ;
2247
2196
}
2248
2197
2249
- async getRemotesFS ( ) : Promise < Remote [ ] > {
2250
- return parseGitRemotes ( await fs . readFile ( path . join ( this . dotGit . commonPath ?? this . dotGit . path , 'config' ) , 'utf8' ) ) ;
2251
- }
2252
-
2253
2198
async getBranch ( name : string ) : Promise < Branch > {
2254
2199
if ( name === 'HEAD' ) {
2255
2200
return this . getHEAD ( ) ;
0 commit comments