@ -3,41 +3,14 @@
* Copyright ( C ) 2008 , Robin Rosenberg < robin . rosenberg @dewire.com >
* Copyright ( C ) 2008 , Robin Rosenberg < robin . rosenberg @dewire.com >
* Copyright ( C ) 2008 , Roger C . Soares < rogersoares @intelinet.com.br >
* Copyright ( C ) 2008 , Roger C . Soares < rogersoares @intelinet.com.br >
* Copyright ( C ) 2006 , Shawn O . Pearce < spearce @spearce.org >
* Copyright ( C ) 2006 , Shawn O . Pearce < spearce @spearce.org >
* Copyright ( C ) 2010 , Chrisian Halstrick < christian . halstrick @sap.com > and
* Copyright ( C ) 2010 , Chrisian Halstrick < christian . halstrick @sap.com >
* other copyright owners as documented in the project ' s IP log .
* Copyright ( C ) 2019 - 2020 , Andre Bossert < andre . bossert @siemens.com >
*
*
* This program and the accompanying materials are made available under the
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v1 . 0 which accompanies this
* terms of the Eclipse Distribution License v . 1 . 0 which is available at
* distribution , is reproduced below , and is available at
* https : //www.eclipse.org/org/documents/edl-v10.php.
* http : //www.eclipse.org/org/documents/edl-v10.php
*
*
* All rights reserved .
* SPDX - License - Identifier : BSD - 3 - Clause
*
* Redistribution and use in source and binary forms , with or without
* modification , are permitted provided that the following conditions are met :
*
* - Redistributions of source code must retain the above copyright notice , this
* list of conditions and the following disclaimer .
*
* - Redistributions in binary form must reproduce the above copyright notice ,
* this list of conditions and the following disclaimer in the documentation
* and / or other materials provided with the distribution .
*
* - Neither the name of the Eclipse Foundation , Inc . nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission .
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED . IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT , INDIRECT , INCIDENTAL , SPECIAL , EXEMPLARY , OR
* CONSEQUENTIAL DAMAGES ( INCLUDING , BUT NOT LIMITED TO , PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE , DATA , OR PROFITS ; OR BUSINESS
* INTERRUPTION ) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY , WHETHER IN
* CONTRACT , STRICT LIABILITY , OR TORT ( INCLUDING NEGLIGENCE OR OTHERWISE )
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE , EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE .
* /
* /
package org.eclipse.jgit.dircache ;
package org.eclipse.jgit.dircache ;
@ -1504,29 +1477,9 @@ public class DirCacheCheckout {
File tmpFile = File . createTempFile (
File tmpFile = File . createTempFile (
"._" + name , null , parentDir ) ; //$NON-NLS-1$
"._" + name , null , parentDir ) ; //$NON-NLS-1$
EolStreamType nonNullEolStreamType ;
getContent ( repo , entry . getPathString ( ) , checkoutMetadata , ol , opt ,
if ( checkoutMetadata . eolStreamType ! = null ) {
new FileOutputStream ( tmpFile ) ) ;
nonNullEolStreamType = checkoutMetadata . eolStreamType ;
} else if ( opt . getAutoCRLF ( ) = = AutoCRLF . TRUE ) {
nonNullEolStreamType = EolStreamType . AUTO_CRLF ;
} else {
nonNullEolStreamType = EolStreamType . DIRECT ;
}
try ( OutputStream channel = EolStreamTypeUtil . wrapOutputStream (
new FileOutputStream ( tmpFile ) , nonNullEolStreamType ) ) {
if ( checkoutMetadata . smudgeFilterCommand ! = null ) {
if ( FilterCommandRegistry
. isRegistered ( checkoutMetadata . smudgeFilterCommand ) ) {
runBuiltinFilterCommand ( repo , checkoutMetadata , ol ,
channel ) ;
} else {
runExternalFilterCommand ( repo , entry , checkoutMetadata , ol ,
fs , channel ) ;
}
} else {
ol . copyTo ( channel ) ;
}
}
// The entry needs to correspond to the on-disk filesize. If the content
// The entry needs to correspond to the on-disk filesize. If the content
// was filtered (either by autocrlf handling or smudge filters) ask the
// was filtered (either by autocrlf handling or smudge filters) ask the
// filesystem again for the length. Otherwise the objectloader knows the
// filesystem again for the length. Otherwise the objectloader knows the
@ -1565,11 +1518,69 @@ public class DirCacheCheckout {
entry . setLastModified ( fs . lastModifiedInstant ( f ) ) ;
entry . setLastModified ( fs . lastModifiedInstant ( f ) ) ;
}
}
/ * *
* Return filtered content for a specific object ( blob ) . EOL handling and
* smudge - filter handling are applied in the same way as it would be done
* during a checkout .
*
* @param repo
* the repository
* @param path
* the path used to determine the correct filters for the object
* @param checkoutMetadata
* containing
* < ul >
* < li > smudgeFilterCommand to be run for smudging the object < / li >
* < li > eolStreamType used for stream conversion ( can be
* null ) < / li >
* < / ul >
* @param ol
* the object loader to read raw content of the object
* @param opt
* the working tree options where only ' core . autocrlf ' is used
* for EOL handling if ' checkoutMetadata . eolStreamType ' is not
* valid
* @param os
* the output stream the filtered content is written to . The
* caller is responsible to close the stream .
* @throws IOException
*
* @since 5 . 7
* /
public static void getContent ( Repository repo , String path ,
CheckoutMetadata checkoutMetadata , ObjectLoader ol ,
WorkingTreeOptions opt , OutputStream os )
throws IOException {
EolStreamType nonNullEolStreamType ;
if ( checkoutMetadata . eolStreamType ! = null ) {
nonNullEolStreamType = checkoutMetadata . eolStreamType ;
} else if ( opt . getAutoCRLF ( ) = = AutoCRLF . TRUE ) {
nonNullEolStreamType = EolStreamType . AUTO_CRLF ;
} else {
nonNullEolStreamType = EolStreamType . DIRECT ;
}
try ( OutputStream channel = EolStreamTypeUtil . wrapOutputStream (
os , nonNullEolStreamType ) ) {
if ( checkoutMetadata . smudgeFilterCommand ! = null ) {
if ( FilterCommandRegistry
. isRegistered ( checkoutMetadata . smudgeFilterCommand ) ) {
runBuiltinFilterCommand ( repo , checkoutMetadata , ol ,
channel ) ;
} else {
runExternalFilterCommand ( repo , path , checkoutMetadata , ol ,
channel ) ;
}
} else {
ol . copyTo ( channel ) ;
}
}
}
// Run an external filter command
// Run an external filter command
private static void runExternalFilterCommand ( Repository repo ,
private static void runExternalFilterCommand ( Repository repo , String path ,
DirCacheEntry entry ,
CheckoutMetadata checkoutMetadata , ObjectLoader ol ,
CheckoutMetadata checkoutMetadata , ObjectLoader ol , FS fs ,
OutputStream channel ) throws IOException {
OutputStream channel ) throws IOException {
FS fs = repo . getFS ( ) ;
ProcessBuilder filterProcessBuilder = fs . runInShell (
ProcessBuilder filterProcessBuilder = fs . runInShell (
checkoutMetadata . smudgeFilterCommand , new String [ 0 ] ) ;
checkoutMetadata . smudgeFilterCommand , new String [ 0 ] ) ;
filterProcessBuilder . directory ( repo . getWorkTree ( ) ) ;
filterProcessBuilder . directory ( repo . getWorkTree ( ) ) ;
@ -1588,12 +1599,12 @@ public class DirCacheCheckout {
} catch ( IOException | InterruptedException e ) {
} catch ( IOException | InterruptedException e ) {
throw new IOException ( new FilterFailedException ( e ,
throw new IOException ( new FilterFailedException ( e ,
checkoutMetadata . smudgeFilterCommand ,
checkoutMetadata . smudgeFilterCommand ,
entry . getPa thString ( ) ) ) ;
pa th) ) ;
}
}
if ( rc ! = 0 ) {
if ( rc ! = 0 ) {
throw new IOException ( new FilterFailedException ( rc ,
throw new IOException ( new FilterFailedException ( rc ,
checkoutMetadata . smudgeFilterCommand ,
checkoutMetadata . smudgeFilterCommand ,
entry . getPa thString ( ) ,
pa th,
result . getStdout ( ) . toByteArray ( MAX_EXCEPTION_TEXT_SIZE ) ,
result . getStdout ( ) . toByteArray ( MAX_EXCEPTION_TEXT_SIZE ) ,
RawParseUtils . decode ( result . getStderr ( )
RawParseUtils . decode ( result . getStderr ( )
. toByteArray ( MAX_EXCEPTION_TEXT_SIZE ) ) ) ) ;
. toByteArray ( MAX_EXCEPTION_TEXT_SIZE ) ) ) ) ;