@ -61,7 +61,6 @@ import org.eclipse.jgit.lib.FileMode;
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.Repository ;
import org.eclipse.jgit.lib.Repository ;
import org.eclipse.jgit.lib.StoredConfig ;
import org.eclipse.jgit.treewalk.AbstractTreeIterator ;
import org.eclipse.jgit.treewalk.AbstractTreeIterator ;
import org.eclipse.jgit.treewalk.CanonicalTreeParser ;
import org.eclipse.jgit.treewalk.CanonicalTreeParser ;
import org.eclipse.jgit.treewalk.EmptyTreeIterator ;
import org.eclipse.jgit.treewalk.EmptyTreeIterator ;
@ -184,9 +183,7 @@ public class DirCacheCheckout {
* /
* /
public DirCacheCheckout ( Repository repo , ObjectId headCommitTree ,
public DirCacheCheckout ( Repository repo , ObjectId headCommitTree ,
DirCache dc , ObjectId mergeCommitTree ) throws IOException {
DirCache dc , ObjectId mergeCommitTree ) throws IOException {
this ( repo , headCommitTree , dc , mergeCommitTree , new FileTreeIterator (
this ( repo , headCommitTree , dc , mergeCommitTree , new FileTreeIterator ( repo ) ) ;
repo . getWorkTree ( ) , repo . getFS ( ) ,
WorkingTreeOptions . createDefaultInstance ( ) ) ) ;
}
}
/ * *
/ * *
@ -224,9 +221,7 @@ public class DirCacheCheckout {
* /
* /
public DirCacheCheckout ( Repository repo , DirCache dc ,
public DirCacheCheckout ( Repository repo , DirCache dc ,
ObjectId mergeCommitTree ) throws IOException {
ObjectId mergeCommitTree ) throws IOException {
this ( repo , null , dc , mergeCommitTree , new FileTreeIterator (
this ( repo , null , dc , mergeCommitTree , new FileTreeIterator ( repo ) ) ;
repo . getWorkTree ( ) , repo . getFS ( ) ,
WorkingTreeOptions . createDefaultInstance ( ) ) ) ;
}
}
/ * *
/ * *
@ -311,7 +306,7 @@ public class DirCacheCheckout {
if ( m ! = null ) {
if ( m ! = null ) {
if ( i = = null | | f = = null | | ! m . idEqual ( i )
if ( i = = null | | f = = null | | ! m . idEqual ( i )
| | ( i . getDirCacheEntry ( ) ! = null & & ( f . isModified (
| | ( i . getDirCacheEntry ( ) ! = null & & ( f . isModified (
i . getDirCacheEntry ( ) , true , config_filemode ( ) ) | |
i . getDirCacheEntry ( ) , true ) | |
i . getDirCacheEntry ( ) . getStage ( ) ! = 0 ) ) ) {
i . getDirCacheEntry ( ) . getStage ( ) ! = 0 ) ) ) {
update ( m . getEntryPathString ( ) , m . getEntryObjectId ( ) ,
update ( m . getEntryPathString ( ) , m . getEntryObjectId ( ) ,
m . getEntryFileMode ( ) ) ;
m . getEntryFileMode ( ) ) ;
@ -391,7 +386,7 @@ public class DirCacheCheckout {
file . getParentFile ( ) . mkdirs ( ) ;
file . getParentFile ( ) . mkdirs ( ) ;
file . createNewFile ( ) ;
file . createNewFile ( ) ;
DirCacheEntry entry = dc . getEntry ( path ) ;
DirCacheEntry entry = dc . getEntry ( path ) ;
checkoutEntry ( repo , file , entry , config_filemode ( ) ) ;
checkoutEntry ( repo , file , entry ) ;
}
}
@ -575,7 +570,7 @@ public class DirCacheCheckout {
case 0xFFD : // 12 13 14
case 0xFFD : // 12 13 14
if ( hId . equals ( iId ) ) {
if ( hId . equals ( iId ) ) {
dce = i . getDirCacheEntry ( ) ;
dce = i . getDirCacheEntry ( ) ;
if ( f = = null | | f . isModified ( dce , true , config_filemode ( ) ) )
if ( f = = null | | f . isModified ( dce , true ) )
conflict ( name , i . getDirCacheEntry ( ) , h , m ) ;
conflict ( name , i . getDirCacheEntry ( ) , h , m ) ;
else
else
remove ( name ) ;
remove ( name ) ;
@ -641,8 +636,7 @@ public class DirCacheCheckout {
if ( m = = null | | mId . equals ( iId ) ) {
if ( m = = null | | mId . equals ( iId ) ) {
if ( m = = null & & walk . isDirectoryFileConflict ( ) ) {
if ( m = = null & & walk . isDirectoryFileConflict ( ) ) {
if ( dce ! = null
if ( dce ! = null
& & ( f = = null | | f . isModified ( dce , true ,
& & ( f = = null | | f . isModified ( dce , true ) ) )
config_filemode ( ) ) ) )
conflict ( name , i . getDirCacheEntry ( ) , h , m ) ;
conflict ( name , i . getDirCacheEntry ( ) , h , m ) ;
else
else
remove ( name ) ;
remove ( name ) ;
@ -664,7 +658,7 @@ public class DirCacheCheckout {
* /
* /
if ( hId . equals ( iId ) ) {
if ( hId . equals ( iId ) ) {
if ( f = = null | | f . isModified ( dce , true , config_filemode ( ) ) )
if ( f = = null | | f . isModified ( dce , true ) )
conflict ( name , i . getDirCacheEntry ( ) , h , m ) ;
conflict ( name , i . getDirCacheEntry ( ) , h , m ) ;
else
else
remove ( name ) ;
remove ( name ) ;
@ -674,9 +668,7 @@ public class DirCacheCheckout {
if ( ! hId . equals ( mId ) & & ! hId . equals ( iId ) & & ! mId . equals ( iId ) )
if ( ! hId . equals ( mId ) & & ! hId . equals ( iId ) & & ! mId . equals ( iId ) )
conflict ( name , i . getDirCacheEntry ( ) , h , m ) ;
conflict ( name , i . getDirCacheEntry ( ) , h , m ) ;
else if ( hId . equals ( iId ) & & ! mId . equals ( iId ) ) {
else if ( hId . equals ( iId ) & & ! mId . equals ( iId ) ) {
if ( dce ! = null
if ( dce ! = null & & ( f = = null | | f . isModified ( dce , true ) ) )
& & ( f = = null | | f . isModified ( dce , true ,
config_filemode ( ) ) ) )
conflict ( name , i . getDirCacheEntry ( ) , h , m ) ;
conflict ( name , i . getDirCacheEntry ( ) , h , m ) ;
else
else
update ( name , mId , m . getEntryFileMode ( ) ) ;
update ( name , mId , m . getEntryFileMode ( ) ) ;
@ -738,19 +730,6 @@ public class DirCacheCheckout {
}
}
}
}
private Boolean filemode ;
private boolean config_filemode ( ) {
// TODO: temporary till we can actually set parameters. We need to be
// able to change this for testing.
if ( filemode = = null ) {
StoredConfig config = repo . getConfig ( ) ;
filemode = Boolean . valueOf ( config . getBoolean ( "core" , null ,
"filemode" , true ) ) ;
}
return filemode . booleanValue ( ) ;
}
/ * *
/ * *
* If < code > true < / code > , will scan first to see if it ' s possible to check
* If < code > true < / code > , will scan first to see if it ' s possible to check
* out , otherwise throw { @link CheckoutConflictException } . If
* out , otherwise throw { @link CheckoutConflictException } . If
@ -790,8 +769,7 @@ public class DirCacheCheckout {
private boolean isModified ( String path ) throws CorruptObjectException , IOException {
private boolean isModified ( String path ) throws CorruptObjectException , IOException {
NameConflictTreeWalk tw = new NameConflictTreeWalk ( repo ) ;
NameConflictTreeWalk tw = new NameConflictTreeWalk ( repo ) ;
tw . addTree ( new DirCacheIterator ( dc ) ) ;
tw . addTree ( new DirCacheIterator ( dc ) ) ;
tw . addTree ( new FileTreeIterator ( repo . getWorkTree ( ) , repo . getFS ( ) ,
tw . addTree ( new FileTreeIterator ( repo ) ) ;
WorkingTreeOptions . createDefaultInstance ( ) ) ) ;
tw . setRecursive ( true ) ;
tw . setRecursive ( true ) ;
tw . setFilter ( PathFilter . create ( path ) ) ;
tw . setFilter ( PathFilter . create ( path ) ) ;
DirCacheIterator dcIt ;
DirCacheIterator dcIt ;
@ -801,8 +779,7 @@ public class DirCacheCheckout {
wtIt = tw . getTree ( 1 , WorkingTreeIterator . class ) ;
wtIt = tw . getTree ( 1 , WorkingTreeIterator . class ) ;
if ( dcIt = = null | | wtIt = = null )
if ( dcIt = = null | | wtIt = = null )
return true ;
return true ;
if ( wtIt . isModified ( dcIt . getDirCacheEntry ( ) , true ,
if ( wtIt . isModified ( dcIt . getDirCacheEntry ( ) , true ) ) {
config_filemode ( ) ) ) {
return true ;
return true ;
}
}
}
}
@ -824,12 +801,10 @@ public class DirCacheCheckout {
* has to exist already
* has to exist already
* @param entry
* @param entry
* the entry containing new mode and content
* the entry containing new mode and content
* @param config_filemode
* whether the mode bits should be handled at all .
* @throws IOException
* @throws IOException
* /
* /
public static void checkoutEntry ( final Repository repo , File f , DirCacheEntry entry ,
public static void checkoutEntry ( final Repository repo , File f ,
boolean config_filemode ) throws IOException {
DirCacheEntry entry ) throws IOException {
ObjectLoader ol = repo . open ( entry . getObjectId ( ) ) ;
ObjectLoader ol = repo . open ( entry . getObjectId ( ) ) ;
File parentDir = f . getParentFile ( ) ;
File parentDir = f . getParentFile ( ) ;
File tmpFile = File . createTempFile ( "._" + f . getName ( ) , null , parentDir ) ;
File tmpFile = File . createTempFile ( "._" + f . getName ( ) , null , parentDir ) ;
@ -840,7 +815,8 @@ public class DirCacheCheckout {
channel . close ( ) ;
channel . close ( ) ;
}
}
FS fs = repo . getFS ( ) ;
FS fs = repo . getFS ( ) ;
if ( config_filemode & & fs . supportsExecute ( ) ) {
WorkingTreeOptions opt = repo . getConfig ( ) . get ( WorkingTreeOptions . KEY ) ;
if ( opt . isFileMode ( ) & & fs . supportsExecute ( ) ) {
if ( FileMode . EXECUTABLE_FILE . equals ( entry . getRawMode ( ) ) ) {
if ( FileMode . EXECUTABLE_FILE . equals ( entry . getRawMode ( ) ) ) {
if ( ! fs . canExecute ( tmpFile ) )
if ( ! fs . canExecute ( tmpFile ) )
fs . setExecute ( tmpFile , true ) ;
fs . setExecute ( tmpFile , true ) ;