comparison src/org/tmatesoft/hg/repo/HgRepositoryFiles.java @ 482:6c67debed07e

Distinguish files in wc from files under repo root, use these constants
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 07 Aug 2012 14:27:13 +0200
parents a458f9fb00ce
children ae4d6604debd
comparison
equal deleted inserted replaced
481:a458f9fb00ce 482:6c67debed07e
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(".hgignore"), HgTags(".hgtags"), HgEol(".hgeol"),
29 Dirstate(".hg/dirstate"), HgLocalTags(".hg/localtags"), 29 Dirstate(false, "dirstate"), HgLocalTags(false, "localtags"),
30 HgSub(".hgsub"), HgSubstate(".hgsubstate"), 30 HgSub(".hgsub"), HgSubstate(".hgsubstate"),
31 LastMessage("last-message.txt"); 31 LastMessage(false, "last-message.txt");
32 32
33 private String fname; 33 private final String fname;
34 private final boolean livesInWC;
34 35
35 private HgRepositoryFiles(String filename) { 36 private HgRepositoryFiles(String filename) {
36 fname = filename; 37 this(true, filename);
37 } 38 }
38 39
40 private HgRepositoryFiles(boolean wcNotRepoRoot, String filename) {
41 fname = filename;
42 livesInWC = wcNotRepoRoot;
43 }
44
45 /**
46 * Path to the file, relative to the parent it lives in.
47 *
48 * For repository files that reside in working directory, return their location relative to the working dir.
49 * For files that reside under repository root, path returned would include '.hg/' prefix.
50 * @return file location, never <code>null</code>
51 */
39 public String getPath() { 52 public String getPath() {
53 return livesInWC ? getName() : ".hg/" + getName();
54 }
55
56 /**
57 * File name without any path information
58 * @return file name, never <code>null</code>
59 */
60 public String getName() {
40 return fname; 61 return fname;
41 } 62 }
63
64 /**
65 * Files that reside under working directory may be accessed like:
66 * <pre>
67 * HgRepository hgRepo = ...;
68 * File f = new File(hgRepo.getWorkingDir(), HgRepositoryFiles.HgIgnore.getPath())
69 * </pre>
70 * @return <code>true</code> if file lives in working tree
71 */
72 public boolean residesUnderWorkingDir() {
73 return livesInWC;
74 }
75
76 /**
77 * @return <code>true</code> if file lives under '.hg/'
78 */
79 public boolean residesUnderRepositoryRoot() {
80 return !livesInWC;
81 }
42 } 82 }