comparison src/com/tmate/hgkit/fs/RepositoryLookup.java @ 2:08db726a0fb7

Shaping out low-level Hg structures
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Sun, 19 Dec 2010 05:41:31 +0100
parents
children aa1912c70b36
comparison
equal deleted inserted replaced
1:a3576694a4d1 2:08db726a0fb7
1 /**
2 * Copyright (c) 2010 Artem Tikhomirov
3 */
4 package com.tmate.hgkit.fs;
5
6 import java.io.File;
7
8 import com.tmate.hgkit.ll.HgRepository;
9 import com.tmate.hgkit.ll.LocalHgRepo;
10
11 /**
12 * @author artem
13 */
14 public class RepositoryLookup {
15
16 public HgRepository detect(String[] commandLineArgs) throws Exception {
17 if (commandLineArgs.length == 0) {
18 return detectFromWorkingDir();
19 }
20 return detect(commandLineArgs[0]);
21 }
22
23 public HgRepository detectFromWorkingDir() throws Exception {
24 return detect(System.getProperty("user.dir"));
25 }
26
27 public HgRepository detect(String location) throws Exception /*FIXME Exception type, RepoInitException? */ {
28 File dir = new File(location);
29 File repository;
30 do {
31 repository = new File(dir, ".hg");
32 if (repository.exists() && repository.isDirectory()) {
33 break;
34 }
35 repository = null;
36 dir = dir.getParentFile();
37
38 } while(dir != null);
39 if (repository == null) {
40 return new LocalHgRepo(location);
41 }
42 return new LocalHgRepo(repository);
43 }
44 }