comparison src/com/tmate/hgkit/ll/HgDirstate.java @ 59:b771e94a4f7c

Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 18 Jan 2011 00:08:15 +0100
parents 02ee376bee79
children
comparison
equal deleted inserted replaced
58:4cfc47bc14cc 59:b771e94a4f7c
1 /* 1 /*
2 * Copyright (c) 2010 Artem Tikhomirov 2 * Copyright (c) 2010, 2011 Artem Tikhomirov
3 */ 3 */
4 package com.tmate.hgkit.ll; 4 package com.tmate.hgkit.ll;
5 5
6 import java.io.File; 6 import java.io.File;
7 import java.io.IOException; 7 import java.io.IOException;
18 * @see http://mercurial.selenic.com/wiki/FileFormats#dirstate 18 * @see http://mercurial.selenic.com/wiki/FileFormats#dirstate
19 * @author artem 19 * @author artem
20 */ 20 */
21 public class HgDirstate { 21 public class HgDirstate {
22 22
23 private final LocalHgRepo repo; 23 private final DataAccessProvider accessProvider;
24 private final File dirstateFile; 24 private final File dirstateFile;
25 private Map<String, Record> normal; 25 private Map<String, Record> normal;
26 private Map<String, Record> added; 26 private Map<String, Record> added;
27 private Map<String, Record> removed; 27 private Map<String, Record> removed;
28 private Map<String, Record> merged; 28 private Map<String, Record> merged;
29 29
30 public HgDirstate(LocalHgRepo hgRepo, File dirstate) { 30 /*package-local*/ HgDirstate() {
31 this.repo = hgRepo; 31 // empty instance
32 this.dirstateFile = dirstate; 32 accessProvider = null;
33 dirstateFile = null;
34 }
35
36 public HgDirstate(DataAccessProvider dap, File dirstate) {
37 accessProvider = dap;
38 dirstateFile = dirstate;
33 } 39 }
34 40
35 private void read() { 41 private void read() {
36 normal = added = removed = merged = Collections.<String, Record>emptyMap(); 42 normal = added = removed = merged = Collections.<String, Record>emptyMap();
37 if (!dirstateFile.exists()) { 43 if (dirstateFile == null || !dirstateFile.exists()) {
38 return; 44 return;
39 } 45 }
40 DataAccessProvider dap = repo.getDataAccess(); 46 DataAccess da = accessProvider.create(dirstateFile);
41 DataAccess da = dap.create(dirstateFile);
42 if (da.isEmpty()) { 47 if (da.isEmpty()) {
43 return; 48 return;
44 } 49 }
45 // not sure linked is really needed here, just for ease of debug 50 // not sure linked is really needed here, just for ease of debug
46 normal = new LinkedHashMap<String, Record>(); 51 normal = new LinkedHashMap<String, Record>();