annotate src/org/tmatesoft/hg/internal/FNCachePathHelper.java @ 686:f1f095e42555

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