@@ -6,17 +6,42 @@ const util = require('../lib/util')
6
6
const updatePatches = ( options ) => {
7
7
config . update ( options )
8
8
9
- const runOptions = { cwd : config . projects . chrome . dir }
10
9
const patchDir = path . join ( config . projects . antimuon . dir , 'patches' )
11
10
11
+ const runOptionsChrome = { cwd : config . projects . chrome . dir }
12
+ const runOptionsPatch = { cwd : patchDir }
13
+
14
+ const desiredReplacementSeparator = '-'
15
+ const patchExtension = '.patch'
16
+
12
17
console . log ( 'updatePatches writing files to: ' + patchDir )
13
18
14
19
// grab Modified (and later Deleted) files but not Created (since we copy those)
15
20
const modifiedDiffArgs = [ 'diff' , '--diff-filter=M' , '--name-only' , '--ignore-space-at-eol' ]
16
- let modifiedDiff = util . run ( 'git' , modifiedDiffArgs , runOptions )
17
- let moddedFileList = modifiedDiff . stdout . toString ( ) . split ( '\n' ) . filter ( s => s . length > 0 )
21
+ let modifiedDiff = util . run ( 'git' , modifiedDiffArgs , runOptionsChrome )
22
+ let modifiedFileList = modifiedDiff . stdout . toString ( ) . split ( '\n' ) . filter ( s => s . length > 0 )
23
+
24
+ // copy array
25
+ let substitutedFileList = modifiedFileList . slice ( )
26
+
27
+ // replacing forward slashes and adding the patch extension to get nice filenames
28
+ // since git on Windows doesn't use backslashes, this is sufficient
29
+ substitutedFileList = substitutedFileList . map ( s => s . replace ( / \/ / g, desiredReplacementSeparator ) + patchExtension )
30
+
31
+ // grab every existing patch file in the dir (at this point, patchfiles for now-unmodified files live on)
32
+ const existingFileArgs = [ 'ls-files' , '--exclude-standard' ]
33
+ let existingFileOutput = util . run ( 'git' , existingFileArgs , runOptionsPatch )
34
+ let existingFileList = existingFileOutput . stdout . toString ( ) . split ( '\n' ) . filter ( s => s . length > 0 )
18
35
19
- let n = moddedFileList . length
36
+ // Add files here we specifically want to keep around regardless
37
+ const exclusionList = [ ]
38
+
39
+ // Subtract to find which patchfiles no longer have diffs, yet still exist
40
+ const minuhend = existingFileList
41
+ const subtrahend = substitutedFileList . concat ( exclusionList )
42
+ const difference = minuhend . filter ( x => ! subtrahend . includes ( x ) )
43
+
44
+ const potentialCruftList = difference
20
45
21
46
// When splitting one large diff into a per-file diff, there are a few ways
22
47
// you can go about it. Because different files can have the same name
@@ -28,27 +53,34 @@ const updatePatches = (options) => {
28
53
// appear, you can quickly patch this by changing the separator, even
29
54
// to something longer
30
55
31
- const desiredReplacementSeparator = '-'
32
- const patchExtension = '.patch'
56
+ let n = modifiedFileList . length
33
57
34
58
for ( var i = 0 ; i < n ; i ++ ) {
35
- const old = moddedFileList [ i ]
36
- let revised = old
37
-
38
- //replacing forward slashes
39
- //since git on Windows doesn't use backslashes, this is sufficient
40
- revised = revised . replace ( / \/ / g, desiredReplacementSeparator )
59
+ const old = modifiedFileList [ i ]
60
+ const revised = substitutedFileList [ i ]
41
61
42
62
const singleDiffArgs = [ 'diff' , '--src-prefix=a/' , '--dst-prefix=b/' , '--full-index' , old ]
43
- let singleDiff = util . run ( 'git' , singleDiffArgs , runOptions )
63
+ let singleDiff = util . run ( 'git' , singleDiffArgs , runOptionsChrome )
44
64
45
65
const contents = singleDiff . stdout . toString ( )
46
- const filename = revised + patchExtension
66
+ const filename = revised
47
67
48
68
fs . writeFileSync ( path . join ( patchDir , filename ) , contents )
49
69
50
70
console . log ( 'updatePatches wrote ' + ( 1 + i ) + '/' + n + ': ' + filename )
51
71
}
72
+
73
+ // emit a warning to patch maintainers
74
+ if ( potentialCruftList . length > 0 ) {
75
+ console . log ( '--------------------------------------------------------------' )
76
+ console . log ( 'NOTICE: The following patchfiles have now-unmodified targets.' )
77
+ console . log ( ' Check to see if you need need to use `git rm`' )
78
+ console . log ( ' Alternatively, add them to the exclusion list.' )
79
+ console . log ( 'Patch dir: ' + patchDir )
80
+ console . log ( '--------------------------------------------------------------' )
81
+ potentialCruftList . filter ( x => console . log ( x ) )
82
+ console . log ( '--------------------------------------------------------------' )
83
+ }
52
84
}
53
85
54
86
module . exports = updatePatches
0 commit comments