Mercurial > jhg
comparison src/org/tmatesoft/hg/repo/HgRepositoryFiles.java @ 647:c75297c17867
Location of repository files as enumeration, use file constants instead of plain names
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
|---|---|
| date | Tue, 25 Jun 2013 18:53:18 +0200 |
| parents | 5afc7eedb3dd |
| children | 42b88709e41d |
comparison
equal
deleted
inserted
replaced
| 646:3b7d51ed4c65 | 647:c75297c17867 |
|---|---|
| 23 * @author Artem Tikhomirov | 23 * @author Artem Tikhomirov |
| 24 * @author TMate Software Ltd. | 24 * @author TMate Software Ltd. |
| 25 */ | 25 */ |
| 26 public enum HgRepositoryFiles { | 26 public enum HgRepositoryFiles { |
| 27 | 27 |
| 28 HgIgnore(".hgignore"), HgTags(".hgtags"), HgEol(".hgeol"), | 28 HgIgnore(Home.Root, ".hgignore"), HgTags(Home.Root, ".hgtags"), HgEol(Home.Root, ".hgeol"), |
| 29 Dirstate(false, "dirstate"), HgLocalTags(false, "localtags"), | 29 Dirstate(Home.Repo, "dirstate"), HgLocalTags(Home.Repo, "localtags"), |
| 30 HgSub(".hgsub"), HgSubstate(".hgsubstate"), | 30 HgSub(Home.Root, ".hgsub"), HgSubstate(Home.Root, ".hgsubstate"), |
| 31 LastMessage(false, "last-message.txt"), | 31 LastMessage(Home.Repo, "last-message.txt"), |
| 32 Bookmarks(false, "bookmarks"), BookmarksCurrent(false, "bookmarks.current"), | 32 Bookmarks(Home.Repo, "bookmarks"), BookmarksCurrent(Home.Repo, "bookmarks.current"), |
| 33 Branch(false, "branch"), | 33 Branch(Home.Repo, "branch"), |
| 34 UndoBranch(false, "undo.branch"), UndoDirstate(false, "undo.dirstate"); | 34 UndoBranch(Home.Repo, "undo.branch"), UndoDirstate(Home.Repo, "undo.dirstate"), |
| 35 Phaseroots(Home.Store, "phaseroots"), FNCache(Home.Store, "fncache"), | |
| 36 WorkingCopyLock(Home.Repo, "wlock"), StoreLock(Home.Store, "lock"); | |
| 37 | |
| 38 /** | |
| 39 * Possible file locations | |
| 40 */ | |
| 41 public enum Home { | |
| 42 Root, Repo, Store | |
| 43 } | |
| 35 | 44 |
| 36 private final String fname; | 45 private final String fname; |
| 37 private final boolean livesInWC; | 46 private final Home residesIn; |
| 38 | 47 |
| 39 private HgRepositoryFiles(String filename) { | 48 private HgRepositoryFiles(Home home, String filename) { |
| 40 this(true, filename); | |
| 41 } | |
| 42 | |
| 43 private HgRepositoryFiles(boolean wcNotRepoRoot, String filename) { | |
| 44 fname = filename; | 49 fname = filename; |
| 45 livesInWC = wcNotRepoRoot; | 50 residesIn = home; |
| 46 } | 51 } |
| 47 | 52 |
| 48 /** | 53 /** |
| 49 * Path to the file, relative to the parent it lives in. | 54 * Path to the file, relative to the repository root. |
| 50 * | 55 * |
| 51 * For repository files that reside in working directory, return their location relative to the working dir. | 56 * For repository files that reside in working directory, return their location relative to the working dir. |
| 52 * For files that reside under repository root, path returned would include '.hg/' prefix. | 57 * For files that reside under repository root, path returned includes '.hg/' prefix. |
| 58 * For files from {@link Home#Store} storage area, path starts with '.hg/store/', although actual use of 'store' folder | |
| 59 * is controlled by repository requirements. Returned value shall be deemed as 'most likely' path in a general environment. | |
| 53 * @return file location, never <code>null</code> | 60 * @return file location, never <code>null</code> |
| 54 */ | 61 */ |
| 55 public String getPath() { | 62 public String getPath() { |
| 56 return livesInWC ? getName() : ".hg/" + getName(); | 63 switch (residesIn) { |
| 64 case Store : return ".hg/store/" + getName(); | |
| 65 case Repo : return ".hg/" + getName(); | |
| 66 default : return getName(); | |
| 67 } | |
| 57 } | 68 } |
| 58 | 69 |
| 59 /** | 70 /** |
| 60 * File name without any path information | 71 * File name without any path information |
| 61 * @return file name, never <code>null</code> | 72 * @return file name, never <code>null</code> |
| 71 * File f = new File(hgRepo.getWorkingDir(), HgRepositoryFiles.HgIgnore.getPath()) | 82 * File f = new File(hgRepo.getWorkingDir(), HgRepositoryFiles.HgIgnore.getPath()) |
| 72 * </pre> | 83 * </pre> |
| 73 * @return <code>true</code> if file lives in working tree | 84 * @return <code>true</code> if file lives in working tree |
| 74 */ | 85 */ |
| 75 public boolean residesUnderWorkingDir() { | 86 public boolean residesUnderWorkingDir() { |
| 76 return livesInWC; | 87 return residesIn == Home.Root; |
| 77 } | 88 } |
| 78 | 89 |
| 79 /** | 90 /** |
| 80 * @return <code>true</code> if file lives under '.hg/' | 91 * @return <code>true</code> if file lives under '.hg/' |
| 81 */ | 92 */ |
| 82 public boolean residesUnderRepositoryRoot() { | 93 public boolean residesUnderRepositoryRoot() { |
| 83 return !livesInWC; | 94 return residesIn == Home.Repo; |
| 95 } | |
| 96 | |
| 97 /** | |
| 98 * Identify a root the file lives under | |
| 99 */ | |
| 100 public Home getHome() { | |
| 101 return residesIn; | |
| 84 } | 102 } |
| 85 } | 103 } |
