@@ -3,7 +3,7 @@ const fs = require('fs-extra')
3
3
const config = require ( '../lib/config' )
4
4
const util = require ( '../lib/util' )
5
5
6
- const updatePatches = ( options ) => {
6
+ const updatePatches = async ( options ) => {
7
7
config . update ( options )
8
8
9
9
const patchDir = path . join ( config . projects [ 'brave-core' ] . dir , 'patches' )
@@ -18,8 +18,7 @@ const updatePatches = (options) => {
18
18
19
19
// grab Modified (and later Deleted) files but not Created (since we copy those)
20
20
const modifiedDiffArgs = [ 'diff' , '--diff-filter=M' , '--name-only' , '--ignore-space-at-eol' ]
21
- const modifiedDiff = util . run ( 'git' , modifiedDiffArgs , runOptionsChrome )
22
- const modifiedFileList = modifiedDiff . stdout . toString ( )
21
+ const modifiedFileList = ( await util . runAsync ( 'git' , modifiedDiffArgs , runOptionsChrome ) )
23
22
. split ( '\n' )
24
23
. filter ( s => s . length > 0 &&
25
24
! s . startsWith ( 'chrome/app/theme/default' ) &&
@@ -38,8 +37,8 @@ const updatePatches = (options) => {
38
37
39
38
// grab every existing patch file in the dir (at this point, patchfiles for now-unmodified files live on)
40
39
const existingFileArgs = [ 'ls-files' , '--exclude-standard' ]
41
- let existingFileOutput = util . run ( 'git' , existingFileArgs , runOptionsPatch )
42
- let existingFileList = existingFileOutput . stdout . toString ( ) . split ( '\n' ) . filter ( s => s . length > 0 )
40
+ let existingFileList = ( await util . runAsync ( 'git' , existingFileArgs , runOptionsPatch ) )
41
+ . split ( '\n' ) . filter ( s => s . length > 0 )
43
42
44
43
// Add files here we specifically want to keep around regardless
45
44
const exclusionList = [ ]
@@ -61,22 +60,20 @@ const updatePatches = (options) => {
61
60
// appear, you can quickly patch this by changing the separator, even
62
61
// to something longer
63
62
64
- let n = modifiedFileList . length
65
-
66
- for ( let i = 0 ; i < n ; i ++ ) {
67
- const old = modifiedFileList [ i ]
68
- const revised = substitutedFileList [ i ]
69
-
63
+ let writeOpsDoneCount = 0
64
+ let writePatchOps = modifiedFileList . map ( async ( old , i ) => {
70
65
const singleDiffArgs = [ 'diff' , '--src-prefix=a/' , '--dst-prefix=b/' , '--full-index' , old ]
71
- let singleDiff = util . run ( 'git' , singleDiffArgs , runOptionsChrome )
66
+ const patchContents = await util . runAsync ( 'git' , singleDiffArgs , runOptionsChrome )
67
+ const patchFilename = substitutedFileList [ i ]
68
+ await fs . writeFile ( path . join ( patchDir , patchFilename ) , patchContents )
72
69
73
- const contents = singleDiff . stdout . toString ( )
74
- const filename = revised
70
+ writeOpsDoneCount ++
71
+ console . log (
72
+ `updatePatches wrote ${ writeOpsDoneCount } / ${ modifiedFileList . length } : ${ patchFilename } `
73
+ )
74
+ } )
75
75
76
- fs . writeFileSync ( path . join ( patchDir , filename ) , contents )
77
-
78
- console . log ( 'updatePatches wrote ' + ( 1 + i ) + '/' + n + ': ' + filename )
79
- }
76
+ await Promise . all ( writePatchOps )
80
77
81
78
// regular rm patchfiles whose target is no longer modified
82
79
let m = cruftList . length
0 commit comments