comparison src/org/tmatesoft/hg/core/HgCommitCommand.java @ 628:6526d8adbc0f

Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 22 May 2013 15:52:31 +0200
parents 5afc7eedb3dd
children b4242b7e7dfe
comparison
equal deleted inserted replaced
627:5153eb73b18d 628:6526d8adbc0f
28 import org.tmatesoft.hg.internal.Transaction; 28 import org.tmatesoft.hg.internal.Transaction;
29 import org.tmatesoft.hg.internal.WorkingCopyContent; 29 import org.tmatesoft.hg.internal.WorkingCopyContent;
30 import org.tmatesoft.hg.repo.HgChangelog; 30 import org.tmatesoft.hg.repo.HgChangelog;
31 import org.tmatesoft.hg.repo.HgDataFile; 31 import org.tmatesoft.hg.repo.HgDataFile;
32 import org.tmatesoft.hg.repo.HgInternals; 32 import org.tmatesoft.hg.repo.HgInternals;
33 import org.tmatesoft.hg.repo.HgInvalidControlFileException;
33 import org.tmatesoft.hg.repo.HgRepository; 34 import org.tmatesoft.hg.repo.HgRepository;
34 import org.tmatesoft.hg.repo.HgRuntimeException; 35 import org.tmatesoft.hg.repo.HgRuntimeException;
35 import org.tmatesoft.hg.repo.HgStatusCollector.Record; 36 import org.tmatesoft.hg.repo.HgStatusCollector.Record;
36 import org.tmatesoft.hg.repo.HgWorkingCopyStatusCollector; 37 import org.tmatesoft.hg.repo.HgWorkingCopyStatusCollector;
37 import org.tmatesoft.hg.util.CancelledException; 38 import org.tmatesoft.hg.util.CancelledException;
72 73
73 /** 74 /**
74 * Tell if changes in the working directory constitute merge commit. May be invoked prior to (and independently from) {@link #execute()} 75 * Tell if changes in the working directory constitute merge commit. May be invoked prior to (and independently from) {@link #execute()}
75 * 76 *
76 * @return <code>true</code> if working directory changes are result of a merge 77 * @return <code>true</code> if working directory changes are result of a merge
77 * @throws HgException subclass thereof to indicate specific issue with the repository 78 * @throws HgLibraryFailureException to indicate unexpected issue with the repository
79 * @throws HgException subclass thereof to indicate other specific issue with repository state
78 */ 80 */
79 public boolean isMergeCommit() throws HgException { 81 public boolean isMergeCommit() throws HgException {
80 int[] parents = new int[2]; 82 try {
81 detectParentFromDirstate(parents); 83 int[] parents = new int[2];
82 return parents[0] != NO_REVISION && parents[1] != NO_REVISION; 84 detectParentFromDirstate(parents);
85 return parents[0] != NO_REVISION && parents[1] != NO_REVISION;
86 } catch (HgRuntimeException ex) {
87 throw new HgLibraryFailureException(ex);
88 }
83 } 89 }
84 90
85 /** 91 /**
86 * @throws HgException subclass thereof to indicate specific issue with the command arguments or repository state 92 * @throws HgException subclass thereof to indicate specific issue with the command arguments or repository state
87 * @throws HgRepositoryLockException if failed to lock the repo for modifications 93 * @throws HgRepositoryLockException if failed to lock the repo for modifications
150 throw new IllegalStateException("Call #execute() first!"); 156 throw new IllegalStateException("Call #execute() first!");
151 } 157 }
152 return newRevision; 158 return newRevision;
153 } 159 }
154 160
155 private String detectBranch() { 161 private String detectBranch() throws HgInvalidControlFileException {
156 return repo.getWorkingCopyBranchName(); 162 return repo.getWorkingCopyBranchName();
157 } 163 }
158 164
159 private String detectUser() { 165 private String detectUser() {
160 if (user != null) { 166 if (user != null) {
162 } 168 }
163 // TODO HgInternals is odd place for getNextCommitUsername() 169 // TODO HgInternals is odd place for getNextCommitUsername()
164 return new HgInternals(repo).getNextCommitUsername(); 170 return new HgInternals(repo).getNextCommitUsername();
165 } 171 }
166 172
167 private void detectParentFromDirstate(int[] parents) { 173 private void detectParentFromDirstate(int[] parents) throws HgRuntimeException {
168 Pair<Nodeid, Nodeid> pn = repo.getWorkingCopyParents(); 174 Pair<Nodeid, Nodeid> pn = repo.getWorkingCopyParents();
169 HgChangelog clog = repo.getChangelog(); 175 HgChangelog clog = repo.getChangelog();
170 parents[0] = pn.first().isNull() ? NO_REVISION : clog.getRevisionIndex(pn.first()); 176 parents[0] = pn.first().isNull() ? NO_REVISION : clog.getRevisionIndex(pn.first());
171 parents[1] = pn.second().isNull() ? NO_REVISION : clog.getRevisionIndex(pn.second()); 177 parents[1] = pn.second().isNull() ? NO_REVISION : clog.getRevisionIndex(pn.second());
172 } 178 }