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

Revert "Split patches" #43

Merged
merged 1 commit into from
Dec 29, 2017
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
51 changes: 3 additions & 48 deletions 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