Mercurial > hg4j
changeset 95:bcd31a4c638a
Lookup to HgLookup
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 27 Jan 2011 21:22:57 +0100 |
parents | af1f3b78b918 |
children | ace7042a5ce6 |
files | cmdline/org/tmatesoft/hg/console/Options.java src/org/tmatesoft/hg/core/RepositoryFacade.java src/org/tmatesoft/hg/repo/HgLookup.java src/org/tmatesoft/hg/repo/Lookup.java test/org/tmatesoft/hg/test/TestHistory.java test/org/tmatesoft/hg/test/TestManifest.java test/org/tmatesoft/hg/test/TestStatus.java |
diffstat | 7 files changed, 67 insertions(+), 61 deletions(-) [+] |
line wrap: on
line diff
--- a/cmdline/org/tmatesoft/hg/console/Options.java Thu Jan 27 21:18:47 2011 +0100 +++ b/cmdline/org/tmatesoft/hg/console/Options.java Thu Jan 27 21:22:57 2011 +0100 @@ -26,7 +26,7 @@ import java.util.Set; import org.tmatesoft.hg.repo.HgRepository; -import org.tmatesoft.hg.repo.Lookup; +import org.tmatesoft.hg.repo.HgLookup; /** * Parse command-line options @@ -44,9 +44,9 @@ public HgRepository findRepository() throws Exception { if (repoLocation != null) { - return new Lookup().detect(repoLocation); + return new HgLookup().detect(repoLocation); } - return new Lookup().detectFromWorkingDir(); + return new HgLookup().detectFromWorkingDir(); }
--- a/src/org/tmatesoft/hg/core/RepositoryFacade.java Thu Jan 27 21:18:47 2011 +0100 +++ b/src/org/tmatesoft/hg/core/RepositoryFacade.java Thu Jan 27 21:22:57 2011 +0100 @@ -19,7 +19,7 @@ import java.io.File; import org.tmatesoft.hg.repo.HgRepository; -import org.tmatesoft.hg.repo.Lookup; +import org.tmatesoft.hg.repo.HgLookup; /** * @@ -33,12 +33,12 @@ } public boolean init() throws Exception /*FIXME RepoInitException*/ { - repo = new Lookup().detectFromWorkingDir(); + repo = new HgLookup().detectFromWorkingDir(); return repo != null && !repo.isInvalid(); } public boolean initFrom(File repoLocation) throws Exception { - repo = new Lookup().detect(repoLocation.getCanonicalPath()); + repo = new HgLookup().detect(repoLocation.getCanonicalPath()); return repo != null && !repo.isInvalid(); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/tmatesoft/hg/repo/HgLookup.java Thu Jan 27 21:22:57 2011 +0100 @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2010-2011 TMate Software Ltd + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * For information on how to redistribute this software under + * the terms of a license other than GNU General Public License + * contact TMate Software at support@svnkit.com + */ +package org.tmatesoft.hg.repo; + +import java.io.File; + +/** + * + * @author Artem Tikhomirov + * @author TMate Software Ltd. + */ +public class HgLookup { + + public HgRepository detectFromWorkingDir() throws Exception { + return detect(System.getProperty("user.dir")); + } + + public HgRepository detect(String location) throws Exception /*FIXME Exception type, RepoInitException? */ { + return detect(new File(location)); + } + + // look up in specified location and above + public HgRepository detect(File location) throws Exception { + File dir = location; + File repository; + do { + repository = new File(dir, ".hg"); + if (repository.exists() && repository.isDirectory()) { + break; + } + repository = null; + dir = dir.getParentFile(); + + } while(dir != null); + if (repository == null) { + // return invalid repository + return new HgRepository(location.getPath()); + } + return new HgRepository(repository); + } +}
--- a/src/org/tmatesoft/hg/repo/Lookup.java Thu Jan 27 21:18:47 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2010-2011 TMate Software Ltd - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * For information on how to redistribute this software under - * the terms of a license other than GNU General Public License - * contact TMate Software at support@svnkit.com - */ -package org.tmatesoft.hg.repo; - -import java.io.File; - -/** - * - * @author Artem Tikhomirov - * @author TMate Software Ltd. - */ -public class Lookup { - - public HgRepository detectFromWorkingDir() throws Exception { - return detect(System.getProperty("user.dir")); - } - - public HgRepository detect(String location) throws Exception /*FIXME Exception type, RepoInitException? */ { - File dir = new File(location); - File repository; - do { - repository = new File(dir, ".hg"); - if (repository.exists() && repository.isDirectory()) { - break; - } - repository = null; - dir = dir.getParentFile(); - - } while(dir != null); - if (repository == null) { - return new HgRepository(location); - } - return new HgRepository(repository); - } -}
--- a/test/org/tmatesoft/hg/test/TestHistory.java Thu Jan 27 21:18:47 2011 +0100 +++ b/test/org/tmatesoft/hg/test/TestHistory.java Thu Jan 27 21:22:57 2011 +0100 @@ -27,7 +27,7 @@ import org.tmatesoft.hg.core.LogCommand.FileRevision; import org.tmatesoft.hg.core.Path; import org.tmatesoft.hg.repo.HgRepository; -import org.tmatesoft.hg.repo.Lookup; +import org.tmatesoft.hg.repo.HgLookup; import org.tmatesoft.hg.test.LogOutputParser.Record; @@ -43,7 +43,7 @@ private LogOutputParser changelogParser; public static void main(String[] args) throws Exception { - TestHistory th = new TestHistory(new Lookup().detectFromWorkingDir()); + TestHistory th = new TestHistory(new HgLookup().detectFromWorkingDir()); th.testCompleteLog(); th.testFollowHistory(); }
--- a/test/org/tmatesoft/hg/test/TestManifest.java Thu Jan 27 21:18:47 2011 +0100 +++ b/test/org/tmatesoft/hg/test/TestManifest.java Thu Jan 27 21:22:57 2011 +0100 @@ -27,7 +27,7 @@ import org.tmatesoft.hg.core.Path; import org.tmatesoft.hg.core.RepositoryTreeWalker; import org.tmatesoft.hg.repo.HgRepository; -import org.tmatesoft.hg.repo.Lookup; +import org.tmatesoft.hg.repo.HgLookup; /** @@ -53,7 +53,7 @@ }; public static void main(String[] args) throws Exception { - HgRepository repo = new Lookup().detectFromWorkingDir(); + HgRepository repo = new HgLookup().detectFromWorkingDir(); TestManifest tm = new TestManifest(repo); tm.testTip(); tm.testFirstRevision();
--- a/test/org/tmatesoft/hg/test/TestStatus.java Thu Jan 27 21:18:47 2011 +0100 +++ b/test/org/tmatesoft/hg/test/TestStatus.java Thu Jan 27 21:22:57 2011 +0100 @@ -26,7 +26,7 @@ import org.tmatesoft.hg.core.Path; import org.tmatesoft.hg.core.StatusCommand; import org.tmatesoft.hg.repo.HgRepository; -import org.tmatesoft.hg.repo.Lookup; +import org.tmatesoft.hg.repo.HgLookup; import org.tmatesoft.hg.repo.HgStatusCollector; import org.tmatesoft.hg.repo.HgWorkingCopyStatusCollector; @@ -43,7 +43,7 @@ private ExecHelper eh; public static void main(String[] args) throws Exception { - HgRepository repo = new Lookup().detectFromWorkingDir(); + HgRepository repo = new HgLookup().detectFromWorkingDir(); TestStatus test = new TestStatus(repo); test.testLowLevel(); // test.testStatusCommand();