Skip to content

Commit

Permalink
warn patch maintainer to remove patch
Browse files Browse the repository at this point in the history
brave/brave#49
  • Loading branch information
kevinlawler committed Jan 8, 2018
1 parent 17afdbe commit 22f9fea
Showing 1 changed file with 46 additions and 14 deletions.
60 changes: 46 additions & 14 deletions lib/updatePatches.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,42 @@ const util = require('../lib/util')
const updatePatches = (options) => {
config.update(options)

const runOptions = { cwd: config.projects.chrome.dir }
const patchDir = path.join(config.projects.antimuon.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().split('\n').filter(s => s.length > 0)
let modifiedDiff = util.run('git', modifiedDiffArgs, runOptionsChrome)
let modifiedFileList = modifiedDiff.stdout.toString().split('\n').filter(s => s.length > 0)

// 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)

let n = moddedFileList.length
// 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 potentialCruftList = 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 @@ -28,27 +53,34 @@ const updatePatches = (options) => {
// appear, you can quickly patch this by changing the separator, even
// to something longer

const desiredReplacementSeparator = '-'
const patchExtension = '.patch'
let n = modifiedFileList.length

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

//replacing forward slashes
//since git on Windows doesn't use backslashes, this is sufficient
revised = revised.replace(/\//g, desiredReplacementSeparator)
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)
}

// emit a warning to patch maintainers
if (potentialCruftList.length > 0) {
console.log('--------------------------------------------------------------')
console.log('NOTICE: The following patchfiles have now-unmodified targets.')
console.log(' Check to see if you need need to use `git rm`')
console.log(' Alternatively, add them to the exclusion list.')
console.log('Patch dir: ' + patchDir)
console.log('--------------------------------------------------------------')
potentialCruftList.filter(x => console.log(x))
console.log('--------------------------------------------------------------')
}
}

module.exports = updatePatches

0 comments on commit 22f9fea

Please sign in to comment.