@ -51,6 +51,8 @@ import org.eclipse.jgit.api.errors.CheckoutConflictException;
import org.eclipse.jgit.api.errors.GitAPIException ;
import org.eclipse.jgit.api.errors.GitAPIException ;
import org.eclipse.jgit.api.errors.JGitInternalException ;
import org.eclipse.jgit.api.errors.JGitInternalException ;
import org.eclipse.jgit.dircache.DirCache ;
import org.eclipse.jgit.dircache.DirCache ;
import org.eclipse.jgit.dircache.DirCacheBuildIterator ;
import org.eclipse.jgit.dircache.DirCacheBuilder ;
import org.eclipse.jgit.dircache.DirCacheCheckout ;
import org.eclipse.jgit.dircache.DirCacheCheckout ;
import org.eclipse.jgit.dircache.DirCacheEditor ;
import org.eclipse.jgit.dircache.DirCacheEditor ;
import org.eclipse.jgit.dircache.DirCacheEditor.DeletePath ;
import org.eclipse.jgit.dircache.DirCacheEditor.DeletePath ;
@ -59,7 +61,6 @@ import org.eclipse.jgit.dircache.DirCacheEntry;
import org.eclipse.jgit.dircache.DirCacheIterator ;
import org.eclipse.jgit.dircache.DirCacheIterator ;
import org.eclipse.jgit.internal.JGitText ;
import org.eclipse.jgit.internal.JGitText ;
import org.eclipse.jgit.lib.Constants ;
import org.eclipse.jgit.lib.Constants ;
import org.eclipse.jgit.lib.FileMode ;
import org.eclipse.jgit.lib.ObjectId ;
import org.eclipse.jgit.lib.ObjectId ;
import org.eclipse.jgit.lib.Ref ;
import org.eclipse.jgit.lib.Ref ;
import org.eclipse.jgit.lib.RefUpdate ;
import org.eclipse.jgit.lib.RefUpdate ;
@ -276,44 +277,30 @@ public class ResetCommand extends GitCommand<Ref> {
private void resetIndexForPaths ( RevCommit commit ) {
private void resetIndexForPaths ( RevCommit commit ) {
DirCache dc = null ;
DirCache dc = null ;
final DirCacheEditor edit ;
try {
try {
dc = repo . lockDirCache ( ) ;
dc = repo . lockDirCache ( ) ;
edit = dc . edito r ( ) ;
DirCacheBuilder builder = dc . build er( ) ;
final TreeWalk tw = new TreeWalk ( repo ) ;
final TreeWalk tw = new TreeWalk ( repo ) ;
tw . addTree ( new DirCacheIterator ( dc ) ) ;
tw . addTree ( new DirCacheBuild Iterator ( builder ) ) ;
tw . addTree ( commit . getTree ( ) ) ;
tw . addTree ( commit . getTree ( ) ) ;
tw . setFilter ( PathFilterGroup . createFromStrings ( filepaths ) ) ;
tw . setFilter ( PathFilterGroup . createFromStrings ( filepaths ) ) ;
tw . setRecursive ( true ) ;
tw . setRecursive ( true ) ;
while ( tw . next ( ) ) {
while ( tw . next ( ) ) {
final String path = tw . getPathString ( ) ;
// DirCacheIterator dci = tw.getTree(0, DirCacheIterator.class);
final CanonicalTreeParser tree = tw . getTree ( 1 ,
final CanonicalTreeParser tree = tw . getTree ( 1 ,
CanonicalTreeParser . class ) ;
CanonicalTreeParser . class ) ;
if ( tree = = null )
// only keep file in index if it's in the commit
// file is not in the commit, remove from index
if ( tree ! = null ) {
edit . add ( new DirCacheEditor . DeletePath ( path ) ) ;
// revert index to commit
else { // revert index to commit
DirCacheEntry entry = new DirCacheEntry ( tw . getRawPath ( ) ) ;
// it seams that there is concurrent access to tree
entry . setFileMode ( tree . getEntryFileMode ( ) ) ;
// variable, therefore we need to keep references to
entry . setObjectId ( tree . getEntryObjectId ( ) ) ;
// entryFileMode and entryObjectId in local
builder . add ( entry ) ;
// variables
final FileMode entryFileMode = tree . getEntryFileMode ( ) ;
final ObjectId entryObjectId = tree . getEntryObjectId ( ) ;
edit . add ( new DirCacheEditor . PathEdit ( path ) {
@Override
public void apply ( DirCacheEntry ent ) {
ent . setFileMode ( entryFileMode ) ;
ent . setObjectId ( entryObjectId ) ;
ent . setLastModified ( 0 ) ;
}
} ) ;
}
}
}
}
edit . commit ( ) ;
builder . commit ( ) ;
} catch ( IOException e ) {
} catch ( IOException e ) {
throw new RuntimeException ( e ) ;
throw new RuntimeException ( e ) ;
} finally {
} finally {