Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
👕 👕 👕
Browse files Browse the repository at this point in the history
  • Loading branch information
smashwilson committed Feb 19, 2018
1 parent 7a85cb6 commit 96c1cf9
Show file tree
Hide file tree
Showing 14 changed files with 272 additions and 223 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"parser": "babel-eslint",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
"jsx": true,
"experimentalDecorators": true,
}
},
"settings": {
Expand Down
5 changes: 5 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"experimentalDecorators": true
}
}
74 changes: 0 additions & 74 deletions lib/github-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,6 @@ import AsyncQueue from './async-queue';
import WorkerManager from './worker-manager';
import getRepoPipelineManager from './get-repo-pipeline-manager';

function logFn(target, key, descriptor) {
const orig = descriptor.value;
descriptor.value = function(...args) {
let name;
if (target && target.name) {
name = `${target.name}.${key}`;
} else if (this.constructor && this.constructor.name) {
name = `${this.constructor.name}#${key}`;
} else {
name = `<Unknown>#${key}`;
}
console.log(`> START: ${name}`);
const value = orig.apply(this, args);
console.log(`> END: ${name}`);
return value;
};
}


const defaultState = {
};

Expand Down Expand Up @@ -105,7 +86,6 @@ export default class GithubPackage {
this.filePatchItems = [];
}

@logFn
setupYardstick() {
const stagingSeries = ['stageLine', 'stageHunk', 'unstageLine', 'unstageHunk'];

Expand Down Expand Up @@ -159,7 +139,6 @@ export default class GithubPackage {
);
}

@logFn
async activate(state = {}) {
this.savedState = {...defaultState, ...state};

Expand Down Expand Up @@ -271,7 +250,6 @@ export default class GithubPackage {
this.rerender();
}

@logFn
serialize() {
const activeRepository = this.getActiveRepository();
const activeRepositoryPath = activeRepository ? activeRepository.getWorkingDirectoryPath() : null;
Expand All @@ -283,27 +261,22 @@ export default class GithubPackage {
}

rerender(callback) {
console.log('> inside rerender... callback??', !!callback);
if (this.workspace.isDestroyed()) {
console.log('workspace is destroyed, returning early');
return;
}

if (!this.activated) {
console.log('package is not activated, returning early');
return;
}

if (!this.element) {
console.log('no element, creating it');
this.element = document.createElement('div');
this.subscriptions.add(new Disposable(() => {
ReactDom.unmountComponentAtNode(this.element);
delete this.element;
}));
}

console.log('finally calling ReactDom.render()');
ReactDom.render(
<RootController
ref={c => { this.controller = c; }}
Expand Down Expand Up @@ -332,10 +305,8 @@ export default class GithubPackage {
getRepositoryForWorkdir={this.getRepositoryForWorkdir}
/>, this.element, callback,
);
console.log('Done with rerender!');
}

@logFn
async deactivate() {
this.subscriptions.dispose();
this.contextPool.clear();
Expand All @@ -348,26 +319,22 @@ export default class GithubPackage {
}

@autobind
@logFn
consumeStatusBar(statusBar) {
this.statusBar = statusBar;
this.rerender();
}

@autobind
@logFn
createGitTimingsView() {
return GitTimingsView.createPaneItem();
}

@autobind
@logFn
createIssueishPaneItem({uri}) {
return IssueishPaneItem.opener(uri);
}

@autobind
@logFn
createDockItemStub({uri}) {
let item;
switch (uri) {
Expand All @@ -392,22 +359,19 @@ export default class GithubPackage {
return item;
}

@logFn
createGitTabControllerStub(uri) {
return StubItem.create('git-tab-controller', {
title: 'Git',
}, uri);
}

@logFn
createGithubTabControllerStub(uri) {
return StubItem.create('github-tab-controller', {
title: 'GitHub (preview)',
}, uri);
}

@autobind
@logFn
createFilePatchControllerStub({uri} = {}) {
const item = StubItem.create('git-file-patch-controller', {
title: 'Diff',
Expand All @@ -420,7 +384,6 @@ export default class GithubPackage {
}

@autobind
@logFn
destroyGitTabItem() {
if (this.gitTabStubItem) {
this.gitTabStubItem.destroy();
Expand All @@ -432,7 +395,6 @@ export default class GithubPackage {
}

@autobind
@logFn
destroyGithubTabItem() {
if (this.githubTabStubItem) {
this.githubTabStubItem.destroy();
Expand All @@ -452,7 +414,6 @@ export default class GithubPackage {
}

@autobind
@logFn
async createRepositoryForProjectPath(projectPath) {
await mkdirs(projectPath);

Expand All @@ -468,7 +429,6 @@ export default class GithubPackage {
}

@autobind
@logFn
async cloneRepositoryForProjectPath(remoteUrl, projectPath) {
const context = this.contextPool.getContext(projectPath);
let repository;
Expand All @@ -489,39 +449,32 @@ export default class GithubPackage {
}

@autobind
@logFn
getRepositoryForWorkdir(projectPath) {
const loadingGuessRepo = Repository.loadingGuess({pipelineManager: this.pipelineManager});
return this.guessedContext ? loadingGuessRepo : this.contextPool.getContext(projectPath).getRepository();
}

@logFn
getActiveWorkdir() {
return this.activeContext.getWorkingDirectory();
}

@logFn
getActiveRepository() {
return this.activeContext.getRepository();
}

@logFn
getActiveResolutionProgress() {
return this.activeContext.getResolutionProgress();
}

@logFn
getContextPool() {
return this.contextPool;
}

@logFn
getSwitchboard() {
return this.switchboard;
}

@autobind
@logFn
async scheduleActiveContextUpdate(savedState = {}) {
this.switchboard.didScheduleActiveContextUpdate();
await this.activeContextQueue.push(this.updateActiveContext.bind(this, savedState), {parallel: false});
Expand All @@ -540,7 +493,6 @@ export default class GithubPackage {
* First updates the pool of resident contexts to match all git working directories that correspond to open
* projects and pane items.
*/
@logFn
async getNextContext(savedState) {
const workdirs = new Set(
await Promise.all(
Expand All @@ -550,107 +502,81 @@ export default class GithubPackage {
}),
),
);
console.log('got all the workdirs');

const fromPaneItem = async maybeItem => {
const itemPath = pathForPaneItem(maybeItem);

if (!itemPath) {
console.log('no item path, returning early');
return {};
}

console.log('getting itemWorkdir from the workdirCache');
const itemWorkdir = await this.workdirCache.find(itemPath);

console.log('maybe adding to workdirs set');
if (itemWorkdir && !this.project.contains(itemPath)) {
workdirs.add(itemWorkdir);
}

console.log('got an item in fromPaneItem! returning', itemPath, itemWorkdir);
return {itemPath, itemWorkdir};
};

console.log('getting active item');
const active = await fromPaneItem(this.workspace.getCenter().getActivePaneItem());

console.log('setting contextPool');
this.contextPool.set(workdirs, savedState);

if (active.itemPath) {
// Prefer an active item
console.log('returning context from contextPool (active.itemPath is truthy)');
return this.contextPool.getContext(active.itemWorkdir || active.itemPath);
}

if (this.project.getPaths().length === 1) {
console.log('inside getPaths().length === 1');
// Single project
const projectPath = this.project.getPaths()[0];
const activeWorkingDir = await this.workdirCache.find(projectPath);
console.log('returning context from contextPool (getPaths().length === 1)');
return this.contextPool.getContext(activeWorkingDir || projectPath);
}

if (this.project.getPaths().length === 0 && !this.activeContext.getRepository().isUndetermined()) {
// No projects. Revert to the absent context unless we've guessed that more projects are on the way.
console.log('no paths and repo is undetermined; return absent');
return WorkdirContext.absent({pipelineManager: this.pipelineManager});
}

// Restore models from saved state. Will return a NullWorkdirContext if this path is not presently
// resident in the pool.
const savedWorkingDir = savedState.activeRepositoryPath;
if (savedWorkingDir) {
console.log('returning savedWorkingDir');
return this.contextPool.getContext(savedWorkingDir);
}

console.log('returning this.activeContext', !!this.activeContext);
return this.activeContext;
}

@logFn
setActiveContext(nextActiveContext) {
console.log('> START setActiveContext');
if (nextActiveContext !== this.activeContext) {
if (this.activeContext === this.guessedContext) {
this.guessedContext.destroy();
this.guessedContext = null;
}
console.log('activeContext set, rerendering');
this.activeContext = nextActiveContext;
console.log('starting rerender');
this.rerender(() => {
console.log('finished rerender, triggering didFinishActiveContextUpdate');
this.switchboard.didFinishContextChangeRender();
this.switchboard.didFinishActiveContextUpdate();
});
} else {
console.log('got into the else case, triggering didFinishActiveContextUpdate');
this.switchboard.didFinishActiveContextUpdate();
}
console.log('> END setActiveContext');
}

@logFn
async updateActiveContext(savedState = {}) {
if (this.workspace.isDestroyed()) {
console.log('returning early from here');
return;
}

console.log('triggering didBeginActiveContextUpdate');
this.switchboard.didBeginActiveContextUpdate();

console.log('getting the next context');
const nextActiveContext = await this.getNextContext(savedState);
console.log('about to call setActiveContext with', !!nextActiveContext);
this.setActiveContext(nextActiveContext);
}

@logFn
refreshAtomGitRepository(workdir) {
const atomGitRepo = this.project.getRepositories().find(repo => {
return repo && path.normalize(repo.getWorkingDirectory()) === workdir;
Expand Down
11 changes: 4 additions & 7 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import fs from 'fs-extra';
import os from 'os';
import temp from 'temp';
import {ncp} from 'ncp';
import realpathNative from 'realpath-native';

import FilePatchController from './controllers/file-patch-controller';

Expand Down Expand Up @@ -205,18 +204,16 @@ export function getTempDir(options = {}) {
if (options.symlinkOk) {
resolve(folder);
} else {
resolve(realpathNative(folder));
// fs.realpath(folder, (realError, rpath) => (realError ? reject(realError) : resolve(rpath)));
fs.realpath(folder, (realError, rpath) => (realError ? reject(realError) : resolve(rpath)));
}
});
});
}

export function realPath(folder) {
return realpathNative(folder);
// return new Promise((resolve, reject) => {
// fs.realpath(folder, (err, rpath) => (err ? reject(err) : resolve(rpath)));
// });
return new Promise((resolve, reject) => {
fs.realpath(folder, (err, rpath) => (err ? reject(err) : resolve(rpath)));
});
}

export function fsStat(absoluteFilePath) {
Expand Down
Loading

0 comments on commit 96c1cf9

Please sign in to comment.