comparison src/org/tmatesoft/hg/repo/HgDirstate.java @ 231:1792b37650f2

Introduced access to conflict resolution information (merge state)
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 01 Jun 2011 05:44:25 +0200
parents 0fd10e5016dd
children a6d19adc2636
comparison
equal deleted inserted replaced
230:0dd9da7489dc 231:1792b37650f2
21 import java.util.Collections; 21 import java.util.Collections;
22 import java.util.LinkedHashMap; 22 import java.util.LinkedHashMap;
23 import java.util.Map; 23 import java.util.Map;
24 import java.util.TreeSet; 24 import java.util.TreeSet;
25 25
26 import org.tmatesoft.hg.core.HgBadStateException;
27 import org.tmatesoft.hg.core.Nodeid;
26 import org.tmatesoft.hg.internal.DataAccess; 28 import org.tmatesoft.hg.internal.DataAccess;
27 import org.tmatesoft.hg.internal.DataAccessProvider; 29 import org.tmatesoft.hg.internal.DataAccessProvider;
28 import org.tmatesoft.hg.util.Path; 30 import org.tmatesoft.hg.util.Path;
29 31
30 32
42 // deliberate String, not Path as it seems useless to keep Path here 44 // deliberate String, not Path as it seems useless to keep Path here
43 private Map<String, Record> normal; 45 private Map<String, Record> normal;
44 private Map<String, Record> added; 46 private Map<String, Record> added;
45 private Map<String, Record> removed; 47 private Map<String, Record> removed;
46 private Map<String, Record> merged; 48 private Map<String, Record> merged;
49 private Nodeid p1, p2;
47 50
48 /*package-local*/ HgDirstate() { 51 /*package-local*/ HgDirstate() {
49 // empty instance 52 // empty instance
50 accessProvider = null; 53 accessProvider = null;
51 dirstateFile = null; 54 dirstateFile = null;
69 normal = new LinkedHashMap<String, Record>(); 72 normal = new LinkedHashMap<String, Record>();
70 added = new LinkedHashMap<String, Record>(); 73 added = new LinkedHashMap<String, Record>();
71 removed = new LinkedHashMap<String, Record>(); 74 removed = new LinkedHashMap<String, Record>();
72 merged = new LinkedHashMap<String, Record>(); 75 merged = new LinkedHashMap<String, Record>();
73 try { 76 try {
74 // XXX skip(40) if we don't need these?
75 byte[] parents = new byte[40]; 77 byte[] parents = new byte[40];
76 da.readBytes(parents, 0, 40); 78 da.readBytes(parents, 0, 40);
79 p1 = Nodeid.fromBinary(parents, 0);
80 p2 = Nodeid.fromBinary(parents, 20);
77 parents = null; 81 parents = null;
78 // hg init; hg up produces an empty repository where dirstate has parents (40 bytes) only 82 // hg init; hg up produces an empty repository where dirstate has parents (40 bytes) only
79 while (!da.isEmpty()) { 83 while (!da.isEmpty()) {
80 final byte state = da.readByte(); 84 final byte state = da.readByte();
81 final int fmode = da.readInt(); 85 final int fmode = da.readInt();
113 } finally { 117 } finally {
114 da.done(); 118 da.done();
115 } 119 }
116 } 120 }
117 121
122 // do not read whole dirstate if all we need is WC parent information
123 private void readParents() {
124 if (dirstateFile == null || !dirstateFile.exists()) {
125 return;
126 }
127 DataAccess da = accessProvider.create(dirstateFile);
128 if (da.isEmpty()) {
129 return;
130 }
131 try {
132 byte[] parents = new byte[40];
133 da.readBytes(parents, 0, 40);
134 p1 = Nodeid.fromBinary(parents, 0);
135 p2 = Nodeid.fromBinary(parents, 20);
136 parents = null;
137 } catch (IOException ex) {
138 throw new HgBadStateException(ex); // XXX in fact, our exception is not the best solution here.
139 } finally {
140 da.done();
141 }
142 }
143
144 /**
145 * @return array of length 2 with working copy parents, non null.
146 */
147 public Nodeid[] parents() {
148 if (p1 == null) {
149 readParents();
150 }
151 Nodeid[] rv = new Nodeid[2];
152 rv[0] = p1;
153 rv[1] = p2;
154 return rv;
155 }
156
118 // new, modifiable collection 157 // new, modifiable collection
119 /*package-local*/ TreeSet<String> all() { 158 /*package-local*/ TreeSet<String> all() {
120 read(); 159 read();
121 TreeSet<String> rv = new TreeSet<String>(); 160 TreeSet<String> rv = new TreeSet<String>();
122 @SuppressWarnings("unchecked") 161 @SuppressWarnings("unchecked")