tikhomirov@328: /*
tikhomirov@403:  * Copyright (c) 2011-2012 TMate Software Ltd
tikhomirov@328:  *  
tikhomirov@328:  * This program is free software; you can redistribute it and/or modify
tikhomirov@328:  * it under the terms of the GNU General Public License as published by
tikhomirov@328:  * the Free Software Foundation; version 2 of the License.
tikhomirov@328:  *
tikhomirov@328:  * This program is distributed in the hope that it will be useful,
tikhomirov@328:  * but WITHOUT ANY WARRANTY; without even the implied warranty of
tikhomirov@328:  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
tikhomirov@328:  * GNU General Public License for more details.
tikhomirov@328:  *
tikhomirov@328:  * For information on how to redistribute this software under
tikhomirov@328:  * the terms of a license other than GNU General Public License
tikhomirov@328:  * contact TMate Software at support@hg4j.com
tikhomirov@328:  */
tikhomirov@328: package org.tmatesoft.hg.core;
tikhomirov@328: 
tikhomirov@328: import java.util.Collection;
tikhomirov@328: 
tikhomirov@423: import org.tmatesoft.hg.internal.Callback;
tikhomirov@515: import org.tmatesoft.hg.repo.HgDataFile;
tikhomirov@328: import org.tmatesoft.hg.util.Pair;
tikhomirov@328: 
tikhomirov@328: /**
tikhomirov@403:  * Handler to iterate file history (generally, any revlog) with access to parent-child relations between changesets.
tikhomirov@403:  * 
tikhomirov@403:  * @see HgLogCommand#execute(HgChangesetTreeHandler)
tikhomirov@403:  * 
tikhomirov@328:  * @author Artem Tikhomirov
tikhomirov@328:  * @author TMate Software Ltd.
tikhomirov@328:  */
tikhomirov@423: @Callback
tikhomirov@328: public interface HgChangesetTreeHandler {
tikhomirov@328: 	/**
tikhomirov@328: 	 * @param entry access to various pieces of information about current tree node. Instances might be 
tikhomirov@370: 	 * reused across calls and shall not be kept by client's code
tikhomirov@423: 	 * @throws HgCallbackTargetException wrapper for any exception user code may produce 
tikhomirov@328: 	 */
tikhomirov@427: 	public void treeElement(HgChangesetTreeHandler.TreeElement entry) throws HgCallbackTargetException;
tikhomirov@328: 
tikhomirov@328: 	interface TreeElement {
tikhomirov@328: 		/**
tikhomirov@328: 		 * Revision of the revlog being iterated. For example, when walking file history, return value represents file revisions.
tikhomirov@328: 		 * 
tikhomirov@328: 		 * @return revision of the revlog being iterated.
tikhomirov@328: 		 */
tikhomirov@423: 		public Nodeid fileRevision();
tikhomirov@515: 		
tikhomirov@515: 		/**
tikhomirov@515: 		 * File node, provided revlog being iterated is a {@link HgDataFile}; {@link #fileRevision()} 
tikhomirov@515: 		 * references revision from the history of this very {@link HgDataFile file}.
tikhomirov@515: 		 * 
tikhomirov@515: 		 * Comes handy when file history with renames is being followed to find out 
tikhomirov@515: 		 * file name for particular revision in the history.
tikhomirov@515: 		 * 
tikhomirov@515: 		 * @return instance of the file being walked, or <code>null</code> if it's not a file but other revlog.
tikhomirov@515: 		 */
tikhomirov@515: 		public HgDataFile file();
tikhomirov@366: 
tikhomirov@328: 		/**
tikhomirov@507: 		 * @return changeset associated with the current file revision
tikhomirov@328: 		 */
tikhomirov@423: 		public HgChangeset changeset();
tikhomirov@328: 
tikhomirov@328: 		/**
tikhomirov@328: 		 * Lightweight alternative to {@link #changeset()}, identifies changeset in which current file node has been modified 
tikhomirov@403: 		 * @return changeset {@link Nodeid revision} 
tikhomirov@328: 		 */
tikhomirov@423: 		public Nodeid changesetRevision();
tikhomirov@328: 
tikhomirov@328: 		/**
tikhomirov@507: 		 * Identifies parent changes, changesets where file/revlog in question was modified prior to change being visited.
tikhomirov@507: 		 * 
tikhomirov@507: 		 * Note, these are not necessarily in direct relation to parents of changeset from {@link #changeset()}
tikhomirov@507: 		 * 
tikhomirov@507: 		 * Imagine next history (grows from bottom to top):
tikhomirov@507: 		 * <pre>
tikhomirov@507: 		 * o A    o
tikhomirov@507: 		 * |   \  |
tikhomirov@507: 		 * o B  \/
tikhomirov@507: 		 * |    o C
tikhomirov@507: 		 * |   /
tikhomirov@507: 		 * o  /
tikhomirov@507: 		 * | /
tikhomirov@507: 		 * o D
tikhomirov@507: 		 * </pre>
tikhomirov@507: 		 * 
tikhomirov@507: 		 * When we are at {@link TreeElement} for <code>A</code>, <code>B</code> and <code>C</code> are changeset parents, naturally. However
tikhomirov@507: 		 * if the file/revlog we've been walking has not been changed in <code>B</code> and <code>C</code>, but e.g. in <code>D</code> only,
tikhomirov@507: 		 * then this {@link #parents()} call would return pair with single element only, pointing to <code>D</code>
tikhomirov@507: 		 * 
tikhomirov@328: 		 * @return changesets that correspond to parents of the current file node, either pair element may be <code>null</code>.
tikhomirov@328: 		 */
tikhomirov@423: 		public Pair<HgChangeset, HgChangeset> parents();
tikhomirov@328: 		
tikhomirov@328: 		/**
tikhomirov@328: 		 * Lightweight alternative to {@link #parents()}, give {@link Nodeid nodeids} only
tikhomirov@328: 		 * @return two values, neither is <code>null</code>, use {@link Nodeid#isNull()} to identify parent not set
tikhomirov@328: 		 */
tikhomirov@423: 		public Pair<Nodeid, Nodeid> parentRevisions();
tikhomirov@328: 
tikhomirov@366: 		/**
tikhomirov@366: 		 * Changes that originate from the given change and bear it as their parent. 
tikhomirov@366: 		 * @return collection (possibly empty) of immediate children of the change
tikhomirov@366: 		 */
tikhomirov@423: 		public Collection<HgChangeset> children();
tikhomirov@328: 
tikhomirov@328: 		/**
tikhomirov@328: 		 * Lightweight alternative to {@link #children()}.
tikhomirov@328: 		 * @return never <code>null</code>
tikhomirov@328: 		 */
tikhomirov@423: 		public Collection<Nodeid> childRevisions();
tikhomirov@328: 	}
tikhomirov@328: }