tikhomirov@74: /*
tikhomirov@74:  * Copyright (c) 2011 TMate Software Ltd
tikhomirov@74:  *  
tikhomirov@74:  * This program is free software; you can redistribute it and/or modify
tikhomirov@74:  * it under the terms of the GNU General Public License as published by
tikhomirov@74:  * the Free Software Foundation; version 2 of the License.
tikhomirov@74:  *
tikhomirov@74:  * This program is distributed in the hope that it will be useful,
tikhomirov@74:  * but WITHOUT ANY WARRANTY; without even the implied warranty of
tikhomirov@74:  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
tikhomirov@74:  * GNU General Public License for more details.
tikhomirov@74:  *
tikhomirov@74:  * For information on how to redistribute this software under
tikhomirov@74:  * the terms of a license other than GNU General Public License
tikhomirov@102:  * contact TMate Software at support@hg4j.com
tikhomirov@74:  */
tikhomirov@74: package org.tmatesoft.hg.internal;
tikhomirov@74: 
tikhomirov@74: import java.io.BufferedReader;
tikhomirov@74: import java.io.File;
tikhomirov@74: import java.io.FileInputStream;
tikhomirov@74: import java.io.IOException;
tikhomirov@74: import java.io.InputStreamReader;
tikhomirov@74: 
tikhomirov@74: /**
tikhomirov@74:  *
tikhomirov@74:  * @author Artem Tikhomirov
tikhomirov@74:  * @author TMate Software Ltd.
tikhomirov@74:  */
tikhomirov@74: public class RequiresFile {
tikhomirov@74: 	public static final int STORE = 1;
tikhomirov@74: 	public static final int FNCACHE = 2;
tikhomirov@74: 	public static final int DOTENCODE = 4;
tikhomirov@74: 	
tikhomirov@74: 	public RequiresFile() {
tikhomirov@74: 	}
tikhomirov@74: 
tikhomirov@295: 	public void parse(Internals repoImpl, File requiresFile) throws IOException {
tikhomirov@74: 		if (!requiresFile.exists()) {
tikhomirov@74: 			return;
tikhomirov@74: 		}
tikhomirov@295: 		BufferedReader br = null;
tikhomirov@74: 		try {
tikhomirov@74: 			boolean revlogv1 = false;
tikhomirov@74: 			boolean store = false;
tikhomirov@74: 			boolean fncache = false;
tikhomirov@74: 			boolean dotencode = false;
tikhomirov@295: 			br = new BufferedReader(new InputStreamReader(new FileInputStream(requiresFile)));
tikhomirov@74: 			String line;
tikhomirov@74: 			while ((line = br.readLine()) != null) {
tikhomirov@74: 				revlogv1 |= "revlogv1".equals(line);
tikhomirov@74: 				store |= "store".equals(line);
tikhomirov@74: 				fncache |= "fncache".equals(line);
tikhomirov@74: 				dotencode |= "dotencode".equals(line);
tikhomirov@74: 			}
tikhomirov@74: 			int flags = 0;
tikhomirov@170: 			flags += store ? STORE : 0;
tikhomirov@170: 			flags += fncache ? FNCACHE : 0;
tikhomirov@170: 			flags += dotencode ? DOTENCODE : 0;
tikhomirov@74: 			repoImpl.setStorageConfig(revlogv1 ? 1 : 0, flags);
tikhomirov@295: 		} finally {
tikhomirov@295: 			if (br != null) {
tikhomirov@295: 				br.close();
tikhomirov@295: 			}
tikhomirov@74: 		}
tikhomirov@74: 	}
tikhomirov@74: }