comparison src/org/tmatesoft/hg/repo/Lookup.java @ 74:6f1b88693d48

Complete refactoring to org.tmatesoft
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 24 Jan 2011 03:14:45 +0100
parents src/com/tmate/hgkit/fs/RepositoryLookup.java@26e3eeaa3962
children
comparison
equal deleted inserted replaced
73:0d279bcc4442 74:6f1b88693d48
1 /*
2 * Copyright (c) 2010-2011 TMate Software Ltd
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * For information on how to redistribute this software under
14 * the terms of a license other than GNU General Public License
15 * contact TMate Software at support@svnkit.com
16 */
17 package org.tmatesoft.hg.repo;
18
19 import java.io.File;
20
21 /**
22 *
23 * @author Artem Tikhomirov
24 * @author TMate Software Ltd.
25 */
26 public class Lookup {
27
28 public HgRepository detectFromWorkingDir() throws Exception {
29 return detect(System.getProperty("user.dir"));
30 }
31
32 public HgRepository detect(String location) throws Exception /*FIXME Exception type, RepoInitException? */ {
33 File dir = new File(location);
34 File repository;
35 do {
36 repository = new File(dir, ".hg");
37 if (repository.exists() && repository.isDirectory()) {
38 break;
39 }
40 repository = null;
41 dir = dir.getParentFile();
42
43 } while(dir != null);
44 if (repository == null) {
45 return new HgRepository(location);
46 }
47 return new HgRepository(repository);
48 }
49 }