@@ -83,70 +83,47 @@ public BlobPrefetcher(
8383
8484 public List < string > FolderList { get ; }
8585
86- public static bool TryLoadFolderList ( Enlistment enlistment , string foldersInput , string folderListFile , List < string > folderListOutput , out string error )
86+ public static bool TryLoadFolderList ( Enlistment enlistment , string foldersInput , string folderListFile , List < string > folderListOutput , bool readListFromStdIn , out string error )
8787 {
88- folderListOutput . AddRange (
89- foldersInput . Split ( new [ ] { ';' } , StringSplitOptions . RemoveEmptyEntries )
90- . Select ( path => BlobPrefetcher . ToAbsolutePath ( enlistment , path , isFolder : true ) ) ) ;
91-
92- if ( ! string . IsNullOrWhiteSpace ( folderListFile ) )
93- {
94- if ( File . Exists ( folderListFile ) )
95- {
96- IEnumerable < string > allLines = File . ReadAllLines ( folderListFile )
97- . Select ( line => line . Trim ( ) )
98- . Where ( line => ! string . IsNullOrEmpty ( line ) )
99- . Where ( line => ! line . StartsWith ( GVFSConstants . GitCommentSign . ToString ( ) ) )
100- . Select ( path => BlobPrefetcher . ToAbsolutePath ( enlistment , path , isFolder : true ) ) ;
101-
102- folderListOutput . AddRange ( allLines ) ;
103- }
104- else
105- {
106- error = string . Format ( "Could not find '{0}' for folder list." , folderListFile ) ;
107- return false ;
108- }
109- }
110-
111- folderListOutput . RemoveAll ( string . IsNullOrWhiteSpace ) ;
112-
113- foreach ( string folder in folderListOutput )
114- {
115- if ( folder . Contains ( "*" ) )
116- {
117- error = "Wildcards are not supported for folders. Invalid entry: " + folder ;
118- return false ;
119- }
120- }
121-
122- error = null ;
123- return true ;
88+ return TryLoadFileOrFolderList (
89+ enlistment ,
90+ foldersInput ,
91+ folderListFile ,
92+ isFolder : true ,
93+ readListFromStdIn : readListFromStdIn ,
94+ output : folderListOutput ,
95+ elementValidationFunction : s =>
96+ s . Contains ( "*" ) ?
97+ "Wildcards are not supported for folders. Invalid entry: " + s :
98+ null ,
99+ error : out error ) ;
124100 }
125101
126- public static bool TryLoadFileList ( Enlistment enlistment , string filesInput , List < string > fileListOutput , out string error )
102+ public static bool TryLoadFileList ( Enlistment enlistment , string filesInput , string filesListFile , List < string > fileListOutput , bool readListFromStdIn , out string error )
127103 {
128- fileListOutput . AddRange (
129- filesInput . Split ( new [ ] { ';' } , StringSplitOptions . RemoveEmptyEntries )
130- . Select ( path => BlobPrefetcher . ToAbsolutePath ( enlistment , path , isFolder : false ) ) ) ;
131-
132- foreach ( string file in fileListOutput )
133- {
134- if ( file . IndexOf ( '*' , 1 ) != - 1 )
104+ return TryLoadFileOrFolderList (
105+ enlistment ,
106+ filesInput ,
107+ filesListFile ,
108+ readListFromStdIn : readListFromStdIn ,
109+ isFolder : false ,
110+ output : fileListOutput ,
111+ elementValidationFunction : s =>
135112 {
136- error = "Only prefix wildcards are supported. Invalid entry: " + file ;
137- return false ;
138- }
113+ if ( s . IndexOf ( '*' , 1 ) != - 1 )
114+ {
115+ return "Only prefix wildcards are supported. Invalid entry: " + s ;
116+ }
139117
140- if ( file . EndsWith ( GVFSConstants . GitPathSeparatorString ) ||
141- file . EndsWith ( pathSeparatorString ) )
142- {
143- error = "Folders are not allowed in the file list. Invalid entry: " + file ;
144- return false ;
145- }
146- }
118+ if ( s . EndsWith ( GVFSConstants . GitPathSeparatorString ) ||
119+ s . EndsWith ( pathSeparatorString ) )
120+ {
121+ return "Folders are not allowed in the file list. Invalid entry: " + s ;
122+ }
147123
148- error = null ;
149- return true ;
124+ return null ;
125+ } ,
126+ error : out error ) ;
150127 }
151128
152129 public static bool IsNoopPrefetch (
@@ -173,7 +150,7 @@ public static bool IsNoopPrefetch(
173150
174151 tracer . RelatedEvent (
175152 EventLevel . Informational ,
176- "BlobPrefetcher.IsNoopPrefetch" ,
153+ "BlobPrefetcher.IsNoopPrefetch" ,
177154 new EventMetadata
178155 {
179156 { "Last" + PrefetchArgs . CommitId , lastCommitId } ,
@@ -231,7 +208,7 @@ public virtual void Prefetch(string branchOrCommit, bool isBranch)
231208 int matchedBlobCount ;
232209 int downloadedBlobCount ;
233210 int hydratedFileCount ;
234-
211+
235212 this . PrefetchWithStats ( branchOrCommit , isBranch , false , out matchedBlobCount , out downloadedBlobCount , out hydratedFileCount ) ;
236213 }
237214
@@ -290,7 +267,7 @@ public void PrefetchWithStats(
290267 return ;
291268 }
292269 }
293-
270+
294271 BlockingCollection < string > availableBlobs = new BlockingCollection < string > ( ) ;
295272
296273 ////
@@ -300,7 +277,7 @@ public void PrefetchWithStats(
300277 // | | | |
301278 // ------------------------------------------------------> fileHydrator
302279 ////
303-
280+
304281 // diff
305282 // Inputs:
306283 // * files/folders
@@ -310,7 +287,7 @@ public void PrefetchWithStats(
310287 // * FileAddOperations (property): Repo-relative paths corresponding to those blob ids
311288 DiffHelper diff = new DiffHelper ( this . Tracer , this . Enlistment , this . FileList , this . FolderList , includeSymLinks : false ) ;
312289
313- // blobFinder
290+ // blobFinder
314291 // Inputs:
315292 // * requiredBlobs (in param): Blob ids from output of `diff`
316293 // Outputs:
@@ -513,9 +490,77 @@ protected void DownloadMissingCommit(string commitSha, GitObjects gitObjects)
513490 }
514491 }
515492
493+ private static IEnumerable < string > GetFilesFromVerbParameter ( string valueString )
494+ {
495+ return valueString . Split ( new [ ] { ';' } , StringSplitOptions . RemoveEmptyEntries ) ;
496+ }
497+
498+ private static IEnumerable < string > GetFilesFromFile ( string fileName , out string error )
499+ {
500+ error = null ;
501+ if ( string . IsNullOrWhiteSpace ( fileName ) )
502+ {
503+ return Enumerable . Empty < string > ( ) ;
504+ }
505+
506+ if ( ! File . Exists ( fileName ) )
507+ {
508+ error = string . Format ( "Could not find '{0}' list file." , fileName ) ;
509+ return Enumerable . Empty < string > ( ) ;
510+ }
511+
512+ return File . ReadAllLines ( fileName )
513+ . Select ( line => line . Trim ( ) ) ;
514+ }
515+
516+ private static IEnumerable < string > GetFilesFromStdin ( bool shouldRead )
517+ {
518+ if ( ! shouldRead )
519+ {
520+ yield break ;
521+ }
522+
523+ string line ;
524+ while ( ( line = Console . In . ReadLine ( ) ) != null )
525+ {
526+ yield return line . Trim ( ) ;
527+ }
528+ }
529+
530+ private static bool TryLoadFileOrFolderList ( Enlistment enlistment , string valueString , string listFileName , bool readListFromStdIn , bool isFolder , List < string > output , Func < string , string > elementValidationFunction , out string error )
531+ {
532+ output . AddRange (
533+ GetFilesFromVerbParameter ( valueString )
534+ . Union ( GetFilesFromFile ( listFileName , out string fileReadError ) )
535+ . Union ( GetFilesFromStdin ( readListFromStdIn ) )
536+ . Where ( path => ! path . StartsWith ( GVFSConstants . GitCommentSign . ToString ( ) ) )
537+ . Where ( path => ! string . IsNullOrWhiteSpace ( path ) )
538+ . Select ( path => BlobPrefetcher . ToAbsolutePath ( enlistment , path , isFolder : isFolder ) ) ) ;
539+
540+ if ( ! string . IsNullOrWhiteSpace ( fileReadError ) )
541+ {
542+ error = fileReadError ;
543+ return false ;
544+ }
545+
546+ string [ ] errorArray = output
547+ . Select ( elementValidationFunction )
548+ . Where ( s => ! string . IsNullOrWhiteSpace ( s ) )
549+ . ToArray ( ) ;
550+
551+ if ( errorArray != null && errorArray . Length > 0 )
552+ {
553+ error = string . Join ( "\n " , errorArray ) ;
554+ return false ;
555+ }
556+
557+ error = null ;
558+ return true ;
559+ }
560+
516561 private static string ToAbsolutePath ( Enlistment enlistment , string path , bool isFolder )
517562 {
518- string absolute =
563+ string absolute =
519564 path . StartsWith ( "*" )
520565 ? path
521566 : Path . Combine ( enlistment . WorkingDirectoryRoot , path . Replace ( GVFSConstants . GitPathSeparator , Path . DirectorySeparatorChar ) . TrimStart ( Path . DirectorySeparatorChar ) ) ;
0 commit comments