@ -56,6 +56,7 @@ import java.util.Iterator;
import java.util.List ;
import java.util.List ;
import java.util.Map ;
import java.util.Map ;
import org.eclipse.jgit.api.errors.CanceledException ;
import org.eclipse.jgit.api.errors.FilterFailedException ;
import org.eclipse.jgit.api.errors.FilterFailedException ;
import org.eclipse.jgit.attributes.FilterCommand ;
import org.eclipse.jgit.attributes.FilterCommand ;
import org.eclipse.jgit.attributes.FilterCommandRegistry ;
import org.eclipse.jgit.attributes.FilterCommandRegistry ;
@ -76,6 +77,7 @@ import org.eclipse.jgit.lib.ObjectChecker;
import org.eclipse.jgit.lib.ObjectId ;
import org.eclipse.jgit.lib.ObjectId ;
import org.eclipse.jgit.lib.ObjectLoader ;
import org.eclipse.jgit.lib.ObjectLoader ;
import org.eclipse.jgit.lib.ObjectReader ;
import org.eclipse.jgit.lib.ObjectReader ;
import org.eclipse.jgit.lib.ProgressMonitor ;
import org.eclipse.jgit.lib.Repository ;
import org.eclipse.jgit.lib.Repository ;
import org.eclipse.jgit.treewalk.AbstractTreeIterator ;
import org.eclipse.jgit.treewalk.AbstractTreeIterator ;
import org.eclipse.jgit.treewalk.CanonicalTreeParser ;
import org.eclipse.jgit.treewalk.CanonicalTreeParser ;
@ -158,6 +160,8 @@ public class DirCacheCheckout {
private boolean performingCheckout ;
private boolean performingCheckout ;
private ProgressMonitor monitor = NullProgressMonitor . INSTANCE ;
/ * *
/ * *
* Get list of updated paths and smudgeFilterCommands
* Get list of updated paths and smudgeFilterCommands
*
*
@ -287,6 +291,18 @@ public class DirCacheCheckout {
this ( repo , null , dc , mergeCommitTree , new FileTreeIterator ( repo ) ) ;
this ( repo , null , dc , mergeCommitTree , new FileTreeIterator ( repo ) ) ;
}
}
/ * *
* Set a progress monitor which can be passed to built - in filter commands ,
* providing progress information for long running tasks .
*
* @param monitor
* the { @link ProgressMonitor }
* @since 4 . 11
* /
public void setProgressMonitor ( ProgressMonitor monitor ) {
this . monitor = monitor ! = null ? monitor : NullProgressMonitor . INSTANCE ;
}
/ * *
/ * *
* Scan head , index and merge tree . Used during normal checkout or merge
* Scan head , index and merge tree . Used during normal checkout or merge
* operations .
* operations .
@ -465,6 +481,10 @@ public class DirCacheCheckout {
public boolean checkout ( ) throws IOException {
public boolean checkout ( ) throws IOException {
try {
try {
return doCheckout ( ) ;
return doCheckout ( ) ;
} catch ( CanceledException ce ) {
// should actually be propagated, but this would change a LOT of
// APIs
throw new IOException ( ce ) ;
} finally {
} finally {
try {
try {
dc . unlock ( ) ;
dc . unlock ( ) ;
@ -482,7 +502,7 @@ public class DirCacheCheckout {
private boolean doCheckout ( ) throws CorruptObjectException , IOException ,
private boolean doCheckout ( ) throws CorruptObjectException , IOException ,
MissingObjectException , IncorrectObjectTypeException ,
MissingObjectException , IncorrectObjectTypeException ,
CheckoutConflictException , IndexWriteException {
CheckoutConflictException , IndexWriteException , CanceledException {
toBeDeleted . clear ( ) ;
toBeDeleted . clear ( ) ;
try ( ObjectReader objectReader = repo . getObjectDatabase ( ) . newReader ( ) ) {
try ( ObjectReader objectReader = repo . getObjectDatabase ( ) . newReader ( ) ) {
if ( headCommitTree ! = null )
if ( headCommitTree ! = null )
@ -500,6 +520,10 @@ public class DirCacheCheckout {
// update our index
// update our index
builder . finish ( ) ;
builder . finish ( ) ;
// init progress reporting
int numTotal = removed . size ( ) + updated . size ( ) ;
monitor . beginTask ( JGitText . get ( ) . checkingOutFiles , numTotal ) ;
performingCheckout = true ;
performingCheckout = true ;
File file = null ;
File file = null ;
String last = null ;
String last = null ;
@ -525,6 +549,12 @@ public class DirCacheCheckout {
removeEmptyParents ( new File ( repo . getWorkTree ( ) , last ) ) ;
removeEmptyParents ( new File ( repo . getWorkTree ( ) , last ) ) ;
last = r ;
last = r ;
}
}
monitor . update ( 1 ) ;
if ( monitor . isCancelled ( ) ) {
throw new CanceledException ( MessageFormat . format (
JGitText . get ( ) . operationCanceled ,
JGitText . get ( ) . checkingOutFiles ) ) ;
}
}
}
if ( file ! = null ) {
if ( file ! = null ) {
removeEmptyParents ( file ) ;
removeEmptyParents ( file ) ;
@ -544,6 +574,13 @@ public class DirCacheCheckout {
checkoutEntry ( repo , entry , objectReader , false , meta ) ;
checkoutEntry ( repo , entry , objectReader , false , meta ) ;
}
}
e = null ;
e = null ;
monitor . update ( 1 ) ;
if ( monitor . isCancelled ( ) ) {
throw new CanceledException ( MessageFormat . format (
JGitText . get ( ) . operationCanceled ,
JGitText . get ( ) . checkingOutFiles ) ) ;
}
}
}
} catch ( Exception ex ) {
} catch ( Exception ex ) {
// We didn't actually modify the current entry nor any that
// We didn't actually modify the current entry nor any that
@ -557,6 +594,8 @@ public class DirCacheCheckout {
}
}
throw ex ;
throw ex ;
}
}
monitor . endTask ( ) ;
// commit the index builder - a new index is persisted
// commit the index builder - a new index is persisted
if ( ! builder . commit ( ) )
if ( ! builder . commit ( ) )
throw new IndexWriteException ( ) ;
throw new IndexWriteException ( ) ;