Mercurial > jhg
comparison src/org/tmatesoft/hg/internal/RequiresFile.java @ 493:ba36f66c32b4
Refactor to keep knowledge about repository control files and their location in respect to .hg/ in a single place (facilitate future adoption of shared repositories)
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 18 Oct 2012 18:36:13 +0200 |
parents | 981f9f50bb6c |
children |
comparison
equal
deleted
inserted
replaced
492:e4eaa23e3442 | 493:ba36f66c32b4 |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2011 TMate Software Ltd | 2 * Copyright (c) 2011-2012 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 * |
26 * | 26 * |
27 * @author Artem Tikhomirov | 27 * @author Artem Tikhomirov |
28 * @author TMate Software Ltd. | 28 * @author TMate Software Ltd. |
29 */ | 29 */ |
30 public class RequiresFile { | 30 public class RequiresFile { |
31 public static final int STORE = 1; | 31 public static final int STORE = 1 << 0; |
32 public static final int FNCACHE = 2; | 32 public static final int FNCACHE = 1 << 1; |
33 public static final int DOTENCODE = 4; | 33 public static final int DOTENCODE = 1 << 2; |
34 public static final int REVLOGV0 = 1 << 31; | |
35 public static final int REVLOGV1 = 1 << 30; | |
34 | 36 |
35 public RequiresFile() { | 37 public RequiresFile() { |
36 } | 38 } |
37 | 39 |
38 public void parse(Internals repoImpl, File requiresFile) throws IOException { | 40 /** |
41 * Settings from requires file as bits | |
42 */ | |
43 public int parse(File requiresFile) throws IOException { | |
39 if (!requiresFile.exists()) { | 44 if (!requiresFile.exists()) { |
40 return; | 45 // TODO check what's going on in Mercurial if no requires exist |
46 return 0; | |
41 } | 47 } |
42 BufferedReader br = null; | 48 BufferedReader br = null; |
43 try { | 49 try { |
44 boolean revlogv1 = false; | |
45 boolean store = false; | |
46 boolean fncache = false; | |
47 boolean dotencode = false; | |
48 br = new BufferedReader(new InputStreamReader(new FileInputStream(requiresFile))); | 50 br = new BufferedReader(new InputStreamReader(new FileInputStream(requiresFile))); |
49 String line; | 51 String line; |
52 int flags = 0; | |
50 while ((line = br.readLine()) != null) { | 53 while ((line = br.readLine()) != null) { |
51 revlogv1 |= "revlogv1".equals(line); | 54 if ("revlogv1".equals(line)) { |
52 store |= "store".equals(line); | 55 flags |= REVLOGV1; |
53 fncache |= "fncache".equals(line); | 56 } else if ("store".equals(line)) { |
54 dotencode |= "dotencode".equals(line); | 57 flags |= STORE; |
58 } else if ("fncache".equals(line)) { | |
59 flags |= FNCACHE; | |
60 } else if ("dotencode".equals(line)) { | |
61 flags |= DOTENCODE; | |
62 } | |
55 } | 63 } |
56 int flags = 0; | 64 if ((flags & REVLOGV1) == 0) { |
57 flags += store ? STORE : 0; | 65 flags |= REVLOGV0; // TODO check if there's no special flag for V0 indeed |
58 flags += fncache ? FNCACHE : 0; | 66 } |
59 flags += dotencode ? DOTENCODE : 0; | 67 return flags; |
60 repoImpl.setStorageConfig(revlogv1 ? 1 : 0, flags); | |
61 } finally { | 68 } finally { |
62 if (br != null) { | 69 if (br != null) { |
63 br.close(); | 70 br.close(); |
64 } | 71 } |
65 } | 72 } |