Skip to content

Commit 5e3631e

Browse files
edgardmessiasJohnstonCode
authored andcommitted
refactor: Refactored function for isSvnFolder (#585)
1 parent 0981045 commit 5e3631e

File tree

2 files changed

+23
-28
lines changed

2 files changed

+23
-28
lines changed

src/model.ts

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
RepositoryState
1818
} from "./common/types";
1919
import { debounce } from "./decorators";
20-
import { exists, readdir, stat } from "./fs";
20+
import { readdir, stat } from "./fs";
2121
import { configuration } from "./helpers/configuration";
2222
import { RemoteRepository } from "./remoteRepository";
2323
import { Repository } from "./repository";
@@ -29,6 +29,7 @@ import {
2929
filterEvent,
3030
IDisposable,
3131
isDescendant,
32+
isSvnFolder,
3233
normalizePath
3334
} from "./util";
3435
import { matchAll } from "./util/globMatch";
@@ -219,34 +220,9 @@ export class Model implements IDisposable {
219220
return;
220221
}
221222

222-
let isSvnFolder = false;
223+
const checkParent = level === 0;
223224

224-
try {
225-
isSvnFolder = await exists(path + "/.svn");
226-
} catch (error) {
227-
// error
228-
}
229-
230-
// If open only a subpath.
231-
if (!isSvnFolder && level === 0) {
232-
const pathParts = path.split(/[\\/]/);
233-
while (pathParts.length > 0) {
234-
pathParts.pop();
235-
const topPath = pathParts.join("/") + "/.svn";
236-
237-
try {
238-
isSvnFolder = await exists(topPath);
239-
} catch (error) {
240-
// error
241-
}
242-
243-
if (isSvnFolder) {
244-
break;
245-
}
246-
}
247-
}
248-
249-
if (isSvnFolder) {
225+
if (isSvnFolder(path, checkParent)) {
250226
// Config based on folder path
251227
const resourceConfig = workspace.getConfiguration("svn", Uri.file(path));
252228

src/util.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,22 @@ export function fixPegRevision(file: string) {
198198

199199
return file;
200200
}
201+
202+
export async function isSvnFolder(dir: string, checkParent: boolean = true): Promise<boolean> {
203+
204+
const result = await exists(`${dir}/.svn`);
205+
206+
if (result || !checkParent) {
207+
return result;
208+
}
209+
210+
const parent = path.dirname(dir);
211+
212+
// For windows: the `path.dirname("c:")` return `c:`
213+
// For empty or doted dir, return "."
214+
if (parent === dir || parent === ".") {
215+
return false;
216+
}
217+
218+
return await isSvnFolder(parent, true);
219+
}

0 commit comments

Comments
 (0)