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

Commit

Permalink
Back out "Share underlying repository for multiple projects in the sa…
Browse files Browse the repository at this point in the history
…me repository"

Summary: There's a bug with this that I have a fix for, but I don't want to rush the fix for next release.  So backing this out

Reviewed By: aadisriram

Differential Revision: D7896068

fbshipit-source-id: 2e61fda96fdcbde630697acd72d954705344a742
  • Loading branch information
TJ Ryan authored and velocityboy committed May 9, 2018
1 parent a2c75e7 commit 516c0fb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 146 deletions.
27 changes: 7 additions & 20 deletions pkg/nuclide-hg-repository-client/lib/HgRepositoryClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ import featureConfig from 'nuclide-commons-atom/feature-config';
import observePaneItemVisibility from 'nuclide-commons-atom/observePaneItemVisibility';
import {observeBufferCloseOrRename} from '../../commons-atom/text-buffer';
import {getLogger} from 'log4js';
import nullthrows from 'nullthrows';

const STATUS_DEBOUNCE_DELAY_MS = 300;
const REVISION_DEBOUNCE_DELAY = 300;
Expand All @@ -77,7 +76,7 @@ type HgRepositoryOptions = {
workingDirectory: atom$Directory | RemoteDirectory,

/** The root directory that is opened in Atom, which this Repository serves. */
projectRootDirectory?: atom$Directory,
projectRootDirectory: atom$Directory,
};

/**
Expand Down Expand Up @@ -147,7 +146,7 @@ export type HgStatusChanges = {
export class HgRepositoryClient {
_path: string;
_workingDirectory: atom$Directory | RemoteDirectory;
_projectDirectory: ?atom$Directory;
_projectDirectory: atom$Directory;
_initializationPromise: Promise<void>;
_originURL: ?string;
_service: HgService;
Expand Down Expand Up @@ -233,7 +232,7 @@ export class HgRepositoryClient {
if (
filePath == null ||
filePath.length === 0 ||
!this.isPathRelevantToRepository(filePath)
!this.isPathRelevant(filePath)
) {
return Observable.empty();
}
Expand Down Expand Up @@ -546,12 +545,7 @@ export class HgRepositoryClient {
// @return The path of the root project folder in Atom that this
// HgRepositoryClient provides information about.
getProjectDirectory(): string {
return this.getInternalProjectDirectory().getPath();
}

// This function exists to be shadowed
getInternalProjectDirectory(): atom$Directory {
return nullthrows(this._projectDirectory);
return this._projectDirectory.getPath();
}

// TODO This is a stub.
Expand Down Expand Up @@ -733,15 +727,8 @@ export class HgRepositoryClient {
*/
isPathRelevant(filePath: NuclideUri): boolean {
return (
this.getInternalProjectDirectory().contains(filePath) ||
this.getInternalProjectDirectory().getPath() === filePath
);
}

isPathRelevantToRepository(filePath: NuclideUri): boolean {
return (
this._workingDirectory.contains(filePath) ||
this._workingDirectory.getPath() === filePath
this._projectDirectory.contains(filePath) ||
this._projectDirectory.getPath() === filePath
);
}

Expand Down Expand Up @@ -860,7 +847,7 @@ export class HgRepositoryClient {
): Observable<?Map<NuclideUri, DiffInfo>> {
const pathsToFetch = filePaths.filter(aPath => {
// Don't try to fetch information for this path if it's not in the repo.
if (!this.isPathRelevantToRepository(aPath)) {
if (!this.isPathRelevant(aPath)) {
return false;
}
// Don't do another update for this path if we are in the middle of running an update.
Expand Down
60 changes: 7 additions & 53 deletions pkg/nuclide-hg-repository/lib/HgRepositoryProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,9 @@ import {
import {HgRepositoryClient} from '../../nuclide-hg-repository-client';
import {getLogger} from 'log4js';
import {findHgRepository} from '../../nuclide-source-control-helpers';
import invariant from 'assert';

const logger = getLogger('nuclide-hg-repository');

type RefCountedRepo = {
refCount: number,
repo: HgRepositoryClient,
};

/**
* @param directory Either a RemoteDirectory or Directory we are interested in.
* @return If the directory is part of a Mercurial repository, returns an object
Expand Down Expand Up @@ -85,10 +79,6 @@ function getRepositoryDescription(
}

export default class HgRepositoryProvider {
// Allow having multiple project roots under the same repo while sharing
// the underlying HgRepositoryClient.
_activeRepositoryClients: Map<string, RefCountedRepo> = new Map();

repositoryForDirectory(directory: Directory): Promise<?HgRepositoryClient> {
return Promise.resolve(this.repositoryForDirectorySync(directory));
}
Expand All @@ -108,49 +98,13 @@ export default class HgRepositoryProvider {
workingDirectoryLocalPath,
} = repositoryDescription;

// extend the underlying instance of HgRepositoryClient to prevent
// having multiple clients for multiple project roots inside the same
// repository folder
const activeRepositoryClients = this._activeRepositoryClients;
let activeRepoClientInfo = activeRepositoryClients.get(repoPath);

if (activeRepoClientInfo != null) {
activeRepoClientInfo.refCount++;
} else {
const service = getHgServiceByNuclideUri(directory.getPath());
const hgService = new service.HgService(workingDirectoryLocalPath);
const activeRepoClient = new HgRepositoryClient(repoPath, hgService, {
workingDirectory,
originURL,
});

activeRepoClientInfo = {
refCount: 1,
repo: activeRepoClient,
};
activeRepositoryClients.set(repoPath, activeRepoClientInfo);
}

let destroyed = false;

/* eslint-disable no-inner-declarations */
function ProjectHgRepositoryClient() {
this.getInternalProjectDirectory = function(): atom$Directory {
return directory;
};
this.destroy = (): void => {
invariant(activeRepoClientInfo != null);
if (!destroyed && --activeRepoClientInfo.refCount === 0) {
destroyed = true;
activeRepoClientInfo.repo.destroy();
activeRepositoryClients.delete(repoPath);
}
};
}

ProjectHgRepositoryClient.prototype = activeRepoClientInfo.repo;

return (new ProjectHgRepositoryClient(): any);
const service = getHgServiceByNuclideUri(directory.getPath());
const hgService = new service.HgService(workingDirectoryLocalPath);
return new HgRepositoryClient(repoPath, hgService, {
workingDirectory,
projectRootDirectory: directory,
originURL,
});
} catch (err) {
logger.error(
'Failed to create an HgRepositoryClient for ',
Expand Down
73 changes: 0 additions & 73 deletions pkg/nuclide-hg-repository/spec/HgRepositoryProvider-spec.js

This file was deleted.

0 comments on commit 516c0fb

Please sign in to comment.