Skip to content

Commit

Permalink
Merge pull request #43 from brave/revert-37-split-patches
Browse files Browse the repository at this point in the history
Revert "Split patches"
  • Loading branch information
bridiver authored Dec 29, 2017
2 parents 4bf2eea + 3401905 commit fd266fd
Showing 1 changed file with 3 additions and 48 deletions.
51 changes: 3 additions & 48 deletions build/commands/lib/updatePatches.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,9 @@ 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')

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 n = moddedFileList.length

// 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
// (by being located in different directories), you need to avoid collisions.
// Mirroring the directory structure seems undesirable.
// Prefixing with numbers works but is O(n) volatile for O(1) additions
// We choose here to flatten the directory structure by replacing separators
// In practice this will avoid collisions. Should a pathological case ever
// 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

//replacing forward slashes
//since git on Windows doesn't use backslashes, this is sufficient
revised = revised.replace(/\//g, desiredReplacementSeparator)

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

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

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

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

// finish off by creating one big patch for deleted files
const deletedDiffArgs = ['diff', '--diff-filter=D', '--src-prefix=a/', '--dst-prefix=b/', '--full-index', '--ignore-space-at-eol']
let deletedDiff = util.run('git', deletedDiffArgs, runOptions)
fs.writeFileSync(path.join(patchDir, 'master_deleted_patch.patch'), deletedDiff.stdout)
const diffArgs = ['diff', '--full-index', '--ignore-space-at-eol']
let diff = util.run('git', diffArgs, { cwd: config.projects.chrome.dir })
fs.writeFileSync(path.join(config.projects.antimuon.dir, 'patches', 'master_patch.patch'), diff.stdout)
}

module.exports = updatePatches

0 comments on commit fd266fd

Please sign in to comment.