tikhomirov@373: /*
tikhomirov@373: * Copyright (c) 2012 TMate Software Ltd
tikhomirov@373: *
tikhomirov@373: * This program is free software; you can redistribute it and/or modify
tikhomirov@373: * it under the terms of the GNU General Public License as published by
tikhomirov@373: * the Free Software Foundation; version 2 of the License.
tikhomirov@373: *
tikhomirov@373: * This program is distributed in the hope that it will be useful,
tikhomirov@373: * but WITHOUT ANY WARRANTY; without even the implied warranty of
tikhomirov@373: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
tikhomirov@373: * GNU General Public License for more details.
tikhomirov@373: *
tikhomirov@373: * For information on how to redistribute this software under
tikhomirov@373: * the terms of a license other than GNU General Public License
tikhomirov@373: * contact TMate Software at support@hg4j.com
tikhomirov@373: */
tikhomirov@373: package org.tmatesoft.hg.repo;
tikhomirov@373:
tikhomirov@373:
tikhomirov@373: /**
tikhomirov@442: * Names of some Mercurial configuration/service files.
tikhomirov@442: *
tikhomirov@373: * @author Artem Tikhomirov
tikhomirov@373: * @author TMate Software Ltd.
tikhomirov@373: */
tikhomirov@373: public enum HgRepositoryFiles {
tikhomirov@373:
tikhomirov@373: HgIgnore(".hgignore"), HgTags(".hgtags"), HgEol(".hgeol"),
tikhomirov@482: Dirstate(false, "dirstate"), HgLocalTags(false, "localtags"),
tikhomirov@481: HgSub(".hgsub"), HgSubstate(".hgsubstate"),
tikhomirov@484: LastMessage(false, "last-message.txt"),
tikhomirov@484: Bookmarks(false, "bookmarks"), BookmarksCurrent(false, "bookmarks.current");
tikhomirov@373:
tikhomirov@482: private final String fname;
tikhomirov@482: private final boolean livesInWC;
tikhomirov@373:
tikhomirov@373: private HgRepositoryFiles(String filename) {
tikhomirov@482: this(true, filename);
tikhomirov@373: }
tikhomirov@373:
tikhomirov@482: private HgRepositoryFiles(boolean wcNotRepoRoot, String filename) {
tikhomirov@482: fname = filename;
tikhomirov@482: livesInWC = wcNotRepoRoot;
tikhomirov@482: }
tikhomirov@482:
tikhomirov@482: /**
tikhomirov@482: * Path to the file, relative to the parent it lives in.
tikhomirov@482: *
tikhomirov@482: * For repository files that reside in working directory, return their location relative to the working dir.
tikhomirov@482: * For files that reside under repository root, path returned would include '.hg/' prefix.
tikhomirov@482: * @return file location, never null
tikhomirov@482: */
tikhomirov@373: public String getPath() {
tikhomirov@482: return livesInWC ? getName() : ".hg/" + getName();
tikhomirov@482: }
tikhomirov@482:
tikhomirov@482: /**
tikhomirov@482: * File name without any path information
tikhomirov@482: * @return file name, never null
tikhomirov@482: */
tikhomirov@482: public String getName() {
tikhomirov@373: return fname;
tikhomirov@373: }
tikhomirov@482:
tikhomirov@482: /**
tikhomirov@482: * Files that reside under working directory may be accessed like:
tikhomirov@482: *
tikhomirov@482: * HgRepository hgRepo = ...; tikhomirov@482: * File f = new File(hgRepo.getWorkingDir(), HgRepositoryFiles.HgIgnore.getPath()) tikhomirov@482: *tikhomirov@482: * @return
true
if file lives in working tree
tikhomirov@482: */
tikhomirov@482: public boolean residesUnderWorkingDir() {
tikhomirov@482: return livesInWC;
tikhomirov@482: }
tikhomirov@482:
tikhomirov@482: /**
tikhomirov@482: * @return true
if file lives under '.hg/'
tikhomirov@482: */
tikhomirov@482: public boolean residesUnderRepositoryRoot() {
tikhomirov@482: return !livesInWC;
tikhomirov@482: }
tikhomirov@373: }