comparison src/org/tmatesoft/hg/core/HgChangeset.java @ 445:d0e5dc3cae6e smartgit3

Support for phases functionality from Mercurial 2.1
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 05 Jun 2012 20:50:06 +0200
parents 9517df1ef7ec
children 03fd8d079e9c
comparison
equal deleted inserted replaced
412:63c5a9d7ca3f 445:d0e5dc3cae6e
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 *
15 * contact TMate Software at support@hg4j.com 15 * contact TMate Software at support@hg4j.com
16 */ 16 */
17 package org.tmatesoft.hg.core; 17 package org.tmatesoft.hg.core;
18 18
19 import java.util.ArrayList; 19 import java.util.ArrayList;
20 import java.util.Arrays;
20 import java.util.Collections; 21 import java.util.Collections;
22 import java.util.HashSet;
21 import java.util.List; 23 import java.util.List;
22 import java.util.Map; 24 import java.util.Map;
23 25
26 import org.tmatesoft.hg.internal.PhasesHelper;
24 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset; 27 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset;
25 import org.tmatesoft.hg.repo.HgChangelog; 28 import org.tmatesoft.hg.repo.HgChangelog;
29 import org.tmatesoft.hg.repo.HgPhase;
26 import org.tmatesoft.hg.repo.HgRepository; 30 import org.tmatesoft.hg.repo.HgRepository;
27 import org.tmatesoft.hg.repo.HgStatusCollector; 31 import org.tmatesoft.hg.repo.HgStatusCollector;
28 import org.tmatesoft.hg.util.Path; 32 import org.tmatesoft.hg.util.Path;
29 33
30 34
49 // 53 //
50 private List<HgFileRevision> modifiedFiles, addedFiles; 54 private List<HgFileRevision> modifiedFiles, addedFiles;
51 private List<Path> deletedFiles; 55 private List<Path> deletedFiles;
52 private int revNumber; 56 private int revNumber;
53 private byte[] parent1, parent2; 57 private byte[] parent1, parent2;
58 private PhasesHelper phaseHelper;
54 59
55 // XXX consider CommandContext with StatusCollector, PathPool etc. Commands optionally get CC through a cons or create new 60 // XXX consider CommandContext with StatusCollector, PathPool etc. Commands optionally get CC through a cons or create new
56 // and pass it around 61 // and pass it around
57 /*package-local*/HgChangeset(HgStatusCollector statusCollector, Path.Source pathFactory) { 62 /*package-local*/HgChangeset(HgStatusCollector statusCollector, Path.Source pathFactory) {
58 statusHelper = statusCollector; 63 statusHelper = statusCollector;
152 } 157 }
153 // read once for both p1 and p2 158 // read once for both p1 and p2
154 if (parent1 == null) { 159 if (parent1 == null) {
155 parent1 = new byte[20]; 160 parent1 = new byte[20];
156 parent2 = new byte[20]; 161 parent2 = new byte[20];
157 statusHelper.getRepo().getChangelog().parents(revNumber, new int[2], parent1, parent2); 162 getRepo().getChangelog().parents(revNumber, new int[2], parent1, parent2);
158 } 163 }
159 return Nodeid.fromBinary(parent1, 0); 164 return Nodeid.fromBinary(parent1, 0);
160 } 165 }
161 166
162 /** 167 /**
168 return parentHelper.safeSecondParent(nodeid); 173 return parentHelper.safeSecondParent(nodeid);
169 } 174 }
170 if (parent2 == null) { 175 if (parent2 == null) {
171 parent1 = new byte[20]; 176 parent1 = new byte[20];
172 parent2 = new byte[20]; 177 parent2 = new byte[20];
173 statusHelper.getRepo().getChangelog().parents(revNumber, new int[2], parent1, parent2); 178 getRepo().getChangelog().parents(revNumber, new int[2], parent1, parent2);
174 } 179 }
175 return Nodeid.fromBinary(parent2, 0); 180 return Nodeid.fromBinary(parent2, 0);
181 }
182
183 /**
184 * Tells the phase this changeset belongs to.
185 * @return one of {@link HgPhase} values
186 */
187 public HgPhase getPhase() throws HgInvalidControlFileException {
188 if (phaseHelper == null) {
189 // XXX would be handy to obtain ProgressSupport (perhaps, from statusHelper?)
190 // and pass it to #init(), so that there could be indication of file being read and cache being built
191 phaseHelper = new PhasesHelper(getRepo(), parentHelper);
192 }
193 return phaseHelper.getPhase(this);
176 } 194 }
177 195
178 @Override 196 @Override
179 public HgChangeset clone() { 197 public HgChangeset clone() {
180 try { 198 try {
183 return copy; 201 return copy;
184 } catch (CloneNotSupportedException ex) { 202 } catch (CloneNotSupportedException ex) {
185 throw new InternalError(ex.toString()); 203 throw new InternalError(ex.toString());
186 } 204 }
187 } 205 }
206
207 private HgRepository getRepo() {
208 return statusHelper.getRepo();
209 }
188 210
189 private /*synchronized*/ void initFileChanges() throws HgInvalidControlFileException { 211 private /*synchronized*/ void initFileChanges() throws HgInvalidControlFileException {
190 ArrayList<Path> deleted = new ArrayList<Path>(); 212 ArrayList<Path> deleted = new ArrayList<Path>();
191 ArrayList<HgFileRevision> modified = new ArrayList<HgFileRevision>(); 213 ArrayList<HgFileRevision> modified = new ArrayList<HgFileRevision>();
192 ArrayList<HgFileRevision> added = new ArrayList<HgFileRevision>(); 214 ArrayList<HgFileRevision> added = new ArrayList<HgFileRevision>();
193 HgStatusCollector.Record r = new HgStatusCollector.Record(); 215 HgStatusCollector.Record r = new HgStatusCollector.Record();
194 statusHelper.change(revNumber, r); 216 statusHelper.change(revNumber, r);
195 final HgRepository repo = statusHelper.getRepo(); 217 final HgRepository repo = getRepo();
196 for (Path s : r.getModified()) { 218 for (Path s : r.getModified()) {
197 Nodeid nid = r.nodeidAfterChange(s); 219 Nodeid nid = r.nodeidAfterChange(s);
198 if (nid == null) { 220 if (nid == null) {
199 throw new HgBadStateException(); 221 throw new HgBadStateException();
200 } 222 }