Mercurial > hg4j
comparison src/org/tmatesoft/hg/internal/RepoInitializer.java @ 490:b3c16d1aede0
Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 16 Aug 2012 17:08:34 +0200 |
parents | |
children | ba36f66c32b4 |
comparison
equal
deleted
inserted
replaced
489:9c0138cda59a | 490:b3c16d1aede0 |
---|---|
1 /* | |
2 * Copyright (c) 2012 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.RequiresFile.*; | |
20 | |
21 import java.io.File; | |
22 import java.io.FileOutputStream; | |
23 import java.io.IOException; | |
24 import java.nio.charset.Charset; | |
25 | |
26 import org.tmatesoft.hg.core.SessionContext; | |
27 import org.tmatesoft.hg.util.PathRewrite; | |
28 | |
29 /** | |
30 * Responsible of `requires` processing both on repo read and repo write | |
31 * XXX needs better name, perhaps | |
32 * | |
33 * @author Artem Tikhomirov | |
34 * @author TMate Software Ltd. | |
35 */ | |
36 public class RepoInitializer { | |
37 private int requiresFlags; | |
38 | |
39 public RepoInitializer() { | |
40 } | |
41 | |
42 public RepoInitializer setRequires(int flags) { | |
43 requiresFlags = flags; | |
44 return this; | |
45 } | |
46 | |
47 public int getRequires() { | |
48 return requiresFlags; | |
49 } | |
50 | |
51 public void initEmptyRepository(File hgDir) throws IOException { | |
52 hgDir.mkdir(); | |
53 FileOutputStream requiresFile = new FileOutputStream(new File(hgDir, "requires")); | |
54 StringBuilder sb = new StringBuilder(40); | |
55 sb.append("revlogv1\n"); | |
56 if ((requiresFlags & STORE) != 0) { | |
57 sb.append("store\n"); | |
58 } | |
59 if ((requiresFlags & FNCACHE) != 0) { | |
60 sb.append("fncache\n"); | |
61 } | |
62 if ((requiresFlags & DOTENCODE) != 0) { | |
63 sb.append("dotencode\n"); | |
64 } | |
65 requiresFile.write(sb.toString().getBytes()); | |
66 requiresFile.close(); | |
67 new File(hgDir, "store").mkdir(); // with that, hg verify says ok. | |
68 } | |
69 | |
70 public PathRewrite buildDataFilesHelper(SessionContext ctx) { | |
71 Charset cs = Internals.getFileEncoding(ctx); | |
72 // StoragePathHelper needs fine-grained control over char encoding, hence doesn't use EncodingHelper | |
73 return new StoragePathHelper((requiresFlags & STORE) != 0, (requiresFlags & FNCACHE) != 0, (requiresFlags & DOTENCODE) != 0, cs); | |
74 } | |
75 } |