comparison src/org/tmatesoft/hg/repo/HgRepository.java @ 481:a458f9fb00ce

Access to user-supplied message of last commit
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 07 Aug 2012 14:02:28 +0200
parents 7bcfbc255f48
children 6c67debed07e
comparison
equal deleted inserted replaced
480:f3fab7a20841 481:a458f9fb00ce
17 package org.tmatesoft.hg.repo; 17 package org.tmatesoft.hg.repo;
18 18
19 import static org.tmatesoft.hg.util.LogFacility.Severity.*; 19 import static org.tmatesoft.hg.util.LogFacility.Severity.*;
20 20
21 import java.io.File; 21 import java.io.File;
22 import java.io.FileReader;
22 import java.io.IOException; 23 import java.io.IOException;
23 import java.io.StringReader; 24 import java.io.StringReader;
24 import java.lang.ref.SoftReference; 25 import java.lang.ref.SoftReference;
26 import java.nio.CharBuffer;
25 import java.util.ArrayList; 27 import java.util.ArrayList;
26 import java.util.Collections; 28 import java.util.Collections;
27 import java.util.HashMap; 29 import java.util.HashMap;
28 import java.util.List; 30 import java.util.List;
29 31
355 */ 357 */
356 public HgIgnore getIgnore() /*throws HgInvalidControlFileException */{ 358 public HgIgnore getIgnore() /*throws HgInvalidControlFileException */{
357 // TODO read config for additional locations 359 // TODO read config for additional locations
358 if (ignore == null) { 360 if (ignore == null) {
359 ignore = new HgIgnore(getToRepoPathHelper()); 361 ignore = new HgIgnore(getToRepoPathHelper());
360 File ignoreFile = new File(getWorkingDir(), ".hgignore"); 362 File ignoreFile = new File(getWorkingDir(), HgRepositoryFiles.HgIgnore.getPath());
361 try { 363 try {
362 final List<String> errors = ignore.read(ignoreFile); 364 final List<String> errors = ignore.read(ignoreFile);
363 if (errors != null) { 365 if (errors != null) {
364 getContext().getLog().dump(getClass(), Warn, "Syntax errors parsing .hgignore:\n%s", Internals.join(errors, ",\n")); 366 getContext().getLog().dump(getClass(), Warn, "Syntax errors parsing %s:\n%s", ignoreFile.getName(), Internals.join(errors, ",\n"));
365 } 367 }
366 } catch (IOException ex) { 368 } catch (IOException ex) {
367 final String m = "Error reading .hgignore file"; 369 final String m = "Error reading .hgignore file";
368 getContext().getLog().dump(getClass(), Warn, ex, m); 370 getContext().getLog().dump(getClass(), Warn, ex, m);
369 // throw new HgInvalidControlFileException(m, ex, ignoreFile); 371 // throw new HgInvalidControlFileException(m, ex, ignoreFile);
370 } 372 }
371 } 373 }
372 return ignore; 374 return ignore;
375 }
376
377 /**
378 * Mercurial saves message user has supplied for a commit to facilitate message re-use in case commit fails.
379 * This method provides this saved message.
380 *
381 * @return message used for last commit attempt, or <code>null</code> if none
382 */
383 public String getCommitLastMessage() {
384 File lastMessage = new File(getRepositoryRoot(), HgRepositoryFiles.LastMessage.getPath());
385 if (!lastMessage.canRead()) {
386 return null;
387 }
388 FileReader fr = null;
389 try {
390 fr = new FileReader(lastMessage);
391 CharBuffer cb = CharBuffer.allocate(Internals.ltoi(lastMessage.length()));
392 fr.read(cb);
393 return cb.flip().toString();
394 } catch (IOException ex) {
395 throw new HgInvalidControlFileException("Can't retrieve message of last commit attempt", ex, lastMessage);
396 } finally {
397 if (fr != null) {
398 try {
399 fr.close();
400 } catch (IOException ex) {
401 getContext().getLog().dump(getClass(), Warn, "Failed to close %s after read", lastMessage);
402 }
403 }
404 }
373 } 405 }
374 406
375 /*package-local*/ DataAccessProvider getDataAccess() { 407 /*package-local*/ DataAccessProvider getDataAccess() {
376 return dataAccess; 408 return dataAccess;
377 } 409 }