Source:
<code>public DirCache call() throws NoFilepatternException { if (filepatterns.isEmpty()) throw new NoFilepatternException(JGitText.get().atLeastOnePatternIsRequired); checkCallable(); DirCache dc = null; try { dc = DirCache.lock(repo); ObjectWriter ow = new ObjectWriter(repo); DirCacheIterator c; DirCacheBuilder builder = dc.builder(); final TreeWalk tw = new TreeWalk(repo); tw.reset(); tw.addTree(new DirCacheBuildIterator(builder)); FileTreeIterator fileTreeIterator = new FileTreeIterator( repo.getWorkDir(), repo.getFS()); tw.addTree(fileTreeIterator); tw.setRecursive(true); tw.setFilter(PathFilterGroup.createFromStrings(filepatterns)); if (update) tw.addTree(new DirCacheIterator(dc)); <START> <END> String lastAddedFile = null; while (tw.next()) { String path = tw.getPathString(); final File file = new File(repo.getWorkDir(), path); if (!(path.equals(lastAddedFile))) { if (!(update && tw.getTree(2, DirCacheIterator.class) == null)) { FileTreeIterator f = tw.getTree(1, FileTreeIterator.class); if (f != null) { DirCacheEntry entry = new DirCacheEntry(path); entry.setLength((int)f.getEntryLength()); entry.setLastModified(f.getEntryLastModified()); entry.setFileMode(f.getEntryFileMode()); entry.setObjectId(ow.writeBlob(file)); builder.add(entry); lastAddedFile = path; } else if (!update){ c = tw.getTree(0, DirCacheIterator.class); builder.add(c.getDirCacheEntry()); } } } } builder.commit(); setCallable(false); } catch (IOException e) { throw new JGitInternalException( JGitText.get().exceptionCaughtDuringExecutionOfAddCommand, e); } finally { if (dc != null) dc.unlock(); } return dc; }</code><technical_language>do add another iterator Dircache? in Walk reuse him</technical_language>

Target:
public DirCache call() throws NoFilepatternException { if (filepatterns.isEmpty()) throw new NoFilepatternException(JGitText.get().atLeastOnePatternIsRequired); checkCallable(); DirCache dc = null; try { dc = DirCache.lock(repo); ObjectWriter ow = new ObjectWriter(repo); DirCacheIterator c; DirCacheBuilder builder = dc.builder(); final TreeWalk tw = new TreeWalk(repo); tw.reset(); tw.addTree(new DirCacheBuildIterator(builder)); FileTreeIterator fileTreeIterator = new FileTreeIterator( repo.getWorkDir(), repo.getFS()); tw.addTree(fileTreeIterator); tw.setRecursive(true); tw.setFilter(PathFilterGroup.createFromStrings(filepatterns)); String lastAddedFile = null; while (tw.next()) { String path = tw.getPathString(); final File file = new File(repo.getWorkDir(), path); if (!(path.equals(lastAddedFile))) { if (!(update && tw.getTree(0, DirCacheIterator.class) == null)) { FileTreeIterator f = tw.getTree(1, FileTreeIterator.class); if (f != null) { DirCacheEntry entry = new DirCacheEntry(path); entry.setLength((int)f.getEntryLength()); entry.setLastModified(f.getEntryLastModified()); entry.setFileMode(f.getEntryFileMode()); entry.setObjectId(ow.writeBlob(file)); builder.add(entry); lastAddedFile = path; } else if (!update){ c = tw.getTree(0, DirCacheIterator.class); builder.add(c.getDirCacheEntry()); } } } } builder.commit(); setCallable(false); } catch (IOException e) { throw new JGitInternalException( JGitText.get().exceptionCaughtDuringExecutionOfAddCommand, e); } finally { if (dc != null) dc.unlock(); } return dc; }