tikhomirov@616: /* tikhomirov@616: * Copyright (c) 2013 TMate Software Ltd tikhomirov@616: * tikhomirov@616: * This program is free software; you can redistribute it and/or modify tikhomirov@616: * it under the terms of the GNU General Public License as published by tikhomirov@616: * the Free Software Foundation; version 2 of the License. tikhomirov@616: * tikhomirov@616: * This program is distributed in the hope that it will be useful, tikhomirov@616: * but WITHOUT ANY WARRANTY; without even the implied warranty of tikhomirov@616: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the tikhomirov@616: * GNU General Public License for more details. tikhomirov@616: * tikhomirov@616: * For information on how to redistribute this software under tikhomirov@616: * the terms of a license other than GNU General Public License tikhomirov@616: * contact TMate Software at support@hg4j.com tikhomirov@616: */ tikhomirov@616: package org.tmatesoft.hg.internal; tikhomirov@616: tikhomirov@616: import static org.tmatesoft.hg.internal.StoragePathHelper.STR_DATA; tikhomirov@616: tikhomirov@616: import org.tmatesoft.hg.util.PathRewrite; tikhomirov@616: tikhomirov@616: /** tikhomirov@616: * Prepare filelog names to be written into fncache. tikhomirov@616: * tikhomirov@616: * @see http://mercurial.selenic.com/wiki/fncacheRepoFormat#The_fncache_file tikhomirov@616: * @author Artem Tikhomirov tikhomirov@616: * @author TMate Software Ltd. tikhomirov@616: */ tikhomirov@616: final class FNCachePathHelper implements PathRewrite { tikhomirov@616: tikhomirov@616: private final EncodeDirPathHelper dirPathRewrite; tikhomirov@616: tikhomirov@616: tikhomirov@616: public FNCachePathHelper() { tikhomirov@616: dirPathRewrite = new EncodeDirPathHelper(); tikhomirov@616: } tikhomirov@616: tikhomirov@616: /** tikhomirov@616: * Input: repository-relative path of a filelog, i.e. without 'data/' or 'dh/' prefix, and/or '.i'/'.d' suffix. tikhomirov@616: * Output: path ready to be written into fncache file, alaways with '.i' suffix (caller is free to alter the suffix to '.d' as appropriate tikhomirov@616: */ tikhomirov@616: public CharSequence rewrite(CharSequence path) { tikhomirov@616: CharSequence p = dirPathRewrite.rewrite(path); tikhomirov@616: StringBuilder result = new StringBuilder(p.length() + STR_DATA.length() + ".i".length()); tikhomirov@616: result.append(STR_DATA); tikhomirov@616: result.append(p); tikhomirov@616: result.append(".i"); tikhomirov@616: return result; tikhomirov@616: } tikhomirov@616: tikhomirov@616: /* tikhomirov@616: * There's always 'data/' prefix, even if actual file resides under 'dh/': tikhomirov@616: * tikhomirov@616: * $ cat .hg/store/fncache tikhomirov@616: * data/very-long-directory-name-level-1/very-long-directory-name-level-2/very-long-directory-name-level-3/file-with-longest-name-i-am-not-lazy-to-type.txt.i tikhomirov@616: * $ ls .hg/store/dh/very-lon/very-lon/very-lon/ tikhomirov@616: * file-with-longest-name-i-am-not-lazy-to-type.txtbbd4d3327f6364027211b0cd8ca499d3d6308849.i tikhomirov@616: */ tikhomirov@616: }