/*******************************************************************************
 * Copyright (C) 2010, Dariusz Luksza <dariusz@luksza.org>
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/
package org.eclipse.egit.ui.internal.synchronize.model;

import static org.eclipse.jgit.treewalk.filter.TreeFilter.ANY_DIFF;

import java.io.IOException;

import org.eclipse.egit.ui.UIText;
import org.eclipse.jgit.dircache.DirCacheIterator;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.treewalk.FileTreeIterator;
import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.treewalk.filter.AndTreeFilter;
import org.eclipse.jgit.treewalk.filter.NotIgnoredFilter;

/**
 * Representation of working tree in EGit ChangeSet model
 */
public class GitModelWorkingTree extends GitModelCache {

	/**
	 * @param parent
	 *            parent of working tree instance
	 * @param commit
	 *            last {@link RevCommit} in repository
	 * @throws IOException
	 */
	public GitModelWorkingTree(GitModelObject parent, RevCommit commit)
			throws IOException {
		super(parent, commit, new FileModelFactory() {
			public GitModelBlob createFileModel(
					GitModelObjectContainer modelParent, RevCommit modelCommit,
					ObjectId repoId, ObjectId cacheId, String name)
					throws IOException {
				return new GitModelWorkingFile(modelParent, modelCommit,
						repoId, name);
			}
		});
	}

	@Override
	public String getName() {
		return UIText.GitModelWorkingTree_workingTree;
	}

	@Override
	protected TreeWalk createAndConfigureTreeWalk() throws IOException {
		TreeWalk tw = createTreeWalk();
		tw.setRecursive(true);

		Repository repo = getRepository();
		tw.addTree(new DirCacheIterator(repo.readDirCache()));
		tw.addTree(new FileTreeIterator(repo));
		dirCacheIteratorNth = 0;

		NotIgnoredFilter notIgnoredFilter = new NotIgnoredFilter(1);
		tw.setFilter(AndTreeFilter.create(ANY_DIFF, notIgnoredFilter));

		return tw;
	}

}

@@ -137,11 +137,72 @@
 rg%3E%0A
+ * Copyright (C) 2011, Matthias Sohn %3Cmatthias.sohn@sap.com%3E%0A
  *%0A
-
  * A
@@ -586,77 +586,8 @@
 l;%0A%0A
-import static org.eclipse.jgit.treewalk.filter.TreeFilter.ANY_DIFF;%0A%0A
 impo
@@ -956,73 +956,17 @@
 ter.
-AndTreeFilter;%0Aimport org.eclipse.jgit.treewalk.filter.NotIgnored
+IndexDiff
 Filt
@@ -1953,24 +1953,46 @@
 sitory();%0A%09%09
+dirCacheIteratorNth = 
 tw.addTree(n
@@ -2036,16 +2036,30 @@
 ()));%0A%09%09
+int ftIndex = 
 tw.addTr
@@ -2096,160 +2096,105 @@
 ;%0A%09%09
-dirCacheIteratorNth = 0;%0A%0A%09%09NotIgnoredFilter notIgnoredFilter = new NotIgnoredFilter(1);%0A%09%09tw.setFilter(AndTreeFilter.create(ANY_DIFF, notIgnored
+IndexDiffFilter idf = new IndexDiffFilter(dirCacheIteratorNth, ftIndex, true);%0A%09%09tw.set
 Filter
-)
+(idf
 );%0A%0A

Use IndexDiffFilter to improve synchronize performance