Mercurial > jhg
annotate src/org/tmatesoft/hg/internal/EncodeDirPathHelper.java @ 680:58a6900f845d
Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Sun, 21 Jul 2013 17:15:34 +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 java.util.regex.Matcher; |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
20 import java.util.regex.Pattern; |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
21 |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
22 import org.tmatesoft.hg.util.PathRewrite; |
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 /** |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
25 * <blockquote cite="http://mercurial.selenic.com/wiki/FileFormats#data.2F">Directory names ending in .i or .d have .hg appended</blockquote> |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
26 * |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
27 * @see http://mercurial.selenic.com/wiki/FileFormats#data.2F |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
28 * @author Artem Tikhomirov |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
29 * @author TMate Software Ltd. |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
30 */ |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 final class EncodeDirPathHelper implements PathRewrite { |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 private final Pattern suffix2replace; |
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 public EncodeDirPathHelper() { |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 suffix2replace = Pattern.compile("\\.([id]|hg)/"); |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
36 } |
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 public CharSequence rewrite(CharSequence p) { |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
39 Matcher suffixMatcher = suffix2replace.matcher(p); |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
40 CharSequence path; |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 // Matcher.replaceAll, but without extra toString |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 boolean found = suffixMatcher.find(); |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 if (found) { |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 StringBuffer sb = new StringBuffer(p.length() + 20); |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
45 do { |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
46 suffixMatcher.appendReplacement(sb, ".$1.hg/"); |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
47 } while (found = suffixMatcher.find()); |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
48 suffixMatcher.appendTail(sb); |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
49 path = sb; |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
50 } else { |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
51 path = p; |
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 return path; |
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 |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
56 } |