From e7df61ef4dc3991d1b218e70ec2095e8c10e97ce Mon Sep 17 00:00:00 2001 From: Christian Halstrick Date: Thu, 23 Jun 2016 17:08:45 +0200 Subject: [PATCH] Fix TreeWalk to reset attributes cache for each entry Treewalk has a member 'attr' which caches the attributes for the current entry. We did not reset the cache always when moving to next entry. The effect was that when there are no attributes for an entry 'a' but 'a' was skipped by a Treewalk filter then Treewalk stopped looking for attributes until TreeWalk.next() was called again. Change-Id: Ied39b7fb5f56afe7a237da17801003d0abe6b1c7 --- .../org/eclipse/jgit/api/AddCommandTest.java | 23 +++++++++++++++++++ .../org/eclipse/jgit/treewalk/TreeWalk.java | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java index 126ca5cdd1..eb2ee08787 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java @@ -135,6 +135,29 @@ public class AddCommandTest extends RepositoryTestCase { } } + @Test + public void testAttributesWithTreeWalkFilter() + throws IOException, GitAPIException { + writeTrashFile(".gitattributes", "*.txt filter=lfs"); + writeTrashFile("src/a.tmp", "foo"); + writeTrashFile("src/a.txt", "foo\n"); + File script = writeTempFile("sed s/o/e/g"); + + try (Git git = new Git(db)) { + StoredConfig config = git.getRepository().getConfig(); + config.setString("filter", "lfs", "clean", + "sh " + slashify(script.getPath())); + config.save(); + + git.add().addFilepattern(".gitattributes").call(); + git.commit().setMessage("attr").call(); + git.add().addFilepattern("src/a.txt").addFilepattern("src/a.tmp") + .addFilepattern(".gitattributes").call(); + git.commit().setMessage("c1").call(); + assertTrue(git.status().call().isClean()); + } + } + @Test public void testCleanFilterEnvironment() throws IOException, GitAPIException { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java index 7dac50a89a..911b7ffa1a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java @@ -795,7 +795,6 @@ public class TreeWalk implements AutoCloseable, AttributesProvider { public boolean next() throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException { try { - attrs = null; if (advance) { advance = false; postChildren = false; @@ -803,6 +802,7 @@ public class TreeWalk implements AutoCloseable, AttributesProvider { } for (;;) { + attrs = null; final AbstractTreeIterator t = min(); if (t.eof()) { if (depth > 0) { -- 2.39.5