Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 544d547

Browse files
author
Nathan Sobo
authored
Merge pull request atom#183 from atom/as-embed-nodegit
Embed nodegit 0.14.1
2 parents 6002a4d + 6e73690 commit 544d547

File tree

9 files changed

+76
-79
lines changed

9 files changed

+76
-79
lines changed

.npmrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
runtime = electron
2+
target_arch = x64
3+
target = 0.37.8
24
disturl = https://atom.io/download/atom-shell
5+
progress = true

.travis.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1-
language: objective-c
1+
os: osx
2+
3+
language: node_js
4+
5+
node_js:
6+
- '4.4.7'
7+
8+
env:
9+
- ATOM_CHANNEL=beta
210

311
notifications:
412
email:
513
on_success: never
614
on_failure: change
715

16+
install:
17+
- npm install -g npm
18+
819
script:
920
- ./script/cibuild

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
11
# GitHub Package
2+
3+
To install dependencies make sure your npm version is higher than `3` and then run:
4+
5+
```bash
6+
npm install
7+
```
8+
9+
**Please, note that `apm install` won't work (for now).**

lib/github-package.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,14 @@ export default class GithubPackage {
127127

128128
async repositoryForProjectDirectory (projectDirectory) {
129129
let repository = this.repositoriesByProjectDirectory.get(projectDirectory)
130-
131130
if (!repository) {
132-
const atomRepository = await this.project.repositoryForDirectory(projectDirectory)
133-
if (atomRepository == null) {
134-
return
135-
} else {
136-
const rawRepositoryPool = await atomRepository.async.repo.repoPool
137-
repository = new Repository(rawRepositoryPool, projectDirectory)
131+
try {
132+
repository = await Repository.open(projectDirectory)
138133
this.repositoriesByProjectDirectory.set(projectDirectory, repository)
134+
} catch (e) {
135+
repository = null
139136
}
140137
}
141-
142138
return repository
143139
}
144140

@@ -148,8 +144,9 @@ export default class GithubPackage {
148144

149145
destroyRepositoriesForRemovedProjectFolders () {
150146
const projectDirectories = this.project.getDirectories()
151-
for (let [projectDirectory] of this.repositoriesByProjectDirectory) {
147+
for (let [projectDirectory, repository] of this.repositoriesByProjectDirectory) {
152148
if (projectDirectories.indexOf(projectDirectory) === -1) {
149+
repository.destroy()
153150
this.repositoriesByProjectDirectory.delete(projectDirectory)
154151
}
155152
}

lib/models/repository.js

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,60 @@
11
/** @babel */
22

3-
import {GitRepositoryAsync, Emitter} from 'atom'
4-
const Git = GitRepositoryAsync.Git
3+
import {Emitter} from 'atom'
4+
import Git from 'nodegit'
5+
import {applyPatch} from 'diff'
56

67
import FilePatch from './file-patch'
78
import Hunk from './hunk'
89
import HunkLine from './hunk-line'
910

10-
import {applyPatch} from 'diff'
11-
1211
const diffOpts = {flags: Git.Diff.OPTION.SHOW_UNTRACKED_CONTENT | Git.Diff.OPTION.RECURSE_UNTRACKED_DIRS}
1312
const findOpts = {flags: Git.Diff.FIND.RENAMES | Git.Diff.FIND.FOR_UNTRACKED}
1413

1514
export default class Repository {
16-
constructor (rawRepositoryPool, workingDirectory) {
17-
this.rawRepositoryPool = rawRepositoryPool
15+
static async open (workingDirectory) {
16+
const rawRepository = await Git.Repository.open(workingDirectory.getPath())
17+
return new Repository(rawRepository, workingDirectory)
18+
}
19+
20+
constructor (rawRepository, workingDirectory) {
21+
this.rawRepository = rawRepository
1822
this.workingDirectory = workingDirectory
19-
this.rawRepository = null
23+
this.transactions = []
2024
this.emitter = new Emitter()
2125
this.stagedFilePatchesById = new Map()
2226
this.unstagedFilePatchesById = new Map()
2327
}
2428

25-
transact (fn) {
26-
if (this.rawRepository) throw new Error('A transaction is already started. Nested transactions are not supported.')
29+
destroy () {
30+
this.emitter.dispose()
31+
this.rawRepository = null
32+
}
33+
34+
async transact (criticalSection) {
35+
return new Promise((resolve, reject) => {
36+
this.transactions.push({criticalSection, resolve, reject})
37+
if (this.transactions.length === 1) {
38+
this.processTransactions()
39+
}
40+
})
41+
}
2742

28-
return this.rawRepositoryPool.enqueue(async (rawRepositoryPromise) => {
43+
async processTransactions () {
44+
while (this.transactions.length > 0) {
45+
const {criticalSection, resolve, reject} = this.transactions[0]
2946
try {
30-
this.rawRepository = await rawRepositoryPromise
31-
let result = await fn()
32-
return result
47+
resolve(await criticalSection())
48+
} catch (e) {
49+
reject(e)
3350
} finally {
34-
this.rawRepository = null
51+
this.transactions.shift()
3552
}
36-
})
53+
}
3754
}
3855

3956
autoTransact (fn) {
40-
if (this.rawRepository) {
41-
return fn(this.rawRepository)
42-
} else {
43-
return this.transact(() => fn(this.rawRepository))
44-
}
57+
return this.transactions.length > 0 ? fn() : this.transact(fn)
4558
}
4659

4760
onDidUpdate (callback) {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"diff": "2.2.2",
1818
"etch": "0.6.0",
1919
"multi-list-selection": "^0.1.1",
20+
"nodegit": "0.14.1",
2021
"nsfw": "1.0.12"
2122
},
2223
"devDependencies": {

script/cibuild

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ if [ "$TRAVIS_OS_NAME" = "osx" ]; then
2323
export ATOM_SCRIPT_PATH="./atom-${ATOM_CHANNEL}"
2424
ln -s "./atom/${ATOM_APP_NAME}/Contents/Resources/app/atom.sh" "${ATOM_SCRIPT_PATH}"
2525
fi
26-
export PATH="$PWD/atom/${ATOM_APP_NAME}/Contents/Resources/app/apm/bin:$PATH"
2726
export ATOM_PATH="./atom"
2827
export APM_SCRIPT_PATH="./atom/${ATOM_APP_NAME}/Contents/Resources/app/apm/node_modules/.bin/apm"
2928
else
@@ -44,39 +43,17 @@ else
4443
export APM_SCRIPT_PATH="$HOME/atom/usr/bin/$APM_SCRIPT_NAME"
4544
fi
4645

47-
4846
echo "Using Atom version:"
49-
"$ATOM_SCRIPT_PATH" -v
50-
echo "Using APM version:"
51-
"$APM_SCRIPT_PATH" -v
47+
"$ATOM_SCRIPT_PATH" --version
48+
echo "Using apm version:"
49+
"$APM_SCRIPT_PATH" --version
50+
echo "Using node version:"
51+
node --version
52+
echo "Using npm version:"
53+
npm --version
5254

5355
echo "Downloading package dependencies..."
54-
"$APM_SCRIPT_PATH" rebuild-module-cache
55-
"$APM_SCRIPT_PATH" clean
56-
"$APM_SCRIPT_PATH" install
57-
"$APM_SCRIPT_PATH" install
58-
59-
TEST_PACKAGES="${APM_TEST_PACKAGES:=none}"
60-
61-
if [ "$TEST_PACKAGES" != "none" ]; then
62-
echo "Installing atom package dependencies..."
63-
for pack in $TEST_PACKAGES ; do
64-
"$APM_SCRIPT_PATH" install $pack
65-
done
66-
fi
67-
68-
# if [ -f ./node_modules/.bin/eslint ]; then
69-
# if [ -d ./lib ]; then
70-
# echo "Linting package..."
71-
# ./node_modules/.bin/eslint lib
72-
# rc=$?; if [ $rc -ne 0 ]; then exit $rc; fi
73-
# fi
74-
# if [ -d ./spec ]; then
75-
# echo "Linting package specs..."
76-
# ./node_modules/.bin/eslint spec
77-
# rc=$?; if [ $rc -ne 0 ]; then exit $rc; fi
78-
# fi
79-
# fi
56+
npm install
8057

8158
echo "Running specs..."
8259
"$ATOM_SCRIPT_PATH" --test test

test/helpers.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
import fs from 'fs-extra'
44
import path from 'path'
55
import temp from 'temp'
6-
import {GitRepositoryAsync, Directory} from 'atom'
7-
8-
const Git = GitRepositoryAsync.Git
6+
import {Directory} from 'atom'
7+
import Git from 'nodegit'
98

109
import Repository from '../lib/models/repository'
1110

@@ -16,10 +15,8 @@ export function copyRepositoryDir (variant = 1) {
1615
return fs.realpathSync(workingDirPath)
1716
}
1817

19-
export async function buildRepository (workingDirPath) {
20-
const atomRepository = new GitRepositoryAsync(workingDirPath, {project: null, refreshOnWindowFocus: false, subscribeToBuffers: false})
21-
const rawRepositoryPool = atomRepository.repo.repoPool
22-
return new Repository(rawRepositoryPool, new Directory(workingDirPath))
18+
export function buildRepository (workingDirPath) {
19+
return Repository.open(new Directory(workingDirPath))
2320
}
2421

2522
export function assertDeepPropertyVals (actual, expected) {

test/models/repository.test.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
/** @babel */
22

3-
import {GitRepositoryAsync} from 'atom'
43
import fs from 'fs'
54
import path from 'path'
65
import sinon from 'sinon'
6+
import Git from 'nodegit'
77

88
import {copyRepositoryDir, buildRepository, assertDeepPropertyVals, cloneRepository, createEmptyCommit} from '../helpers'
99

10-
const Git = GitRepositoryAsync.Git
11-
1210
describe('Repository', () => {
1311
describe('transact', () => {
1412
it('serializes critical sections', async () => {
@@ -38,14 +36,6 @@ describe('Repository', () => {
3836
assert.deepEqual(actualEvents, expectedEvents)
3937
})
4038

41-
it('does not allow transactions to nest', async () => {
42-
const workingDirPath = copyRepositoryDir(1)
43-
const repo = await buildRepository(workingDirPath)
44-
await repo.transact(function () {
45-
assert.throws(() => repo.transact(), /Nested transaction/)
46-
})
47-
})
48-
4939
it('allows to create a new transaction if the previous one throws an error', async () => {
5040
const workingDirPath = copyRepositoryDir(1)
5141
const repo = await buildRepository(workingDirPath)

0 commit comments

Comments
 (0)