changeset 247:f052f40839ec

Issue 9: NPE in getModificationDate for files with status 'Unknown'
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 12 Aug 2011 17:17:37 +0200
parents ff4fdbab4e2d
children 3fbfce107f94
files src/org/tmatesoft/hg/core/HgStatus.java src/org/tmatesoft/hg/internal/ChangelogHelper.java
diffstat 2 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/core/HgStatus.java	Thu Aug 11 05:12:13 2011 +0200
+++ b/src/org/tmatesoft/hg/core/HgStatus.java	Fri Aug 12 17:17:37 2011 +0200
@@ -16,6 +16,7 @@
  */
 package org.tmatesoft.hg.core;
 
+import java.io.File;
 import java.util.Date;
 
 import org.tmatesoft.hg.internal.ChangelogHelper;
@@ -86,6 +87,10 @@
 	public Date getModificationDate() {
 		RawChangeset cset = logHelper.findLatestChangeWith(path);
 		if (cset == null) {
+			File localFile = new File(logHelper.getRepo().getWorkingDir(), path.toString());
+			if (localFile.canRead()) {
+				return new Date(localFile.lastModified());
+			}
 			// FIXME check dirstate and/or local file for tstamp
 			return new Date(); // what's correct 
 		} else {
--- a/src/org/tmatesoft/hg/internal/ChangelogHelper.java	Thu Aug 11 05:12:13 2011 +0200
+++ b/src/org/tmatesoft/hg/internal/ChangelogHelper.java	Fri Aug 12 17:17:37 2011 +0200
@@ -60,6 +60,9 @@
 	 */
 	public RawChangeset findLatestChangeWith(Path file) {
 		HgDataFile df = repo.getFileNode(file);
+		if (!df.exists()) {
+			return null;
+		}
 		int changelogRev = df.getChangesetLocalRevision(HgRepository.TIP);
 		if (changelogRev >= leftBoundary) {
 			// the method is likely to be invoked for different files,