changeset 683:98ff1fb49abe

Update commands to use changeset Nodeid and int in uniform way, clients of core.* classes shall not go back and forth from int to Nodeid
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 24 Jul 2013 16:40:15 +0200
parents f568330dd9c0
children 2353e4217f59
files src/org/tmatesoft/hg/core/HgCatCommand.java src/org/tmatesoft/hg/core/HgDiffCommand.java src/org/tmatesoft/hg/core/HgLogCommand.java src/org/tmatesoft/hg/core/HgManifestCommand.java src/org/tmatesoft/hg/core/HgStatusCommand.java
diffstat 5 files changed, 132 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/core/HgCatCommand.java	Mon Jul 22 22:47:06 2013 +0200
+++ b/src/org/tmatesoft/hg/core/HgCatCommand.java	Wed Jul 24 16:40:15 2013 +0200
@@ -23,6 +23,7 @@
 import java.io.IOException;
 import java.nio.ByteBuffer;
 
+import org.tmatesoft.hg.internal.CsetParamKeeper;
 import org.tmatesoft.hg.repo.HgDataFile;
 import org.tmatesoft.hg.repo.HgRepository;
 import org.tmatesoft.hg.repo.HgRuntimeException;
@@ -74,7 +75,7 @@
 	 * although possible, makes little sense (command would fail if executed).  
  	 * @return <code>this</code> for convenience
 	 */
-	public HgCatCommand revision(int fileRevisionIndex) {
+	public HgCatCommand revision(int fileRevisionIndex) { // TODO [2.0 API break] shall throw HgBadArgumentException, like other commands do
 		if (wrongRevisionIndex(fileRevisionIndex)) {
 			throw new IllegalArgumentException(String.valueOf(fileRevisionIndex));
 		}
@@ -130,6 +131,18 @@
 	}
 
 	/**
+	 * Select file by changeset
+	 * @see #changeset(Nodeid) 
+	 * @param revisionIndex index of changelog revision
+	 * @return <code>this</code> for convenience
+	 * @throws HgBadArgumentException if failed to find supplied changeset revision
+	 */
+	public HgCatCommand changeset(int revisionIndex) throws HgBadArgumentException {
+		int ri = new CsetParamKeeper(repo).set(revisionIndex).get();
+		return changeset(repo.getChangelog().getRevision(ri));
+	}
+
+	/**
 	 * Runs the command with current set of parameters and pipes data to provided sink.
 	 * 
 	 * @param sink output channel to write data to.
--- a/src/org/tmatesoft/hg/core/HgDiffCommand.java	Mon Jul 22 22:47:06 2013 +0200
+++ b/src/org/tmatesoft/hg/core/HgDiffCommand.java	Wed Jul 24 16:40:15 2013 +0200
@@ -94,6 +94,20 @@
 	}
 	
 	/**
+	 * Select range of file history, limited by changesets.
+	 * @see #range(int, int)
+	 * @param cset1 changelog revision, left range boundary
+	 * @param cset2 changelog revision, right range boundary
+	 * @return <code>this</code> for convenience
+	 * @throws HgBadArgumentException if revisions are not valid changeset identifiers
+	 */
+	public HgDiffCommand range(Nodeid cset1, Nodeid cset2) throws HgBadArgumentException {
+		clogRevIndexStart.set(cset1);
+		clogRevIndexEnd.set(cset2);
+		return this;
+	}
+	
+	/**
 	 * Selects revision for {@link #executeParentsAnnotate(HgBlameInspector)}, the one 
 	 * to diff against its parents. 
 	 * 
@@ -109,6 +123,20 @@
 		clogRevIndexEnd.set(changelogRevIndex);
 		return this;
 	}
+	
+	/**
+	 * Select specific changeset or a range [0..changeset], like {@link #changeset(int)}
+	 * 
+	 * @param nid changeset
+	 * @return <code>this</code> for convenience
+	 * @throws HgBadArgumentException if failed to find supplied changeset revision 
+	 */
+	public HgDiffCommand changeset(Nodeid nid) throws HgBadArgumentException {
+		clogRevIndexStart.set(0);
+		clogRevIndexEnd.set(nid);
+		return this;
+	}
+
 
 	/**
 	 * Revision differences are reported in selected order when 
--- a/src/org/tmatesoft/hg/core/HgLogCommand.java	Mon Jul 22 22:47:06 2013 +0200
+++ b/src/org/tmatesoft/hg/core/HgLogCommand.java	Wed Jul 24 16:40:15 2013 +0200
@@ -180,6 +180,34 @@
 	}
 	
 	/**
+	 * Limit history to specified range.
+	 * 
+	 * @see #range(int, int)
+	 * @param cset1 range start revision
+	 * @param cset2 range end revision
+	 * @return <code>this</code> instance for convenience
+	 * @throws HgBadArgumentException if revisions are not valid changeset identifiers
+	 */
+	public HgLogCommand range(Nodeid cset1, Nodeid cset2) throws HgBadArgumentException {
+		CsetParamKeeper pk = new CsetParamKeeper(repo);
+		int r1 = pk.set(cset1).get();
+		int r2 = pk.set(cset2).get();
+		return range(r1, r2);
+	}
+	
+	/**
+	 * Select specific changeset by index
+	 * @see #changeset(Nodeid)
+	 * @param revisionIndex index of changelog revision
+	 * @return <code>this</code> for convenience
+	 * @throws HgBadArgumentException if failed to find supplied changeset revision
+	 */
+	public HgLogCommand changeset(int revisionIndex) throws HgBadArgumentException {
+		int ri = new CsetParamKeeper(repo).set(revisionIndex).get();
+		return range(ri, ri);
+	}
+	
+	/**
 	 * Select specific changeset
 	 * 
 	 * @param nid changeset revision
--- a/src/org/tmatesoft/hg/core/HgManifestCommand.java	Mon Jul 22 22:47:06 2013 +0200
+++ b/src/org/tmatesoft/hg/core/HgManifestCommand.java	Wed Jul 24 16:40:15 2013 +0200
@@ -77,6 +77,22 @@
 	}
 	
 	/**
+	 * Limit command to visit specific subset of repository revisions
+	 * 
+	 * @see #range(int, int)
+	 * @param cset1 range start revision
+	 * @param cset2 range end revision
+	 * @return <code>this</code> instance for convenience
+	 * @throws HgBadArgumentException if revisions are not valid changeset identifiers
+	 */
+	public HgManifestCommand range(Nodeid cset1, Nodeid cset2) throws HgBadArgumentException {
+		CsetParamKeeper pk = new CsetParamKeeper(repo);
+		int r1 = pk.set(cset1).get();
+		int r2 = pk.set(cset2).get();
+		return range(r1, r2);
+	}
+	
+	/**
 	 * Select changeset for the command using revision index 
 	 * @param csetRevisionIndex index of changeset revision
 	 * @return <code>this</code> for convenience.
--- a/src/org/tmatesoft/hg/core/HgStatusCommand.java	Mon Jul 22 22:47:06 2013 +0200
+++ b/src/org/tmatesoft/hg/core/HgStatusCommand.java	Wed Jul 24 16:40:15 2013 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011-2012 TMate Software Ltd
+ * Copyright (c) 2011-2013 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
@@ -25,6 +25,7 @@
 
 import org.tmatesoft.hg.internal.AdapterPlug;
 import org.tmatesoft.hg.internal.ChangelogHelper;
+import org.tmatesoft.hg.internal.CsetParamKeeper;
 import org.tmatesoft.hg.internal.Internals;
 import org.tmatesoft.hg.repo.HgRepository;
 import org.tmatesoft.hg.repo.HgRuntimeException;
@@ -115,9 +116,21 @@
 			changesetRevisionIndex = TIP;
 		}
 		startRevision = changesetRevisionIndex;
+		// TODO [2.0 API break] shall throw HgBadArgumentException, like other commands do
 		return this;
 	}
-	
+
+	/**
+	 * Select base revision for difference
+	 * @param changeset changelog revision, left range boundary if used in conjunction with {@link #revision(int)}  
+	 * @return <code>this</code> for convenience
+	 * @throws HgBadArgumentException if revision is not a valid changeset identifier
+	 */
+	public HgStatusCommand base(Nodeid changeset) throws HgBadArgumentException {
+		int ri = new CsetParamKeeper(repo).set(changeset).get();
+		return base(ri);
+	}
+
 	/**
 	 * Revision without base == --change
 	 * Pass {@link HgRepository#WORKING_COPY} or {@link HgRepository#BAD_REVISION} to reset
@@ -133,20 +146,45 @@
 			throw new IllegalArgumentException(String.valueOf(changesetRevisionIndex));
 		}
 		endRevision = changesetRevisionIndex;
+		// TODO [2.0 API break] shall throw HgBadArgumentException, like other commands do
 		return this;
 	}
-	
+
+	/**
+	 * Select changeset to show difference
+	 * @see #revision(int) 
+	 * @param changeset changelog revision, right range boundary if <code>base</code> revision is set  
+	 * @return <code>this</code> for convenience
+	 * @throws HgBadArgumentException if revision is not a valid changeset identifier
+	 */
+	public HgStatusCommand revision(Nodeid changeset) throws HgBadArgumentException {
+		int ri = new CsetParamKeeper(repo).set(changeset).get();
+		return revision(ri);
+	}
+
 	/**
 	 * Shorthand for {@link #base(int) cmd.base(BAD_REVISION)}{@link #change(int) .revision(revision)}
-	 *  
-	 * @param changesetRevisionIndex compare given revision against its parent
+	 * 
+	 * @param changesetIndex compare given revision against its parent
 	 * @return <code>this</code> for convenience
 	 */
-	public HgStatusCommand change(int changesetRevisionIndex) {
+	public HgStatusCommand change(int changesetIndex) {
 		base(BAD_REVISION);
-		return revision(changesetRevisionIndex);
+		return revision(changesetIndex);
 	}
-	
+
+	/**
+	 * Report changes in specified changeset 
+	 * @see #change(int)
+	 * @param changeset changelog revision to get status of  
+	 * @return <code>this</code> for convenience
+	 * @throws HgBadArgumentException if revision is not a valid changeset identifier
+	 */
+	public HgStatusCommand change(Nodeid changeset) throws HgBadArgumentException {
+		base(BAD_REVISION);
+		return revision(changeset);
+	}
+
 	/**
 	 * Limit status operation to certain sub-tree.
 	 *