comparison src/org/tmatesoft/hg/repo/HgLookup.java @ 95:bcd31a4c638a

Lookup to HgLookup
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 27 Jan 2011 21:22:57 +0100
parents src/org/tmatesoft/hg/repo/Lookup.java@6f1b88693d48
children a3a2e5deb320
comparison
equal deleted inserted replaced
94:af1f3b78b918 95:bcd31a4c638a
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 HgLookup {
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 return detect(new File(location));
34 }
35
36 // look up in specified location and above
37 public HgRepository detect(File location) throws Exception {
38 File dir = location;
39 File repository;
40 do {
41 repository = new File(dir, ".hg");
42 if (repository.exists() && repository.isDirectory()) {
43 break;
44 }
45 repository = null;
46 dir = dir.getParentFile();
47
48 } while(dir != null);
49 if (repository == null) {
50 // return invalid repository
51 return new HgRepository(location.getPath());
52 }
53 return new HgRepository(repository);
54 }
55 }