Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warn patch maintainer to remove patch #50

Merged
merged 1 commit into from
Jul 6, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 46 additions & 15 deletions 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