# HG changeset patch # User Artem Tikhomirov # Date 1344340948 -7200 # Node ID a458f9fb00ce15f49a8f64fae97105c0e3f89b54 # Parent f3fab7a208416e11c6358b228d1cb9992497d54c Access to user-supplied message of last commit diff -r f3fab7a20841 -r a458f9fb00ce cmdline/org/tmatesoft/hg/console/Main.java --- a/cmdline/org/tmatesoft/hg/console/Main.java Tue Jul 17 22:14:21 2012 +0200 +++ b/cmdline/org/tmatesoft/hg/console/Main.java Tue Aug 07 14:02:28 2012 +0200 @@ -109,6 +109,7 @@ public static void main(String[] args) throws Exception { Main m = new Main(args); + m.dumpCommitLastMessage(); // m.buildFileLog(); // m.testConsoleLog(); // m.testTreeTraversal(); @@ -129,6 +130,10 @@ // m.dumpCompleteManifestHigh(); // m.bunchOfTests(); } + + private void dumpCommitLastMessage() throws Exception { + System.out.println(hgRepo.getCommitLastMessage()); + } private void buildFileLog() throws Exception { final long start = System.nanoTime(); diff -r f3fab7a20841 -r a458f9fb00ce src/org/tmatesoft/hg/repo/HgRepository.java --- a/src/org/tmatesoft/hg/repo/HgRepository.java Tue Jul 17 22:14:21 2012 +0200 +++ b/src/org/tmatesoft/hg/repo/HgRepository.java Tue Aug 07 14:02:28 2012 +0200 @@ -19,9 +19,11 @@ import static org.tmatesoft.hg.util.LogFacility.Severity.*; import java.io.File; +import java.io.FileReader; import java.io.IOException; import java.io.StringReader; import java.lang.ref.SoftReference; +import java.nio.CharBuffer; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -357,11 +359,11 @@ // TODO read config for additional locations if (ignore == null) { ignore = new HgIgnore(getToRepoPathHelper()); - File ignoreFile = new File(getWorkingDir(), ".hgignore"); + File ignoreFile = new File(getWorkingDir(), HgRepositoryFiles.HgIgnore.getPath()); try { final List errors = ignore.read(ignoreFile); if (errors != null) { - getContext().getLog().dump(getClass(), Warn, "Syntax errors parsing .hgignore:\n%s", Internals.join(errors, ",\n")); + getContext().getLog().dump(getClass(), Warn, "Syntax errors parsing %s:\n%s", ignoreFile.getName(), Internals.join(errors, ",\n")); } } catch (IOException ex) { final String m = "Error reading .hgignore file"; @@ -371,6 +373,36 @@ } return ignore; } + + /** + * Mercurial saves message user has supplied for a commit to facilitate message re-use in case commit fails. + * This method provides this saved message. + * + * @return message used for last commit attempt, or null if none + */ + public String getCommitLastMessage() { + File lastMessage = new File(getRepositoryRoot(), HgRepositoryFiles.LastMessage.getPath()); + if (!lastMessage.canRead()) { + return null; + } + FileReader fr = null; + try { + fr = new FileReader(lastMessage); + CharBuffer cb = CharBuffer.allocate(Internals.ltoi(lastMessage.length())); + fr.read(cb); + return cb.flip().toString(); + } catch (IOException ex) { + throw new HgInvalidControlFileException("Can't retrieve message of last commit attempt", ex, lastMessage); + } finally { + if (fr != null) { + try { + fr.close(); + } catch (IOException ex) { + getContext().getLog().dump(getClass(), Warn, "Failed to close %s after read", lastMessage); + } + } + } + } /*package-local*/ DataAccessProvider getDataAccess() { return dataAccess; diff -r f3fab7a20841 -r a458f9fb00ce src/org/tmatesoft/hg/repo/HgRepositoryFiles.java --- a/src/org/tmatesoft/hg/repo/HgRepositoryFiles.java Tue Jul 17 22:14:21 2012 +0200 +++ b/src/org/tmatesoft/hg/repo/HgRepositoryFiles.java Tue Aug 07 14:02:28 2012 +0200 @@ -27,7 +27,8 @@ HgIgnore(".hgignore"), HgTags(".hgtags"), HgEol(".hgeol"), Dirstate(".hg/dirstate"), HgLocalTags(".hg/localtags"), - HgSub(".hgsub"), HgSubstate(".hgsubstate"); + HgSub(".hgsub"), HgSubstate(".hgsubstate"), + LastMessage("last-message.txt"); private String fname;