Mercurial > hg4j
comparison src/org/tmatesoft/hg/internal/FNCachePathHelper.java @ 616:5e0313485eef
encode directories as demanded by fncache format
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 14 May 2013 17:31:35 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
615:84104448a0bf | 616:5e0313485eef |
---|---|
1 /* | |
2 * Copyright (c) 2013 TMate Software Ltd | |
3 * | |
4 * This program is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; version 2 of the License. | |
7 * | |
8 * This program is distributed in the hope that it will be useful, | |
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 * GNU General Public License for more details. | |
12 * | |
13 * For information on how to redistribute this software under | |
14 * the terms of a license other than GNU General Public License | |
15 * contact TMate Software at support@hg4j.com | |
16 */ | |
17 package org.tmatesoft.hg.internal; | |
18 | |
19 import static org.tmatesoft.hg.internal.StoragePathHelper.STR_DATA; | |
20 | |
21 import org.tmatesoft.hg.util.PathRewrite; | |
22 | |
23 /** | |
24 * Prepare filelog names to be written into fncache. | |
25 * | |
26 * @see http://mercurial.selenic.com/wiki/fncacheRepoFormat#The_fncache_file | |
27 * @author Artem Tikhomirov | |
28 * @author TMate Software Ltd. | |
29 */ | |
30 final class FNCachePathHelper implements PathRewrite { | |
31 | |
32 private final EncodeDirPathHelper dirPathRewrite; | |
33 | |
34 | |
35 public FNCachePathHelper() { | |
36 dirPathRewrite = new EncodeDirPathHelper(); | |
37 } | |
38 | |
39 /** | |
40 * Input: repository-relative path of a filelog, i.e. without 'data/' or 'dh/' prefix, and/or '.i'/'.d' suffix. | |
41 * Output: path ready to be written into fncache file, alaways with '.i' suffix (caller is free to alter the suffix to '.d' as appropriate | |
42 */ | |
43 public CharSequence rewrite(CharSequence path) { | |
44 CharSequence p = dirPathRewrite.rewrite(path); | |
45 StringBuilder result = new StringBuilder(p.length() + STR_DATA.length() + ".i".length()); | |
46 result.append(STR_DATA); | |
47 result.append(p); | |
48 result.append(".i"); | |
49 return result; | |
50 } | |
51 | |
52 /* | |
53 * There's always 'data/' prefix, even if actual file resides under 'dh/': | |
54 * | |
55 * $ cat .hg/store/fncache | |
56 * 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 | |
57 * $ ls .hg/store/dh/very-lon/very-lon/very-lon/ | |
58 * file-with-longest-name-i-am-not-lazy-to-type.txtbbd4d3327f6364027211b0cd8ca499d3d6308849.i | |
59 */ | |
60 } |