# HG changeset patch # User Artem Tikhomirov # Date 1296159777 -3600 # Node ID bcd31a4c638af878c619177399e0f5ee99a9d7bd # Parent af1f3b78b9180ba635d746add5977394c545b92c Lookup to HgLookup diff -r af1f3b78b918 -r bcd31a4c638a cmdline/org/tmatesoft/hg/console/Options.java --- 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(); } diff -r af1f3b78b918 -r bcd31a4c638a src/org/tmatesoft/hg/core/RepositoryFacade.java --- 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(); } diff -r af1f3b78b918 -r bcd31a4c638a src/org/tmatesoft/hg/repo/HgLookup.java --- /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); + } +} diff -r af1f3b78b918 -r bcd31a4c638a src/org/tmatesoft/hg/repo/Lookup.java --- 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); - } -} diff -r af1f3b78b918 -r bcd31a4c638a test/org/tmatesoft/hg/test/TestHistory.java --- 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(); } diff -r af1f3b78b918 -r bcd31a4c638a test/org/tmatesoft/hg/test/TestManifest.java --- 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(); diff -r af1f3b78b918 -r bcd31a4c638a test/org/tmatesoft/hg/test/TestStatus.java --- 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();