Mercurial > jhg
annotate 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 | 
| rev | line source | 
|---|---|
| 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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 1 /* | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 2 * Copyright (c) 2012 TMate Software Ltd | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 3 * | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 4 * This program is free software; you can redistribute it and/or modify | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 5 * it under the terms of the GNU General Public License as published by | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 6 * the Free Software Foundation; version 2 of the License. | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 7 * | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 8 * This program is distributed in the hope that it will be useful, | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 11 * GNU General Public License for more details. | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 12 * | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 13 * For information on how to redistribute this software under | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 14 * the terms of a license other than GNU General Public License | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 15 * contact TMate Software at support@hg4j.com | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 16 */ | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 17 package org.tmatesoft.hg.internal; | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 18 | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 19 import static org.tmatesoft.hg.internal.RequiresFile.*; | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 20 | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 21 import java.io.File; | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 22 import java.io.FileOutputStream; | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 23 import java.io.IOException; | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 24 import java.nio.charset.Charset; | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 25 | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 26 import org.tmatesoft.hg.core.SessionContext; | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 27 import org.tmatesoft.hg.util.PathRewrite; | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 28 | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 29 /** | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 30 * Responsible of `requires` processing both on repo read and repo write | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 31 * XXX needs better name, perhaps | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 32 * | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 33 * @author Artem Tikhomirov | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 34 * @author TMate Software Ltd. | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 35 */ | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 36 public class RepoInitializer { | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 37 private int requiresFlags; | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 38 | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 39 public RepoInitializer() { | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 40 } | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 41 | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 42 public RepoInitializer setRequires(int flags) { | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 43 requiresFlags = flags; | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 44 return this; | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 45 } | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 46 | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 47 public int getRequires() { | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 48 return requiresFlags; | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 49 } | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 50 | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 51 public void initEmptyRepository(File hgDir) throws IOException { | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 52 hgDir.mkdir(); | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 53 FileOutputStream requiresFile = new FileOutputStream(new File(hgDir, "requires")); | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 54 StringBuilder sb = new StringBuilder(40); | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 55 sb.append("revlogv1\n"); | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 56 if ((requiresFlags & STORE) != 0) { | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 57 sb.append("store\n"); | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 58 } | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 59 if ((requiresFlags & FNCACHE) != 0) { | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 60 sb.append("fncache\n"); | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 61 } | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 62 if ((requiresFlags & DOTENCODE) != 0) { | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 63 sb.append("dotencode\n"); | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 64 } | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 65 requiresFile.write(sb.toString().getBytes()); | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 66 requiresFile.close(); | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 67 new File(hgDir, "store").mkdir(); // with that, hg verify says ok. | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 68 } | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 69 | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 70 public PathRewrite buildDataFilesHelper(SessionContext ctx) { | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 71 Charset cs = Internals.getFileEncoding(ctx); | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 72 // StoragePathHelper needs fine-grained control over char encoding, hence doesn't use EncodingHelper | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 73 return new StoragePathHelper((requiresFlags & STORE) != 0, (requiresFlags & FNCACHE) != 0, (requiresFlags & DOTENCODE) != 0, cs); | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 74 } | 
| 
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)
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 75 } | 
