@@ -358,10 +358,19 @@ function splitNullSeparatedPaths(input: string, truncated: boolean): string[] {
358358 return parts . filter ( ( value ) => value . length > 0 ) ;
359359}
360360
361- function parseCheckpointStatusPaths ( output : string ) : string [ ] {
362- return splitNullSeparatedPaths ( output , false ) . flatMap ( ( entry ) =>
363- entry . length > 3 && entry [ 2 ] === " " ? [ entry . slice ( 3 ) ] : [ ] ,
364- ) ;
361+ function parseCheckpointStatusPathspec ( output : Uint8Array ) : Uint8Array {
362+ const paths : Uint8Array [ ] = [ ] ;
363+ let recordStart = 0 ;
364+ for ( let index = 0 ; index < output . byteLength ; index += 1 ) {
365+ if ( output [ index ] !== 0 ) {
366+ continue ;
367+ }
368+ if ( index - recordStart > 3 && output [ recordStart + 2 ] === 0x20 ) {
369+ paths . push ( output . subarray ( recordStart + 3 , index + 1 ) ) ;
370+ }
371+ recordStart = index + 1 ;
372+ }
373+ return Buffer . concat ( paths ) ;
365374}
366375
367376function chunkPathsForGitCheckIgnore ( relativePaths : ReadonlyArray < string > ) : string [ ] [ ] {
@@ -432,7 +441,8 @@ const gitCommand = (
432441 cwd : string ,
433442 args : ReadonlyArray < string > ,
434443 options ?: {
435- readonly stdin ?: string ;
444+ readonly stdin ?: string | Uint8Array ;
445+ readonly captureStdoutBytes ?: boolean ;
436446 readonly env ?: NodeJS . ProcessEnv ;
437447 readonly allowNonZeroExit ?: boolean ;
438448 readonly timeoutMs ?: number ;
@@ -447,6 +457,9 @@ const gitCommand = (
447457 cwd,
448458 spawnCwd : globalThis . process . cwd ( ) ,
449459 ...( options ?. stdin !== undefined ? { stdin : options . stdin } : { } ) ,
460+ ...( options ?. captureStdoutBytes !== undefined
461+ ? { captureStdoutBytes : options . captureStdoutBytes }
462+ : { } ) ,
450463 ...( options ?. env !== undefined ? { env : options . env } : { } ) ,
451464 ...( options ?. allowNonZeroExit !== undefined
452465 ? { allowNonZeroExit : options . allowNonZeroExit }
@@ -487,6 +500,9 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
487500 const execute : VcsDriver . VcsDriver [ "Service" ] [ "execute" ] = ( input ) =>
488501 gitCommand ( vcsProcess , input . operation , input . cwd , input . args , {
489502 ...( input . stdin !== undefined ? { stdin : input . stdin } : { } ) ,
503+ ...( input . captureStdoutBytes !== undefined
504+ ? { captureStdoutBytes : input . captureStdoutBytes }
505+ : { } ) ,
490506 ...( input . env !== undefined ? { env : input . env } : { } ) ,
491507 ...( input . allowNonZeroExit !== undefined ? { allowNonZeroExit : input . allowNonZeroExit } : { } ) ,
492508 ...( input . timeoutMs !== undefined ? { timeoutMs : input . timeoutMs } : { } ) ,
@@ -714,12 +730,14 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
714730 return path . isAbsolute ( gitCommonDir ) ? gitCommonDir : path . resolve ( cwd , gitCommonDir ) ;
715731 } ) ;
716732
717- const resolveRepositoryRoot = ( cwd : string ) =>
718- execute ( {
733+ const resolveRepositoryRoot = Effect . fn ( "resolveRepositoryRoot" ) ( function * ( cwd : string ) {
734+ const result = yield * execute ( {
719735 operation : "GitVcsDriver.checkpoints.resolveRepositoryRoot" ,
720736 cwd,
721737 args : [ "rev-parse" , "--show-toplevel" ] ,
722- } ) . pipe ( Effect . map ( ( result ) => result . stdout . trim ( ) ) ) ;
738+ } ) ;
739+ return result . stdout . trim ( ) ;
740+ } ) ;
723741
724742 const checkpoints : VcsDriver . VcsCheckpointOps = {
725743 captureCheckpoint : Effect . fn ( "GitVcsDriver.checkpoints.captureCheckpoint" ) ( function * ( input ) {
@@ -769,18 +787,19 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
769787 GIT_OPTIONAL_LOCKS : "0" ,
770788 } ,
771789 maxOutputBytes : WORKSPACE_FILES_MAX_OUTPUT_BYTES ,
790+ captureStdoutBytes : true ,
772791 } ) ;
773792
774- if ( statusResult . stdoutTruncated ) {
793+ if ( statusResult . stdoutTruncated || statusResult . stdoutBytes === undefined ) {
775794 yield * execute ( {
776795 operation,
777796 cwd : input . cwd ,
778797 args : [ "add" , "-A" , "--" , "." ] ,
779798 env : commitEnv ,
780799 } ) ;
781800 } else {
782- const changedPaths = parseCheckpointStatusPaths ( statusResult . stdout ) ;
783- if ( changedPaths . length > 0 ) {
801+ const changedPathspec = parseCheckpointStatusPathspec ( statusResult . stdoutBytes ) ;
802+ if ( changedPathspec . byteLength > 0 ) {
784803 yield * execute ( {
785804 operation,
786805 cwd : repositoryRoot ,
@@ -791,7 +810,7 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
791810 "--pathspec-from-file=-" ,
792811 "--pathspec-file-nul" ,
793812 ] ,
794- stdin : ` ${ changedPaths . join ( "\0" ) } \0` ,
813+ stdin : changedPathspec ,
795814 env : commitEnv ,
796815 } ) ;
797816 }
0 commit comments