From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Shawn O. Pearce" Subject: [JGIT PATCH 5/8] Allow CanonicalTreeParsers to be created with a UTF-8 path prefix Date: Mon, 13 Oct 2008 14:10:14 -0700 Message-ID: <1223932217-4771-6-git-send-email-spearce@spearce.org> References: <1223932217-4771-1-git-send-email-spearce@spearce.org> <1223932217-4771-2-git-send-email-spearce@spearce.org> <1223932217-4771-3-git-send-email-spearce@spearce.org> <1223932217-4771-4-git-send-email-spearce@spearce.org> <1223932217-4771-5-git-send-email-spearce@spearce.org> Cc: git@vger.kernel.org To: Robin Rosenberg X-From: git-owner@vger.kernel.org Mon Oct 13 23:12:25 2008 Return-path: Envelope-to: gcvg-git-2@gmane.org Received: from vger.kernel.org ([209.132.176.167]) by lo.gmane.org with esmtp (Exim 4.50) id 1KpUiF-0002Kl-0T for gcvg-git-2@gmane.org; Mon, 13 Oct 2008 23:12:23 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756485AbYJMVKe (ORCPT ); Mon, 13 Oct 2008 17:10:34 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1756570AbYJMVKb (ORCPT ); Mon, 13 Oct 2008 17:10:31 -0400 Received: from george.spearce.org ([209.20.77.23]:39779 "EHLO george.spearce.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756031AbYJMVKW (ORCPT ); Mon, 13 Oct 2008 17:10:22 -0400 Received: by george.spearce.org (Postfix, from userid 1000) id D8A3D383A4; Mon, 13 Oct 2008 21:10:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.2.4 (2008-01-01) on george.spearce.org X-Spam-Level: X-Spam-Status: No, score=-4.4 required=4.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham version=3.2.4 Received: from localhost.localdomain (localhost [127.0.0.1]) by george.spearce.org (Postfix) with ESMTP id E85433838D; Mon, 13 Oct 2008 21:10:19 +0000 (UTC) X-Mailer: git-send-email 1.6.0.2.706.g340fc In-Reply-To: <1223932217-4771-5-git-send-email-spearce@spearce.org> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: Creating an iterator with a path prefix permits a tree to be "mounted" at a different part of a repository, permitting more sophisticated merge strategies beyond just 1:1 path matching. Signed-off-by: Shawn O. Pearce --- .../jgit/treewalk/AbstractTreeIterator.java | 31 ++++++++++++++++++++ .../spearce/jgit/treewalk/CanonicalTreeParser.java | 28 ++++++++++++++++++ .../src/org/spearce/jgit/treewalk/TreeWalk.java | 2 +- 3 files changed, 60 insertions(+), 1 deletions(-) diff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java index 5226ab6..adfbb11 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java +++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java @@ -170,6 +170,37 @@ protected AbstractTreeIterator(final String prefix) { } /** + * Create a new iterator with no parent and a prefix. + *

+ * The prefix path supplied is inserted in front of all paths generated by + * this iterator. It is intended to be used when an iterator is being + * created for a subsection of an overall repository and needs to be + * combined with other iterators that are created to run over the entire + * repository namespace. + * + * @param prefix + * position of this iterator in the repository tree. The value + * may be null or the empty array to indicate the prefix is the + * root of the repository. A trailing slash ('/') is + * automatically appended if the prefix does not end in '/'. + */ + protected AbstractTreeIterator(final byte[] prefix) { + parent = null; + + if (prefix != null && prefix.length > 0) { + pathLen = prefix.length; + path = new byte[Math.max(DEFAULT_PATH_SIZE, pathLen + 1)]; + System.arraycopy(prefix, 0, path, 0, pathLen); + if (path[pathLen - 1] != '/') + path[pathLen++] = '/'; + pathOffset = pathLen; + } else { + path = new byte[DEFAULT_PATH_SIZE]; + pathOffset = 0; + } + } + + /** * Create an iterator for a subtree of an existing iterator. * * @param p diff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/CanonicalTreeParser.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/CanonicalTreeParser.java index dcc53cd..3dac6dd 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/CanonicalTreeParser.java +++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/CanonicalTreeParser.java @@ -62,6 +62,34 @@ public CanonicalTreeParser() { // Nothing necessary. } + /** + * Create a new parser for a tree appearing in a subset of a repository. + * + * @param prefix + * position of this iterator in the repository tree. The value + * may be null or the empty array to indicate the prefix is the + * root of the repository. A trailing slash ('/') is + * automatically appended if the prefix does not end in '/'. + * @param repo + * repository to load the tree data from. + * @param treeId + * identity of the tree being parsed; used only in exception + * messages if data corruption is found. + * @throws MissingObjectException + * the object supplied is not available from the repository. + * @throws IncorrectObjectTypeException + * the object supplied as an argument is not actually a tree and + * cannot be parsed as though it were a tree. + * @throws IOException + * a loose object or pack file could not be read. + */ + public CanonicalTreeParser(final byte[] prefix, final Repository repo, + final ObjectId treeId) throws IncorrectObjectTypeException, + IOException { + super(prefix); + reset(repo, treeId); + } + private CanonicalTreeParser(final CanonicalTreeParser p) { super(p); } diff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java index 3af3d09..b1cbd2d 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java +++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java @@ -307,7 +307,7 @@ public void reset(final ObjectId[] ids) throws MissingObjectException, o = trees[i]; while (o.parent != null) o = o.parent; - if (o instanceof CanonicalTreeParser) { + if (o instanceof CanonicalTreeParser && o.pathOffset == 0) { o.matches = null; o.matchShift = 0; ((CanonicalTreeParser) o).reset(db, ids[i]); -- 1.6.0.2.706.g340fc