diff 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
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/RequiresFile.java	Thu Oct 18 16:27:32 2012 +0200
+++ b/src/org/tmatesoft/hg/internal/RequiresFile.java	Thu Oct 18 18:36:13 2012 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011 TMate Software Ltd
+ * Copyright (c) 2011-2012 TMate Software Ltd
  *  
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -28,36 +28,43 @@
  * @author TMate Software Ltd.
  */
 public class RequiresFile {
-	public static final int STORE = 1;
-	public static final int FNCACHE = 2;
-	public static final int DOTENCODE = 4;
+	public static final int STORE 		= 1 << 0;
+	public static final int FNCACHE		= 1 << 1;
+	public static final int DOTENCODE	= 1 << 2;
+	public static final int REVLOGV0	= 1 << 31;
+	public static final int REVLOGV1	= 1 << 30;
 	
 	public RequiresFile() {
 	}
 
-	public void parse(Internals repoImpl, File requiresFile) throws IOException {
+	/**
+	 * Settings from requires file as bits
+	 */
+	public int parse(File requiresFile) throws IOException {
 		if (!requiresFile.exists()) {
-			return;
+			// TODO check what's going on in Mercurial if no requires exist
+			return 0;
 		}
 		BufferedReader br = null;
 		try {
-			boolean revlogv1 = false;
-			boolean store = false;
-			boolean fncache = false;
-			boolean dotencode = false;
 			br = new BufferedReader(new InputStreamReader(new FileInputStream(requiresFile)));
 			String line;
+			int flags = 0;
 			while ((line = br.readLine()) != null) {
-				revlogv1 |= "revlogv1".equals(line);
-				store |= "store".equals(line);
-				fncache |= "fncache".equals(line);
-				dotencode |= "dotencode".equals(line);
+				if ("revlogv1".equals(line)) {
+					flags |= REVLOGV1;
+				} else if ("store".equals(line)) {
+					flags |= STORE;
+				} else if ("fncache".equals(line)) {
+					flags |= FNCACHE;
+				} else if ("dotencode".equals(line)) {
+					flags |= DOTENCODE;
+				}
 			}
-			int flags = 0;
-			flags += store ? STORE : 0;
-			flags += fncache ? FNCACHE : 0;
-			flags += dotencode ? DOTENCODE : 0;
-			repoImpl.setStorageConfig(revlogv1 ? 1 : 0, flags);
+			if ((flags & REVLOGV1) == 0) {
+				flags |= REVLOGV0; // TODO check if there's no special flag for V0 indeed
+			}
+			return flags;
 		} finally {
 			if (br != null) {
 				br.close();