Skip to content

Commit

Permalink
Warn patch maintainer to remove patch
Browse files Browse the repository at this point in the history
Fix brave/brave-browser#49

rm cruft patches in addition to notifying
  • Loading branch information
kevinlawler authored and bbondy committed Jul 6, 2018
1 parent 40bef24 commit a4467b1
Showing 1 changed file with 46 additions and 15 deletions.
61 changes: 46 additions & 15 deletions build/lib/updatePatches.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,46 @@ const util = require('../lib/util')
const updatePatches = (options) => {
config.update(options)

const runOptions = { cwd: config.projects.chrome.dir }
const patchDir = path.join(config.projects['brave-core'].dir, 'patches')

const runOptionsChrome = { cwd: config.projects.chrome.dir }
const runOptionsPatch = { cwd: patchDir }

const desiredReplacementSeparator = '-'
const patchExtension = '.patch'

console.log('updatePatches writing files to: ' + patchDir)

// grab Modified (and later Deleted) files but not Created (since we copy those)
const modifiedDiffArgs = ['diff', '--diff-filter=M', '--name-only', '--ignore-space-at-eol']
let modifiedDiff = util.run('git', modifiedDiffArgs, runOptions)
let moddedFileList = modifiedDiff.stdout.toString()
const modifiedDiff = util.run('git', modifiedDiffArgs, runOptionsChrome)
const modifiedFileList = modifiedDiff.stdout.toString()
.split('\n')
.filter(s => s.length > 0 && !s.startsWith('chrome/app/theme') &&
!s.endsWith('.xtb') && !s.endsWith('.grd') && !s.endsWith('.grdp') &&
!s.includes('google_update_idl'))

let n = moddedFileList.length
// copy array
let substitutedFileList = modifiedFileList.slice()

// replacing forward slashes and adding the patch extension to get nice filenames
// since git on Windows doesn't use backslashes, this is sufficient
substitutedFileList = substitutedFileList.map(s => s.replace(/\//g, desiredReplacementSeparator) + patchExtension)

// grab every existing patch file in the dir (at this point, patchfiles for now-unmodified files live on)
const existingFileArgs = ['ls-files', '--exclude-standard']
let existingFileOutput = util.run('git', existingFileArgs, runOptionsPatch)
let existingFileList = existingFileOutput.stdout.toString().split('\n').filter(s => s.length > 0)

// Add files here we specifically want to keep around regardless
const exclusionList = []

// Subtract to find which patchfiles no longer have diffs, yet still exist
const minuhend = existingFileList
const subtrahend = substitutedFileList.concat(exclusionList)
const difference = minuhend.filter(x => !subtrahend.includes(x))

const cruftList = difference

// When splitting one large diff into a per-file diff, there are a few ways
// you can go about it. Because different files can have the same name
Expand All @@ -32,27 +57,33 @@ const updatePatches = (options) => {
// appear, you can quickly patch this by changing the separator, even
// to something longer

const desiredReplacementSeparator = '-'
const patchExtension = '.patch'

for (var i = 0; i < n; i++) {
const old = moddedFileList[i]
let revised = old
let n = modifiedFileList.length

//replacing forward slashes
//since git on Windows doesn't use backslashes, this is sufficient
revised = revised.replace(/\//g, desiredReplacementSeparator)
for (let i = 0; i < n; i++) {
const old = modifiedFileList[i]
const revised = substitutedFileList[i]

const singleDiffArgs = ['diff', '--src-prefix=a/', '--dst-prefix=b/', '--full-index', old]
let singleDiff = util.run('git', singleDiffArgs, runOptions)
let singleDiff = util.run('git', singleDiffArgs, runOptionsChrome)

const contents = singleDiff.stdout.toString()
const filename = revised + patchExtension
const filename = revised

fs.writeFileSync(path.join(patchDir, filename), contents)

console.log('updatePatches wrote ' + (1 + i) + '/' + n + ': ' + filename)
}

// regular rm patchfiles whose target is no longer modified
let m = cruftList.length
for (let i = 0; i < m; i++) {
let filename = cruftList[i]
let fullpath = path.join(patchDir, filename)

fs.removeSync(fullpath)

console.log('updatePatches *REMOVED* ' + (1 + i) + '/' + m + ': ' + filename)
}
}

module.exports = updatePatches

0 comments on commit a4467b1

Please sign in to comment.