annotate src/org/tmatesoft/hg/repo/HgRepositoryFiles.java @ 533:e6f72c9829a6

Generate patches using diff algorithm
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 30 Jan 2013 15:48:36 +0100
parents 47b7bedf0569
children 65c01508f002
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"),
484
ae4d6604debd Bookmarks support added
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 482
diff changeset
31 LastMessage(false, "last-message.txt"),
527
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 484
diff changeset
32 Bookmarks(false, "bookmarks"), BookmarksCurrent(false, "bookmarks.current"),
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 484
diff changeset
33 Branch(false, "branch");
373
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34
482
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
35 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
36 private final boolean livesInWC;
373
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
37
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 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
39 this(true, filename);
373
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40 }
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41
482
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
42 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
43 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
44 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
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
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 * 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
49 *
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
50 * 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
51 * 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
52 * @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
53 */
373
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54 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
55 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
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
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 * 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
60 * @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
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 public String getName() {
373
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
63 return fname;
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 }
482
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
65
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
66 /**
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
67 * 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
68 * <pre>
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
69 * 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
70 * 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
71 * </pre>
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
72 * @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
73 */
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
74 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
75 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
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
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 * @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
80 */
6c67debed07e Distinguish files in wc from files under repo root, use these constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 481
diff changeset
81 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
82 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
83 }
373
dd492acd2431 Constants for well-known repository file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
84 }