From 533272372945e0e5ddbab1502f185c5afd582f19 Mon Sep 17 00:00:00 2001 From: Thomas Wolf Date: Sat, 11 Jul 2020 15:29:04 +0200 Subject: DiffFormatter: correctly deal with tracked files in ignored folders In JGit 5.0, the FileTreeIterator was changed to skip ignored folders by default. To catch tracked files inside ignored folders, the tree walk needs to have a DirCacheIterator, and the FileTreeIterator has to know about that DirCacheIterator via setDirCacheIterator(). (Or the optimization has to be switched off explicitly via setWalkIgnoredDirectories(true).) Skipping ignored directories is an important optimization in some cases, for instance in node.js/npm projects, where we'd otherwise traverse the whole huge and deep hierarchy of the typically ignored node_modules folder. While all uses of WorkingTreeIterator in JGit had been adapted, DiffFormatter was forgotten. To make it work correctly (again) also for such cases, make it set up a WorkingTreeeIterator automatically, and make sure the WorkingTreeSource can find such files, too. Also pass the repository to the TreeWalks used inside the DiffFormatter to pick up the correct attributes, filters, and line-ending settings. Bug: 565081 Change-Id: Ie88ac81166dc396ba28b83313964c1712b6ca199 Signed-off-by: Thomas Wolf --- .../src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/treewalk') diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java index 994af2607c..4c26dd0c40 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java @@ -2,7 +2,7 @@ * Copyright (C) 2008, Shawn O. Pearce * Copyright (C) 2010, Christian Halstrick * Copyright (C) 2010, Matthias Sohn - * Copyright (C) 2012-2013, Robin Rosenberg and others + * Copyright (C) 2012-2020, Robin Rosenberg and others * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0 which is available at @@ -522,6 +522,17 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator { return state.options; } + /** + * Retrieves the {@link Repository} this {@link WorkingTreeIterator} + * operates on. + * + * @return the {@link Repository} + * @since 5.9 + */ + public Repository getRepository() { + return repository; + } + /** {@inheritDoc} */ @Override public int idOffset() { -- cgit v1.2.3