mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Merge branch 'master' of github.com:atom/atom into content-regex
This commit is contained in:
@@ -177,7 +177,7 @@ exports.install = function (resourcesPath, nodeRequire) {
|
||||
var rawData = sourceMappingURL.slice(sourceMappingURL.indexOf(',') + 1)
|
||||
|
||||
try {
|
||||
var sourceMap = JSON.parse(Buffer.from(rawData, 'base64'))
|
||||
var sourceMap = JSON.parse(new Buffer(rawData, 'base64'))
|
||||
} catch (error) {
|
||||
console.warn('Error parsing source map', error.stack)
|
||||
return null
|
||||
|
||||
@@ -20,7 +20,7 @@ class FileSystemBlobStore {
|
||||
|
||||
reset () {
|
||||
this.inMemoryBlobs = new Map()
|
||||
this.storedBlob = Buffer.alloc(0)
|
||||
this.storedBlob = new Buffer(0)
|
||||
this.storedBlobMap = {}
|
||||
this.usedKeys = new Set()
|
||||
}
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
fs = require 'fs'
|
||||
{Directory} = require 'pathwatcher'
|
||||
GitRepository = require './git-repository'
|
||||
|
||||
# Returns the .gitdir path in the agnostic Git symlink .git file given, or
|
||||
# null if the path is not a valid gitfile.
|
||||
#
|
||||
# * `gitFile` {String} path of gitfile to parse
|
||||
gitFileRegex = RegExp "^gitdir: (.+)"
|
||||
pathFromGitFile = (gitFile) ->
|
||||
try
|
||||
gitFileBuff = fs.readFileSync(gitFile, 'utf8')
|
||||
return gitFileBuff?.match(gitFileRegex)[1]
|
||||
|
||||
# Checks whether a valid `.git` directory is contained within the given
|
||||
# directory or one of its ancestors. If so, a Directory that corresponds to the
|
||||
# `.git` folder will be returned. Otherwise, returns `null`.
|
||||
#
|
||||
# * `directory` {Directory} to explore whether it is part of a Git repository.
|
||||
findGitDirectorySync = (directory) ->
|
||||
# TODO: Fix node-pathwatcher/src/directory.coffee so the following methods
|
||||
# can return cached values rather than always returning new objects:
|
||||
# getParent(), getFile(), getSubdirectory().
|
||||
gitDir = directory.getSubdirectory('.git')
|
||||
gitDirPath = pathFromGitFile(gitDir.getPath?())
|
||||
if gitDirPath
|
||||
gitDir = new Directory(directory.resolve(gitDirPath))
|
||||
if gitDir.existsSync?() and isValidGitDirectorySync gitDir
|
||||
gitDir
|
||||
else if directory.isRoot()
|
||||
return null
|
||||
else
|
||||
findGitDirectorySync directory.getParent()
|
||||
|
||||
# Returns a boolean indicating whether the specified directory represents a Git
|
||||
# repository.
|
||||
#
|
||||
# * `directory` {Directory} whose base name is `.git`.
|
||||
isValidGitDirectorySync = (directory) ->
|
||||
# To decide whether a directory has a valid .git folder, we use
|
||||
# the heuristic adopted by the valid_repository_path() function defined in
|
||||
# node_modules/git-utils/deps/libgit2/src/repository.c.
|
||||
return directory.getSubdirectory('objects').existsSync() and
|
||||
directory.getFile('HEAD').existsSync() and
|
||||
directory.getSubdirectory('refs').existsSync()
|
||||
|
||||
# Provider that conforms to the atom.repository-provider@0.1.0 service.
|
||||
module.exports =
|
||||
class GitRepositoryProvider
|
||||
|
||||
constructor: (@project, @config) ->
|
||||
# Keys are real paths that end in `.git`.
|
||||
# Values are the corresponding GitRepository objects.
|
||||
@pathToRepository = {}
|
||||
|
||||
# Returns a {Promise} that resolves with either:
|
||||
# * {GitRepository} if the given directory has a Git repository.
|
||||
# * `null` if the given directory does not have a Git repository.
|
||||
repositoryForDirectory: (directory) ->
|
||||
# TODO: Currently, this method is designed to be async, but it relies on a
|
||||
# synchronous API. It should be rewritten to be truly async.
|
||||
Promise.resolve(@repositoryForDirectorySync(directory))
|
||||
|
||||
# Returns either:
|
||||
# * {GitRepository} if the given directory has a Git repository.
|
||||
# * `null` if the given directory does not have a Git repository.
|
||||
repositoryForDirectorySync: (directory) ->
|
||||
# Only one GitRepository should be created for each .git folder. Therefore,
|
||||
# we must check directory and its parent directories to find the nearest
|
||||
# .git folder.
|
||||
gitDir = findGitDirectorySync(directory)
|
||||
unless gitDir
|
||||
return null
|
||||
|
||||
gitDirPath = gitDir.getPath()
|
||||
repo = @pathToRepository[gitDirPath]
|
||||
unless repo
|
||||
repo = GitRepository.open(gitDirPath, {@project, @config})
|
||||
return null unless repo
|
||||
repo.onDidDestroy(=> delete @pathToRepository[gitDirPath])
|
||||
@pathToRepository[gitDirPath] = repo
|
||||
repo.refreshIndex()
|
||||
repo.refreshStatus()
|
||||
repo
|
||||
180
src/git-repository-provider.js
Normal file
180
src/git-repository-provider.js
Normal file
@@ -0,0 +1,180 @@
|
||||
const fs = require('fs')
|
||||
const { Directory } = require('pathwatcher')
|
||||
const GitRepository = require('./git-repository')
|
||||
|
||||
const GIT_FILE_REGEX = RegExp('^gitdir: (.+)')
|
||||
|
||||
// Returns the .gitdir path in the agnostic Git symlink .git file given, or
|
||||
// null if the path is not a valid gitfile.
|
||||
//
|
||||
// * `gitFile` {String} path of gitfile to parse
|
||||
function pathFromGitFileSync (gitFile) {
|
||||
try {
|
||||
const gitFileBuff = fs.readFileSync(gitFile, 'utf8')
|
||||
return gitFileBuff != null ? gitFileBuff.match(GIT_FILE_REGEX)[1] : null
|
||||
} catch (error) {}
|
||||
}
|
||||
|
||||
// Returns a {Promise} that resolves to the .gitdir path in the agnostic
|
||||
// Git symlink .git file given, or null if the path is not a valid gitfile.
|
||||
//
|
||||
// * `gitFile` {String} path of gitfile to parse
|
||||
function pathFromGitFile (gitFile) {
|
||||
return new Promise(resolve => {
|
||||
fs.readFile(gitFile, 'utf8', (err, gitFileBuff) => {
|
||||
if (err == null && gitFileBuff != null) {
|
||||
const result = gitFileBuff.toString().match(GIT_FILE_REGEX)
|
||||
resolve(result != null ? result[1] : null)
|
||||
} else {
|
||||
resolve(null)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// Checks whether a valid `.git` directory is contained within the given
|
||||
// directory or one of its ancestors. If so, a Directory that corresponds to the
|
||||
// `.git` folder will be returned. Otherwise, returns `null`.
|
||||
//
|
||||
// * `directory` {Directory} to explore whether it is part of a Git repository.
|
||||
function findGitDirectorySync (directory) {
|
||||
// TODO: Fix node-pathwatcher/src/directory.coffee so the following methods
|
||||
// can return cached values rather than always returning new objects:
|
||||
// getParent(), getFile(), getSubdirectory().
|
||||
let gitDir = directory.getSubdirectory('.git')
|
||||
if (typeof gitDir.getPath === 'function') {
|
||||
const gitDirPath = pathFromGitFileSync(gitDir.getPath())
|
||||
if (gitDirPath) {
|
||||
gitDir = new Directory(directory.resolve(gitDirPath))
|
||||
}
|
||||
}
|
||||
if (
|
||||
typeof gitDir.existsSync === 'function' &&
|
||||
gitDir.existsSync() &&
|
||||
isValidGitDirectorySync(gitDir)
|
||||
) {
|
||||
return gitDir
|
||||
} else if (directory.isRoot()) {
|
||||
return null
|
||||
} else {
|
||||
return findGitDirectorySync(directory.getParent())
|
||||
}
|
||||
}
|
||||
|
||||
// Checks whether a valid `.git` directory is contained within the given
|
||||
// directory or one of its ancestors. If so, a Directory that corresponds to the
|
||||
// `.git` folder will be returned. Otherwise, returns `null`.
|
||||
//
|
||||
// Returns a {Promise} that resolves to
|
||||
// * `directory` {Directory} to explore whether it is part of a Git repository.
|
||||
async function findGitDirectory (directory) {
|
||||
// TODO: Fix node-pathwatcher/src/directory.coffee so the following methods
|
||||
// can return cached values rather than always returning new objects:
|
||||
// getParent(), getFile(), getSubdirectory().
|
||||
let gitDir = directory.getSubdirectory('.git')
|
||||
if (typeof gitDir.getPath === 'function') {
|
||||
const gitDirPath = await pathFromGitFile(gitDir.getPath())
|
||||
if (gitDirPath) {
|
||||
gitDir = new Directory(directory.resolve(gitDirPath))
|
||||
}
|
||||
}
|
||||
if (
|
||||
typeof gitDir.exists === 'function' &&
|
||||
(await gitDir.exists()) &&
|
||||
isValidGitDirectory(gitDir)
|
||||
) {
|
||||
return gitDir
|
||||
} else if (directory.isRoot()) {
|
||||
return null
|
||||
} else {
|
||||
return await findGitDirectory(directory.getParent())
|
||||
}
|
||||
}
|
||||
|
||||
// Returns a boolean indicating whether the specified directory represents a Git
|
||||
// repository.
|
||||
//
|
||||
// * `directory` {Directory} whose base name is `.git`.
|
||||
function isValidGitDirectorySync (directory) {
|
||||
// To decide whether a directory has a valid .git folder, we use
|
||||
// the heuristic adopted by the valid_repository_path() function defined in
|
||||
// node_modules/git-utils/deps/libgit2/src/repository.c.
|
||||
return (
|
||||
directory.getSubdirectory('objects').existsSync() &&
|
||||
directory.getFile('HEAD').existsSync() &&
|
||||
directory.getSubdirectory('refs').existsSync()
|
||||
)
|
||||
}
|
||||
|
||||
// Returns a {Promise} that resolves to a {Boolean} indicating whether the
|
||||
// specified directory represents a Git repository.
|
||||
//
|
||||
// * `directory` {Directory} whose base name is `.git`.
|
||||
async function isValidGitDirectory (directory) {
|
||||
// To decide whether a directory has a valid .git folder, we use
|
||||
// the heuristic adopted by the valid_repository_path() function defined in
|
||||
// node_modules/git-utils/deps/libgit2/src/repository.c.
|
||||
return (
|
||||
(await directory.getSubdirectory('objects').exists()) &&
|
||||
(await directory.getFile('HEAD').exists()) &&
|
||||
(await directory.getSubdirectory('refs').exists())
|
||||
)
|
||||
}
|
||||
|
||||
// Provider that conforms to the atom.repository-provider@0.1.0 service.
|
||||
class GitRepositoryProvider {
|
||||
constructor (project, config) {
|
||||
// Keys are real paths that end in `.git`.
|
||||
// Values are the corresponding GitRepository objects.
|
||||
this.project = project
|
||||
this.config = config
|
||||
this.pathToRepository = {}
|
||||
}
|
||||
|
||||
// Returns a {Promise} that resolves with either:
|
||||
// * {GitRepository} if the given directory has a Git repository.
|
||||
// * `null` if the given directory does not have a Git repository.
|
||||
async repositoryForDirectory (directory) {
|
||||
// Only one GitRepository should be created for each .git folder. Therefore,
|
||||
// we must check directory and its parent directories to find the nearest
|
||||
// .git folder.
|
||||
const gitDir = await findGitDirectory(directory)
|
||||
return this.repositoryForGitDirectory(gitDir)
|
||||
}
|
||||
|
||||
// Returns either:
|
||||
// * {GitRepository} if the given directory has a Git repository.
|
||||
// * `null` if the given directory does not have a Git repository.
|
||||
repositoryForDirectorySync (directory) {
|
||||
// Only one GitRepository should be created for each .git folder. Therefore,
|
||||
// we must check directory and its parent directories to find the nearest
|
||||
// .git folder.
|
||||
const gitDir = findGitDirectorySync(directory)
|
||||
return this.repositoryForGitDirectory(gitDir)
|
||||
}
|
||||
|
||||
// Returns either:
|
||||
// * {GitRepository} if the given Git directory has a Git repository.
|
||||
// * `null` if the given directory does not have a Git repository.
|
||||
repositoryForGitDirectory (gitDir) {
|
||||
if (!gitDir) {
|
||||
return null
|
||||
}
|
||||
|
||||
const gitDirPath = gitDir.getPath()
|
||||
let repo = this.pathToRepository[gitDirPath]
|
||||
if (!repo) {
|
||||
repo = GitRepository.open(gitDirPath, { project: this.project, config: this.config })
|
||||
if (!repo) {
|
||||
return null
|
||||
}
|
||||
repo.onDidDestroy(() => delete this.pathToRepository[gitDirPath])
|
||||
this.pathToRepository[gitDirPath] = repo
|
||||
repo.refreshIndex()
|
||||
repo.refreshStatus()
|
||||
}
|
||||
return repo
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GitRepositoryProvider
|
||||
@@ -32,7 +32,17 @@ module.exports = ({blobStore}) ->
|
||||
|
||||
{testRunnerPath, legacyTestRunnerPath, headless, logFile, testPaths, env} = getWindowLoadSettings()
|
||||
|
||||
unless headless
|
||||
if headless
|
||||
# Install console functions that output to stdout and stderr.
|
||||
util = require 'util'
|
||||
|
||||
Object.defineProperties process,
|
||||
stdout: {value: remote.process.stdout}
|
||||
stderr: {value: remote.process.stderr}
|
||||
|
||||
console.log = (args...) -> process.stdout.write "#{util.format(args...)}\n"
|
||||
console.error = (args...) -> process.stderr.write "#{util.format(args...)}\n"
|
||||
else
|
||||
# Show window synchronously so a focusout doesn't fire on input elements
|
||||
# that are focused in the very first spec run.
|
||||
remote.getCurrentWindow().show()
|
||||
|
||||
@@ -23,6 +23,17 @@ const ConfigSchema = require('../config-schema')
|
||||
|
||||
const LocationSuffixRegExp = /(:\d+)(:\d+)?$/
|
||||
|
||||
const getDefaultPath = () => {
|
||||
const editor = atom.workspace.getActiveTextEditor()
|
||||
if (!editor || !editor.getPath()) {
|
||||
return
|
||||
}
|
||||
const paths = atom.project.getPaths()
|
||||
if (paths) {
|
||||
return paths[0]
|
||||
}
|
||||
}
|
||||
|
||||
// The application's singleton class.
|
||||
//
|
||||
// It's the entry point into the Atom application and maintains the global state
|
||||
@@ -392,6 +403,9 @@ class AtomApplication extends EventEmitter {
|
||||
this.on('application:check-for-update', () => this.autoUpdateManager.check())
|
||||
|
||||
if (process.platform === 'darwin') {
|
||||
this.on('application:open', () => this.promptForPathToOpen('all', getLoadSettings(), getDefaultPath()))
|
||||
this.on('application:open-file', () => this.promptForPathToOpen('file', getLoadSettings(), getDefaultPath()))
|
||||
this.on('application:open-folder', () => this.promptForPathToOpen('folder', getLoadSettings(), getDefaultPath()))
|
||||
this.on('application:bring-all-windows-to-front', () => Menu.sendActionToFirstResponder('arrangeInFront:'))
|
||||
this.on('application:hide', () => Menu.sendActionToFirstResponder('hide:'))
|
||||
this.on('application:hide-other-applications', () => Menu.sendActionToFirstResponder('hideOtherApplications:'))
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const Module = require('module')
|
||||
const path = require('path')
|
||||
const cachedVm = require('cached-run-in-this-context')
|
||||
const crypto = require('crypto')
|
||||
const vm = require('vm')
|
||||
|
||||
function computeHash (contents) {
|
||||
return crypto.createHash('sha1').update(contents, 'utf8').digest('hex')
|
||||
@@ -34,24 +34,6 @@ class NativeCompileCache {
|
||||
this.previousModuleCompile = Module.prototype._compile
|
||||
}
|
||||
|
||||
runInThisContext (code, filename) {
|
||||
// produceCachedData is deprecated after Node 10.6, will need to update
|
||||
// this for Electron 4.0 to use script.createCachedData()
|
||||
const script = new vm.Script(code, {filename, produceCachedData: true})
|
||||
return {
|
||||
result: script.runInThisContext(),
|
||||
cacheBuffer: script.cachedData
|
||||
}
|
||||
}
|
||||
|
||||
runInThisContextCached (code, filename, cachedData) {
|
||||
const script = new vm.Script(code, {filename, cachedData})
|
||||
return {
|
||||
result: script.runInThisContext(),
|
||||
wasRejected: script.cachedDataRejected
|
||||
}
|
||||
}
|
||||
|
||||
overrideModuleCompile () {
|
||||
let self = this
|
||||
// Here we override Node's module.js
|
||||
@@ -82,7 +64,7 @@ class NativeCompileCache {
|
||||
let compiledWrapper = null
|
||||
if (self.cacheStore.has(cacheKey)) {
|
||||
let buffer = self.cacheStore.get(cacheKey)
|
||||
let compilationResult = self.runInThisContextCached(wrapper, filename, buffer)
|
||||
let compilationResult = cachedVm.runInThisContextCached(wrapper, filename, buffer)
|
||||
compiledWrapper = compilationResult.result
|
||||
if (compilationResult.wasRejected) {
|
||||
self.cacheStore.delete(cacheKey)
|
||||
@@ -90,12 +72,12 @@ class NativeCompileCache {
|
||||
} else {
|
||||
let compilationResult
|
||||
try {
|
||||
compilationResult = self.runInThisContext(wrapper, filename)
|
||||
compilationResult = cachedVm.runInThisContext(wrapper, filename)
|
||||
} catch (err) {
|
||||
console.error(`Error running script ${filename}`)
|
||||
throw err
|
||||
}
|
||||
if (compilationResult.cacheBuffer !== null) {
|
||||
if (compilationResult.cacheBuffer) {
|
||||
self.cacheStore.set(cacheKey, compilationResult.cacheBuffer)
|
||||
}
|
||||
compiledWrapper = compilationResult.result
|
||||
|
||||
@@ -84,17 +84,17 @@ class Task
|
||||
|
||||
# Routes messages from the child to the appropriate event.
|
||||
handleEvents: ->
|
||||
@childProcess.removeAllListeners('message')
|
||||
@childProcess.removeAllListeners()
|
||||
@childProcess.on 'message', ({event, args}) =>
|
||||
@emitter.emit(event, args) if @childProcess?
|
||||
|
||||
# Catch the errors that happened before task-bootstrap.
|
||||
if @childProcess.stdout?
|
||||
@childProcess.stdout.removeAllListeners('data')
|
||||
@childProcess.stdout.removeAllListeners()
|
||||
@childProcess.stdout.on 'data', (data) -> console.log data.toString()
|
||||
|
||||
if @childProcess.stderr?
|
||||
@childProcess.stderr.removeAllListeners('data')
|
||||
@childProcess.stderr.removeAllListeners()
|
||||
@childProcess.stderr.on 'data', (data) -> console.error data.toString()
|
||||
|
||||
# Public: Starts the task.
|
||||
@@ -147,9 +147,9 @@ class Task
|
||||
terminate: ->
|
||||
return false unless @childProcess?
|
||||
|
||||
@childProcess.removeAllListeners('message')
|
||||
@childProcess.stdout?.removeAllListeners('data')
|
||||
@childProcess.stderr?.removeAllListeners('data')
|
||||
@childProcess.removeAllListeners()
|
||||
@childProcess.stdout?.removeAllListeners()
|
||||
@childProcess.stderr?.removeAllListeners()
|
||||
@childProcess.kill()
|
||||
@childProcess = null
|
||||
|
||||
|
||||
@@ -4446,7 +4446,7 @@ class NodePool {
|
||||
|
||||
if (element) {
|
||||
element.className = className || ''
|
||||
element.attributeStyleMap.forEach((value, key) => {
|
||||
element.styleMap.forEach((value, key) => {
|
||||
if (!style || style[key] == null) element.style[key] = ''
|
||||
})
|
||||
if (style) Object.assign(element.style, style)
|
||||
|
||||
Reference in New Issue
Block a user