annotate src/org/tmatesoft/hg/repo/HgRepositoryFiles.java @ 710:cf200271439a

KeywordFilter: 'IllegalStateException: need buffer of at least...' during status op for a small file
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 07 Oct 2013 01:56:05 +0200
parents 42b88709e41d
children a62079bc422b
rev   line source
373
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
626
5afc7eedb3dd @since, TODOs. Tests: add 1 sec to deal with fs timestamp granularity on linux
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 617
diff changeset
2 * Copyright (c) 2012-2013 TMate Software Ltd
373
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
647
c75297c17867 Location of repository files as enumeration, use file constants instead of plain names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
28 HgIgnore(Home.Root, ".hgignore"), HgTags(Home.Root, ".hgtags"), HgEol(Home.Root, ".hgeol"),
c75297c17867 Location of repository files as enumeration, use file constants instead of plain names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
29 Dirstate(Home.Repo, "dirstate"), HgLocalTags(Home.Repo, "localtags"),
c75297c17867 Location of repository files as enumeration, use file constants instead of plain names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
30 HgSub(Home.Root, ".hgsub"), HgSubstate(Home.Root, ".hgsubstate"),
c75297c17867 Location of repository files as enumeration, use file constants instead of plain names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
31 LastMessage(Home.Repo, "last-message.txt"),
c75297c17867 Location of repository files as enumeration, use file constants instead of plain names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
32 Bookmarks(Home.Repo, "bookmarks"), BookmarksCurrent(Home.Repo, "bookmarks.current"),
c75297c17867 Location of repository files as enumeration, use file constants instead of plain names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
33 Branch(Home.Repo, "branch"),
c75297c17867 Location of repository files as enumeration, use file constants instead of plain names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
34 UndoBranch(Home.Repo, "undo.branch"), UndoDirstate(Home.Repo, "undo.dirstate"),
c75297c17867 Location of repository files as enumeration, use file constants instead of plain names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
35 Phaseroots(Home.Store, "phaseroots"), FNCache(Home.Store, "fncache"),
707
42b88709e41d Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 647
diff changeset
36 WorkingCopyLock(Home.Repo, "wlock"), StoreLock(Home.Store, "lock"),
42b88709e41d Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 647
diff changeset
37 MergeState(Home.Repo, "merge/state");
647
c75297c17867 Location of repository files as enumeration, use file constants instead of plain names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
38
c75297c17867 Location of repository files as enumeration, use file constants instead of plain names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
39 /**
707
42b88709e41d Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 647
diff changeset
40 * Possible file locations
42b88709e41d Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 647
diff changeset
41 * <ul>
42b88709e41d Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 647
diff changeset
42 * <li>{@link #Root} lives in working copy
42b88709e41d Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 647
diff changeset
43 * <li>{@link #Repo} files under <samp>.hg/</samp>
42b88709e41d Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 647
diff changeset
44 * <li>#{@link #Store} files in storage area, either <samp>.hg/store/</samp> or <samp>.hg/</samp>
42b88709e41d Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 647
diff changeset
45 * </ul>
647
c75297c17867 Location of repository files as enumeration, use file constants instead of plain names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
46 */
c75297c17867 Location of repository files as enumeration, use file constants instead of plain names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
47 public enum Home {
c75297c17867 Location of repository files as enumeration, use file constants instead of plain names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
48 Root, Repo, Store
c75297c17867 Location of repository files as enumeration, use file constants instead of plain names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
49 }
373
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50
482
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
51 private final String fname;
647
c75297c17867 Location of repository files as enumeration, use file constants instead of plain names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
52 private final Home residesIn;
373
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53
647
c75297c17867 Location of repository files as enumeration, use file constants instead of plain names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
54 private HgRepositoryFiles(Home home, 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
55 fname = filename;
647
c75297c17867 Location of repository files as enumeration, use file constants instead of plain names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
56 residesIn = home;
482
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
57 }
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
58
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
59 /**
647
c75297c17867 Location of repository files as enumeration, use file constants instead of plain names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
60 * Path to the file, relative to the repository root.
482
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
61 *
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
62 * For repository files that reside in working directory, return their location relative to the working dir.
647
c75297c17867 Location of repository files as enumeration, use file constants instead of plain names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
63 * For files that reside under repository root, path returned includes '.hg/' prefix.
c75297c17867 Location of repository files as enumeration, use file constants instead of plain names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
64 * For files from {@link Home#Store} storage area, path starts with '.hg/store/', although actual use of 'store' folder
c75297c17867 Location of repository files as enumeration, use file constants instead of plain names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
65 * is controlled by repository requirements. Returned value shall be deemed as 'most likely' path in a general environment.
482
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
66 * @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
67 */
373
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
68 public String getPath() {
647
c75297c17867 Location of repository files as enumeration, use file constants instead of plain names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
69 switch (residesIn) {
c75297c17867 Location of repository files as enumeration, use file constants instead of plain names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
70 case Store : return ".hg/store/" + getName();
c75297c17867 Location of repository files as enumeration, use file constants instead of plain names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
71 case Repo : return ".hg/" + getName();
c75297c17867 Location of repository files as enumeration, use file constants instead of plain names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
72 default : return getName();
c75297c17867 Location of repository files as enumeration, use file constants instead of plain names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
73 }
482
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 * 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
78 * @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
79 */
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
80 public String getName() {
373
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
81 return fname;
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
82 }
482
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
83
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
84 /**
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
85 * 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
86 * <pre>
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
87 * 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
88 * 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
89 * </pre>
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
90 * @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
91 */
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
92 public boolean residesUnderWorkingDir() {
647
c75297c17867 Location of repository files as enumeration, use file constants instead of plain names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
93 return residesIn == Home.Root;
482
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
94 }
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
95
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
96 /**
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
97 * @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
98 */
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
99 public boolean residesUnderRepositoryRoot() {
647
c75297c17867 Location of repository files as enumeration, use file constants instead of plain names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
100 return residesIn == Home.Repo;
c75297c17867 Location of repository files as enumeration, use file constants instead of plain names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
101 }
c75297c17867 Location of repository files as enumeration, use file constants instead of plain names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
102
c75297c17867 Location of repository files as enumeration, use file constants instead of plain names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
103 /**
c75297c17867 Location of repository files as enumeration, use file constants instead of plain names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
104 * Identify a root the file lives under
c75297c17867 Location of repository files as enumeration, use file constants instead of plain names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
105 */
c75297c17867 Location of repository files as enumeration, use file constants instead of plain names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
106 public Home getHome() {
c75297c17867 Location of repository files as enumeration, use file constants instead of plain names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
107 return residesIn;
482
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
108 }
373
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
109 }