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

Commit

Permalink
Mercurial: Fix #726 Atom freezing when opening preferences
Browse files Browse the repository at this point in the history
Summary:
Open `atom://` uris had a `nuclideUri.join(directoryPath, '..')` which can go in an infinite loop.
Replacing with `nuclideUri.dirname` fixes that and makes the code more friendly with windows directory paths.

Reviewed By: shushz

Differential Revision: D3908314

fbshipit-source-id: 88985638cc5598943f516f4f4cc342c36039c2a7
  • Loading branch information
mostafaeweda authored and Facebook Github Bot 3 committed Sep 22, 2016
1 parent 697bfc5 commit ac43a48
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
14 changes: 9 additions & 5 deletions pkg/commons-node/nuclideUri.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,13 @@ function isBrokenDeserializedUri(uri: ?NuclideUri): boolean {
return uri != null && uri.match(/nuclide:[\\/][^/]/) != null;
}

function isUri(uri: string): boolean {
const parsedUri = url.parse(_escapeSpecialCharacters(uri));
return parsedUri.protocol != null;
}

function isLocal(uri: NuclideUri): boolean {
return !isRemote(uri);
return !isRemote(uri) && !isUri(uri);
}

function createRemoteUri(hostname: string, remotePath: string): string {
Expand All @@ -98,7 +103,8 @@ function createRemoteUri(hostname: string, remotePath: string): string {
* }
*/
function parse(uri: NuclideUri): ParsedUrl {
if (isLocal(uri)) {
const parsedUri = url.parse(_escapeSpecialCharacters(uri));
if (parsedUri.protocol == null) {
return {
auth: null,
host: null,
Expand All @@ -113,8 +119,6 @@ function parse(uri: NuclideUri): ParsedUrl {
};
}

const parsedUri = url.parse(_escapeSpecialCharacters(uri));

invariant(
parsedUri.path,
'Nuclide URIs must contain paths, ' +
Expand Down Expand Up @@ -192,7 +196,7 @@ function getHostname(remoteUri: NuclideUri): string {
}

function getHostnameOpt(remoteUri: ?NuclideUri): ?string {
if (remoteUri == null || isLocal(remoteUri)) {
if (remoteUri == null || !isRemote(remoteUri)) {
return null;
}

Expand Down
5 changes: 4 additions & 1 deletion pkg/nuclide-source-control-helpers/lib/hg-repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import type {HgRepositoryDescription} from '..';
* originURL iff it finds that the given directory is within an Hg repository.
*/
export default function findHgRepository(startDirectoryPath: string): ?HgRepositoryDescription {
if (!nuclideUri.isLocal(startDirectoryPath)) {
return null;
}
let workingDirectoryPath = startDirectoryPath;
for (;;) {
const repoPath = nuclideUri.join(workingDirectoryPath, '.hg');
Expand All @@ -35,7 +38,7 @@ export default function findHgRepository(startDirectoryPath: string): ?HgReposit
}
return {repoPath, originURL, workingDirectoryPath};
}
const parentDir = nuclideUri.join(workingDirectoryPath, '..');
const parentDir = nuclideUri.dirname(workingDirectoryPath);
if (parentDir === workingDirectoryPath) {
return null;
} else {
Expand Down

0 comments on commit ac43a48

Please sign in to comment.