Mercurial > hg4j
changeset 506:27398bbfd543
Experiment to add a facility to check working files for actual changes
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 30 Nov 2012 22:52:39 +0100 |
parents | 3cd3c3d37432 |
children | a6435c1a42d0 |
files | cmdline/org/tmatesoft/hg/console/Main.java src/org/tmatesoft/hg/repo/HgWorkingCopyStatusCollector.java |
diffstat | 2 files changed, 26 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/cmdline/org/tmatesoft/hg/console/Main.java Fri Nov 30 22:08:11 2012 +0100 +++ b/cmdline/org/tmatesoft/hg/console/Main.java Fri Nov 30 22:52:39 2012 +0100 @@ -16,42 +16,31 @@ */ package org.tmatesoft.hg.console; -import static org.junit.Assert.*; import static org.tmatesoft.hg.repo.HgRepository.TIP; import static org.tmatesoft.hg.repo.HgRepository.WORKING_COPY; import static org.tmatesoft.hg.util.LogFacility.Severity.*; import java.io.File; -import java.io.IOException; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.regex.Pattern; -import org.tmatesoft.hg.core.HgManifestHandler; -import org.tmatesoft.hg.core.HgCallbackTargetException; -import org.tmatesoft.hg.core.HgCatCommand; import org.tmatesoft.hg.core.HgChangeset; -import org.tmatesoft.hg.core.HgChangesetFileSneaker; import org.tmatesoft.hg.core.HgChangesetTreeHandler; import org.tmatesoft.hg.core.HgException; import org.tmatesoft.hg.core.HgFileRevision; import org.tmatesoft.hg.core.HgLogCommand; import org.tmatesoft.hg.core.HgManifestCommand; +import org.tmatesoft.hg.core.HgManifestHandler; import org.tmatesoft.hg.core.Nodeid; import org.tmatesoft.hg.internal.BasicSessionContext; import org.tmatesoft.hg.internal.ByteArrayChannel; import org.tmatesoft.hg.internal.ConfigFile; import org.tmatesoft.hg.internal.DigestHelper; -import org.tmatesoft.hg.internal.IntMap; -import org.tmatesoft.hg.internal.Internals; import org.tmatesoft.hg.internal.PathGlobMatcher; -import org.tmatesoft.hg.internal.PhasesHelper; import org.tmatesoft.hg.internal.RelativePathRewrite; -import org.tmatesoft.hg.internal.RevisionDescendants; import org.tmatesoft.hg.internal.StreamLogFacility; import org.tmatesoft.hg.repo.HgBookmarks; import org.tmatesoft.hg.repo.HgBranches; @@ -66,30 +55,22 @@ import org.tmatesoft.hg.repo.HgManifest; import org.tmatesoft.hg.repo.HgManifest.Flags; import org.tmatesoft.hg.repo.HgMergeState; -import org.tmatesoft.hg.repo.HgParentChildMap; -import org.tmatesoft.hg.repo.HgPhase; import org.tmatesoft.hg.repo.HgRepository; +import org.tmatesoft.hg.repo.HgRevisionMap; import org.tmatesoft.hg.repo.HgRuntimeException; import org.tmatesoft.hg.repo.HgStatusCollector; import org.tmatesoft.hg.repo.HgStatusInspector; import org.tmatesoft.hg.repo.HgSubrepoLocation; import org.tmatesoft.hg.repo.HgSubrepoLocation.Kind; +import org.tmatesoft.hg.repo.HgWorkingCopyStatusCollector; import org.tmatesoft.hg.repo.ext.HgExtensionsManager; import org.tmatesoft.hg.repo.ext.HgExtensionsManager.HgExt; -import org.tmatesoft.hg.repo.ext.MqManager; import org.tmatesoft.hg.repo.ext.Rebase; -import org.tmatesoft.hg.repo.ext.MqManager.PatchRecord; -import org.tmatesoft.hg.repo.HgWorkingCopyStatusCollector; -import org.tmatesoft.hg.repo.HgRevisionMap; -import org.tmatesoft.hg.test.ExecHelper; -import org.tmatesoft.hg.test.OutputParser; import org.tmatesoft.hg.util.FileWalker; import org.tmatesoft.hg.util.LogFacility; import org.tmatesoft.hg.util.Pair; import org.tmatesoft.hg.util.Path; import org.tmatesoft.hg.util.PathRewrite; -import org.tmatesoft.hg.util.ProgressSupport; -import org.tmatesoft.hg.util.LogFacility.Severity; /** * Various debug dumps. @@ -159,7 +140,7 @@ private void dumpBookmarks() throws Exception { HgBookmarks bm = hgRepo.getBookmarks(); String active = bm.getActiveBookmarkName(); - ArrayList<String> all = new ArrayList(bm.getAllBookmarks()); + ArrayList<String> all = new ArrayList<String>(bm.getAllBookmarks()); Collections.sort(all); for (String bmname : all) { if (bmname.equals(active)) {
--- a/src/org/tmatesoft/hg/repo/HgWorkingCopyStatusCollector.java Fri Nov 30 22:08:11 2012 +0100 +++ b/src/org/tmatesoft/hg/repo/HgWorkingCopyStatusCollector.java Fri Nov 30 22:52:39 2012 +0100 @@ -34,6 +34,7 @@ import org.tmatesoft.hg.core.Nodeid; import org.tmatesoft.hg.core.SessionContext; import org.tmatesoft.hg.internal.ByteArrayChannel; +import org.tmatesoft.hg.internal.Experimental; import org.tmatesoft.hg.internal.FilterByteChannel; import org.tmatesoft.hg.internal.Internals; import org.tmatesoft.hg.internal.ManifestRevision; @@ -162,7 +163,7 @@ * Walk working copy, analyze status for each file found and missing. * May be invoked few times. * - * <p>There's no dedicated constant to for working copy parent, at least now. + * <p>There's no dedicated constant for working copy parent, at least now. * Use {@link HgRepository#WORKING_COPY} to indicate comparison * shall be run against working copy parent. Although a bit confusing, single case doesn't * justify a dedicated constant. @@ -322,6 +323,26 @@ } return rv; } + + /** + * Compares file state from working directory against parent recorded in dirstate. + * Might be handy for merged files, always reported as 'modified' or files deemed modified + * based on their flags change. + * + * @param fname repository-relative path to the file in question + * @param fileInfo file content mediator + * @return <code>true</code> when content in working dir differs from that of manifest-recorded revision + */ + @Experimental(reason="Perhaps, HgDataFile#isWorkingCopyChanged() would be better - no need to pass any arguments?") + public boolean hasTangibleChanges(Path fname, FileInfo fileInfo) throws HgRuntimeException { + // see #checkLocalStatusAgainstFile() below for the origin of changed file check + HgDataFile df = repo.getFileNode(fname); + if (!df.exists()) { + throw new HgInvalidFileException("File not found", null).setFileName(fname); + } + Nodeid rev = getDirstateParentManifest().nodeid(fname); + return rev == null || !areTheSame(fileInfo, df, rev); + } //********************************************