Mercurial > jhg
comparison src/org/tmatesoft/hg/internal/CommitFacility.java @ 636:ffce73efa2c2
HgCommitCommand: save last commit message
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
|---|---|
| date | Thu, 06 Jun 2013 19:39:06 +0200 |
| parents | 6526d8adbc0f |
| children | cd77bf51b562 |
comparison
equal
deleted
inserted
replaced
| 635:4ec2d44e2bf3 | 636:ffce73efa2c2 |
|---|---|
| 16 */ | 16 */ |
| 17 package org.tmatesoft.hg.internal; | 17 package org.tmatesoft.hg.internal; |
| 18 | 18 |
| 19 import static org.tmatesoft.hg.repo.HgRepository.DEFAULT_BRANCH_NAME; | 19 import static org.tmatesoft.hg.repo.HgRepository.DEFAULT_BRANCH_NAME; |
| 20 import static org.tmatesoft.hg.repo.HgRepository.NO_REVISION; | 20 import static org.tmatesoft.hg.repo.HgRepository.NO_REVISION; |
| 21 import static org.tmatesoft.hg.repo.HgRepositoryFiles.*; | |
| 21 import static org.tmatesoft.hg.repo.HgRepositoryFiles.Branch; | 22 import static org.tmatesoft.hg.repo.HgRepositoryFiles.Branch; |
| 22 import static org.tmatesoft.hg.repo.HgRepositoryFiles.UndoBranch; | 23 import static org.tmatesoft.hg.repo.HgRepositoryFiles.UndoBranch; |
| 23 import static org.tmatesoft.hg.util.LogFacility.Severity.Error; | 24 import static org.tmatesoft.hg.util.LogFacility.Severity.Error; |
| 24 | 25 |
| 25 import java.io.File; | 26 import java.io.File; |
| 26 import java.io.FileOutputStream; | 27 import java.io.FileOutputStream; |
| 28 import java.io.FileWriter; | |
| 27 import java.io.IOException; | 29 import java.io.IOException; |
| 28 import java.util.ArrayList; | 30 import java.util.ArrayList; |
| 29 import java.util.HashMap; | 31 import java.util.HashMap; |
| 30 import java.util.LinkedHashMap; | 32 import java.util.LinkedHashMap; |
| 31 import java.util.Map; | 33 import java.util.Map; |
| 133 // | 135 // |
| 134 // Forget removed | 136 // Forget removed |
| 135 for (Path p : removals) { | 137 for (Path p : removals) { |
| 136 newManifestRevision.remove(p); | 138 newManifestRevision.remove(p); |
| 137 } | 139 } |
| 140 // | |
| 141 saveCommitMessage(message); | |
| 138 // | 142 // |
| 139 // Register new/changed | 143 // Register new/changed |
| 140 LinkedHashMap<Path, RevlogStream> newlyAddedFiles = new LinkedHashMap<Path, RevlogStream>(); | 144 LinkedHashMap<Path, RevlogStream> newlyAddedFiles = new LinkedHashMap<Path, RevlogStream>(); |
| 141 ArrayList<Path> touchInDirstate = new ArrayList<Path>(); | 145 ArrayList<Path> touchInDirstate = new ArrayList<Path>(); |
| 142 for (Pair<HgDataFile, DataSource> e : files.values()) { | 146 for (Pair<HgDataFile, DataSource> e : files.values()) { |
| 233 // TODO Revisit: might be reasonable to send out a "Repo changed" notification, to clear | 237 // TODO Revisit: might be reasonable to send out a "Repo changed" notification, to clear |
| 234 // e.g. cached branch, tags and so on, not to rely on file change detection methods? | 238 // e.g. cached branch, tags and so on, not to rely on file change detection methods? |
| 235 // The same notification might come useful once Pull is implemented | 239 // The same notification might come useful once Pull is implemented |
| 236 return changesetRev; | 240 return changesetRev; |
| 237 } | 241 } |
| 242 | |
| 243 private void saveCommitMessage(String message) throws HgIOException { | |
| 244 File lastMessage = repo.getRepositoryFile(LastMessage); | |
| 245 // do not attempt to write if we are going to fail anyway | |
| 246 if ((lastMessage.isFile() && !lastMessage.canWrite()) || !lastMessage.getParentFile().canWrite()) { | |
| 247 return; | |
| 248 } | |
| 249 FileWriter w = null; | |
| 250 try { | |
| 251 w = new FileWriter(lastMessage); | |
| 252 w.write(message == null ? new String() : message); | |
| 253 w.flush(); | |
| 254 } catch (IOException ex) { | |
| 255 throw new HgIOException("Failed to save last commit message", ex, lastMessage); | |
| 256 } finally { | |
| 257 new FileUtils(repo.getLog()).closeQuietly(w, lastMessage); | |
| 258 } | |
| 259 } | |
| 238 /* | 260 /* |
| 239 private Pair<Integer, Integer> getManifestParents() { | 261 private Pair<Integer, Integer> getManifestParents() { |
| 240 return new Pair<Integer, Integer>(extractManifestRevisionIndex(p1Commit), extractManifestRevisionIndex(p2Commit)); | 262 return new Pair<Integer, Integer>(extractManifestRevisionIndex(p1Commit), extractManifestRevisionIndex(p2Commit)); |
| 241 } | 263 } |
| 242 | 264 |
