annotate 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
rev   line source
373
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2012 TMate Software Ltd
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 *
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 *
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 *
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 * For information on how to redistribute this software under
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14 * the terms of a license other than GNU General Public License
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
15 * contact TMate Software at support@hg4j.com
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 package org.tmatesoft.hg.repo;
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
19
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20 /**
442
6865eb742883 Tests for subrepo API, refactor status tests for reuse, better subrepos API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 373
diff changeset
21 * Names of some Mercurial configuration/service files.
6865eb742883 Tests for subrepo API, refactor status tests for reuse, better subrepos API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 373
diff changeset
22 *
373
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23 * @author Artem Tikhomirov
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24 * @author TMate Software Ltd.
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 */
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26 public enum HgRepositoryFiles {
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28 HgIgnore(".hgignore"), HgTags(".hgtags"), HgEol(".hgeol"),
482
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
29 Dirstate(false, "dirstate"), HgLocalTags(false, "localtags"),
481
a458f9fb00ce Access to user-supplied message of last commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 456
diff changeset
30 HgSub(".hgsub"), HgSubstate(".hgsubstate"),
482
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
31 LastMessage(false, "last-message.txt");
373
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32
482
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
33 private final String fname;
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
34 private final boolean livesInWC;
373
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36 private HgRepositoryFiles(String filename) {
482
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
37 this(true, filename);
373
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 }
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39
482
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
40 private HgRepositoryFiles(boolean wcNotRepoRoot, String filename) {
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
41 fname = filename;
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
42 livesInWC = wcNotRepoRoot;
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
43 }
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
44
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
45 /**
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
46 * Path to the file, relative to the parent it lives in.
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
47 *
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
48 * For repository files that reside in working directory, return their location relative to the working dir.
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
49 * For files that reside under repository root, path returned would include '.hg/' prefix.
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
50 * @return file location, never <code>null</code>
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
51 */
373
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52 public String getPath() {
482
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
53 return livesInWC ? getName() : ".hg/" + getName();
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
54 }
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
55
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
56 /**
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
57 * File name without any path information
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
58 * @return file name, never <code>null</code>
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
59 */
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
60 public String getName() {
373
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61 return fname;
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
62 }
482
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
63
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
64 /**
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
65 * Files that reside under working directory may be accessed like:
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
66 * <pre>
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
67 * HgRepository hgRepo = ...;
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
68 * File f = new File(hgRepo.getWorkingDir(), HgRepositoryFiles.HgIgnore.getPath())
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
69 * </pre>
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
70 * @return <code>true</code> if file lives in working tree
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
71 */
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
72 public boolean residesUnderWorkingDir() {
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
73 return livesInWC;
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
74 }
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
75
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
76 /**
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
77 * @return <code>true</code> if file lives under '.hg/'
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
78 */
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
79 public boolean residesUnderRepositoryRoot() {
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
80 return !livesInWC;
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
81 }
373
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
82 }