comparison src/org/tmatesoft/hg/internal/RepoInitializer.java @ 637:4a0bab2c6da1

HgInitCommand: expose repo init functionality
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 07 Jun 2013 12:32:15 +0200
parents 4e6179bde4fc
children
comparison
equal deleted inserted replaced
636:ffce73efa2c2 637:4a0bab2c6da1
1 /* 1 /*
2 * Copyright (c) 2012 TMate Software Ltd 2 * Copyright (c) 2012-2013 TMate Software Ltd
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify 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 5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License. 6 * the Free Software Foundation; version 2 of the License.
7 * 7 *
30 30
31 /** 31 /**
32 * Responsible of `requires` processing both on repo read and repo write 32 * Responsible of `requires` processing both on repo read and repo write
33 * XXX needs better name, perhaps 33 * XXX needs better name, perhaps
34 * 34 *
35 * @see http://mercurial.selenic.com/wiki/RequiresFile
35 * @author Artem Tikhomirov 36 * @author Artem Tikhomirov
36 * @author TMate Software Ltd. 37 * @author TMate Software Ltd.
37 */ 38 */
38 public class RepoInitializer { 39 public class RepoInitializer {
39 private int requiresFlags; 40 private int requiresFlags;
64 repoDir.mkdirs(); 65 repoDir.mkdirs();
65 final File requiresFile = new File(repoDir, "requires"); 66 final File requiresFile = new File(repoDir, "requires");
66 try { 67 try {
67 FileOutputStream requiresStream = new FileOutputStream(requiresFile); 68 FileOutputStream requiresStream = new FileOutputStream(requiresFile);
68 StringBuilder sb = new StringBuilder(40); 69 StringBuilder sb = new StringBuilder(40);
69 sb.append("revlogv1\n"); 70 if ((requiresFlags & REVLOGV1) != 0) {
71 sb.append("revlogv1\n");
72 }
70 if ((requiresFlags & STORE) != 0) { 73 if ((requiresFlags & STORE) != 0) {
71 sb.append("store\n"); 74 sb.append("store\n");
72 } 75 }
73 if ((requiresFlags & FNCACHE) != 0) { 76 if ((requiresFlags & FNCACHE) != 0) {
74 sb.append("fncache\n"); 77 sb.append("fncache\n");
79 requiresStream.write(sb.toString().getBytes()); 82 requiresStream.write(sb.toString().getBytes());
80 requiresStream.close(); 83 requiresStream.close();
81 } catch (IOException ex) { 84 } catch (IOException ex) {
82 throw new HgIOException("Failed to initialize empty repo", ex, requiresFile); 85 throw new HgIOException("Failed to initialize empty repo", ex, requiresFile);
83 } 86 }
84 new File(repoDir, "store").mkdir(); // with that, hg verify says ok. 87 if ((requiresFlags & STORE) != 0) {
88 new File(repoDir, "store").mkdir(); // with that, hg verify says ok.
89 }
85 } 90 }
86 91
87 public PathRewrite buildDataFilesHelper(SessionContext ctx) { 92 public PathRewrite buildDataFilesHelper(SessionContext ctx) {
88 Charset cs = Internals.getFileEncoding(ctx); 93 Charset cs = Internals.getFileEncoding(ctx);
89 // StoragePathHelper needs fine-grained control over char encoding, hence doesn't use EncodingHelper 94 // StoragePathHelper needs fine-grained control over char encoding, hence doesn't use EncodingHelper