Mercurial > jhg
comparison src/org/tmatesoft/hg/repo/HgLookup.java @ 578:f97e81d13190
Throw exception if repository encountered is too old for Hg4J
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Wed, 17 Apr 2013 16:02:52 +0200 |
parents | 2f9ed6bcefa2 |
children | 7c0d2ce340b8 |
comparison
equal
deleted
inserted
replaced
577:5d7399ade999 | 578:f97e81d13190 |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2010-2012 TMate Software Ltd | 2 * Copyright (c) 2010-2013 TMate Software Ltd |
3 * | 3 * |
4 * This program is free software; you can redistribute it and/or modify | 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 | 5 * it under the terms of the GNU General Public License as published by |
6 * the Free Software Foundation; version 2 of the License. | 6 * the Free Software Foundation; version 2 of the License. |
7 * | 7 * |
27 import org.tmatesoft.hg.core.SessionContext; | 27 import org.tmatesoft.hg.core.SessionContext; |
28 import org.tmatesoft.hg.internal.BasicSessionContext; | 28 import org.tmatesoft.hg.internal.BasicSessionContext; |
29 import org.tmatesoft.hg.internal.ConfigFile; | 29 import org.tmatesoft.hg.internal.ConfigFile; |
30 import org.tmatesoft.hg.internal.DataAccessProvider; | 30 import org.tmatesoft.hg.internal.DataAccessProvider; |
31 import org.tmatesoft.hg.internal.Internals; | 31 import org.tmatesoft.hg.internal.Internals; |
32 import org.tmatesoft.hg.internal.RequiresFile; | |
32 import org.tmatesoft.hg.repo.HgRepoConfig.PathsSection; | 33 import org.tmatesoft.hg.repo.HgRepoConfig.PathsSection; |
33 | 34 |
34 /** | 35 /** |
35 * Utility methods to find Mercurial repository at a given location | 36 * Utility methods to find Mercurial repository at a given location |
36 * | 37 * |
55 | 56 |
56 public HgRepository detect(String location) throws HgRepositoryNotFoundException { | 57 public HgRepository detect(String location) throws HgRepositoryNotFoundException { |
57 return detect(new File(location)); | 58 return detect(new File(location)); |
58 } | 59 } |
59 | 60 |
60 // look up in specified location and above | 61 /** |
62 * Look up repository in specified location and above | |
63 * | |
64 * @param location where to look for .hg directory, never <code>null</code> | |
65 * @return repository object, never <code>null</code> | |
66 * @throws HgRepositoryNotFoundException if no repository found, or repository version is not supported | |
67 */ | |
61 public HgRepository detect(File location) throws HgRepositoryNotFoundException { | 68 public HgRepository detect(File location) throws HgRepositoryNotFoundException { |
62 File dir = location.getAbsoluteFile(); | 69 File dir = location.getAbsoluteFile(); |
63 File repository; | 70 File repository; |
64 do { | 71 do { |
65 repository = new File(dir, ".hg"); | 72 repository = new File(dir, ".hg"); |
72 } while(dir != null); | 79 } while(dir != null); |
73 if (repository == null) { | 80 if (repository == null) { |
74 throw new HgRepositoryNotFoundException(String.format("Can't locate .hg/ directory of Mercurial repository in %s nor in parent dirs", location)).setLocation(location.getPath()); | 81 throw new HgRepositoryNotFoundException(String.format("Can't locate .hg/ directory of Mercurial repository in %s nor in parent dirs", location)).setLocation(location.getPath()); |
75 } | 82 } |
76 String repoPath = repository.getParentFile().getAbsolutePath(); | 83 String repoPath = repository.getParentFile().getAbsolutePath(); |
77 return new HgRepository(getContext(), repoPath, repository); | 84 HgRepository rv = new HgRepository(getContext(), repoPath, repository); |
85 int requiresFlags = rv.getImplHelper().getRequiresFlags(); | |
86 if ((requiresFlags & RequiresFile.REVLOGV1) == 0) { | |
87 throw new HgRepositoryNotFoundException(String.format("%s: repository version is not supported (Mercurial <0.9?)", repoPath)).setLocation(location.getPath()); | |
88 } | |
89 return rv; | |
78 } | 90 } |
79 | 91 |
80 public HgBundle loadBundle(File location) throws HgRepositoryNotFoundException { | 92 public HgBundle loadBundle(File location) throws HgRepositoryNotFoundException { |
81 if (location == null || !location.canRead()) { | 93 if (location == null || !location.canRead()) { |
82 throw new HgRepositoryNotFoundException(String.format("Can't read file %s", location)).setLocation(String.valueOf(location)); | 94 throw new HgRepositoryNotFoundException(String.format("Can't read file %s", location)).setLocation(String.valueOf(location)); |