Mercurial > jhg
changeset 235:fd845a53f53d
Experimental access to working dir parents
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 07 Jun 2011 04:54:13 +0200 |
parents | b2cfbe46f9b6 |
children | 883300108179 |
files | cmdline/org/tmatesoft/hg/console/Main.java src/org/tmatesoft/hg/repo/HgRepository.java src/org/tmatesoft/hg/util/Pair.java |
diffstat | 3 files changed, 80 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/cmdline/org/tmatesoft/hg/console/Main.java Tue Jun 07 04:28:32 2011 +0200 +++ b/cmdline/org/tmatesoft/hg/console/Main.java Tue Jun 07 04:54:13 2011 +0200 @@ -43,6 +43,7 @@ import org.tmatesoft.hg.repo.HgStatusInspector; import org.tmatesoft.hg.repo.HgWorkingCopyStatusCollector; import org.tmatesoft.hg.repo.HgChangelog.RawChangeset; +import org.tmatesoft.hg.util.Pair; import org.tmatesoft.hg.util.Path; /** @@ -68,7 +69,8 @@ public static void main(String[] args) throws Exception { Main m = new Main(args); - m.testEffectiveFileLog(); + m.testParents(); +// m.testEffectiveFileLog(); // m.testCatAtCsetRevision(); // m.testMergeState(); // m.testFileStatus(); @@ -83,6 +85,23 @@ // m.bunchOfTests(); } + private void testParents() throws Exception { + // hg parents cmd + final Pair<Nodeid, Nodeid> wcParents = hgRepo.getWorkingCopyParents(); + ChangesetDumpHandler dump = new ChangesetDumpHandler(hgRepo); + final HgChangelog clog = hgRepo.getChangelog(); + HgLogCommand cmd = new HgLogCommand(hgRepo); + if (wcParents.hasFirst()) { + int x = clog.getLocalRevision(wcParents.first()); + cmd.range(x, x).execute(dump); // FIXME HgLogCommand shall support Nodeid as revisions + } + if (wcParents.hasSecond()) { + int x = clog.getLocalRevision(wcParents.second()); + cmd.range(x, x).execute(dump); + } + } + + // -R \temp\hg\hg4j-50 src/org/tmatesoft/hg/internal/RevlogStream.java private void testEffectiveFileLog() { for (String fname : cmdLineOpts.getList("")) { System.out.println(fname);
--- a/src/org/tmatesoft/hg/repo/HgRepository.java Tue Jun 07 04:28:32 2011 +0200 +++ b/src/org/tmatesoft/hg/repo/HgRepository.java Tue Jun 07 04:54:13 2011 +0200 @@ -16,6 +16,8 @@ */ package org.tmatesoft.hg.repo; +import static org.tmatesoft.hg.core.Nodeid.NULL; + import java.io.File; import java.io.IOException; import java.io.StringReader; @@ -27,6 +29,7 @@ import java.util.List; import org.tmatesoft.hg.core.HgDataStreamException; +import org.tmatesoft.hg.core.Nodeid; import org.tmatesoft.hg.internal.ByteArrayChannel; import org.tmatesoft.hg.internal.ConfigFile; import org.tmatesoft.hg.internal.DataAccessProvider; @@ -35,6 +38,7 @@ import org.tmatesoft.hg.internal.RequiresFile; import org.tmatesoft.hg.internal.RevlogStream; import org.tmatesoft.hg.util.CancelledException; +import org.tmatesoft.hg.util.Pair; import org.tmatesoft.hg.util.Path; import org.tmatesoft.hg.util.PathRewrite; import org.tmatesoft.hg.util.ProgressSupport; @@ -219,6 +223,12 @@ public PathRewrite getToRepoPathHelper() { return normalizePath; } + + @Experimental(reason="return type and possible values (presently null, perhaps Nodeid.NULL) may get changed") + public Pair<Nodeid,Nodeid> getWorkingCopyParents() { + Nodeid[] p = loadDirstate().parents(); + return new Pair<Nodeid,Nodeid>(NULL == p[0] ? null : p[0], NULL == p[1] ? null : p[1]); + } // local to hide use of io.File. /*package-local*/ File getRepositoryRoot() {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/tmatesoft/hg/util/Pair.java Tue Jun 07 04:54:13 2011 +0200 @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2011 TMate Software Ltd + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * For information on how to redistribute this software under + * the terms of a license other than GNU General Public License + * contact TMate Software at support@hg4j.com + */ +package org.tmatesoft.hg.util; + +import org.tmatesoft.hg.internal.Experimental; + +/** + * Nothing but a holder for two values. + * + * @author Artem Tikhomirov + * @author TMate Software Ltd. + */ +@Experimental +public final class Pair<T1,T2> { + private final T1 value1; + private final T2 value2; + + public Pair(T1 v1, T2 v2) { + value1 = v1; + value2 = v2; + } + + public T1 first() { + return value1; + } + public T2 second() { + return value2; + } + public boolean hasFirst() { + return value1 != null; + } + public boolean hasSecond() { + return value2 != null; + } +} +