Top Description Inners Fields Constructors Methods
org.eclipse.jgit.dircache

public Class DirCacheCheckout

extends Object
Class Inheritance
Static Imports
org.eclipse.jgit.treewalk.TreeWalk.OperationType.CHECKOUT_OP

This class handles checking out one or two trees merging with the index.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
DirCacheCheckout.CheckoutMetadata

Metadata used in checkout process

public static interface
DirCacheCheckout.StreamSupplier

Something that can supply an InputStream.

Field Summary

Modifier and TypeField and Description
private DirCacheBuilder
private Checkout
private ArrayList<String>
private DirCache
private Set<String>
private boolean
private boolean
private ObjectId
private boolean
private ArrayList<String>
private static final Logger
private static final int
private ObjectId
private ProgressMonitor
private boolean
private TreeSet<String>
private Repository
private ArrayList<String>
private Map<String, DirCacheCheckout.CheckoutMetadata>
private NameConflictTreeWalk
private WorkingTreeIterator

Constructor Summary

AccessConstructor and Description
public
DirCacheCheckout(Repository
the repository in which we do the checkout
repo
,
ObjectId
the id of the tree of the head commit
headCommitTree
,
DirCache
the (already locked) Dircache for this repo
dc
,
ObjectId
the id of the tree we want to fast-forward to
mergeCommitTree
,
WorkingTreeIterator
an iterator over the repositories Working Tree
workingTree
)

Constructs a DirCacheCeckout for merging and checking out two trees (HEAD and mergeCommitTree) and the index.

public
DirCacheCheckout(Repository
the repository in which we do the checkout
repo
,
ObjectId
the id of the tree of the head commit
headCommitTree
,
DirCache
the (already locked) Dircache for this repo
dc
,
ObjectId
the id of the tree we want to fast-forward to
mergeCommitTree
)

Constructs a DirCacheCeckout for merging and checking out two trees (HEAD and mergeCommitTree) and the index.

public
DirCacheCheckout(Repository
the repository in which we do the checkout
repo
,
DirCache
the (already locked) Dircache for this repo
dc
,
ObjectId
the id of the tree we want to fast-forward to
mergeCommitTree
,
WorkingTreeIterator
an iterator over the repositories Working Tree
workingTree
)

Constructs a DirCacheCeckout for checking out one tree, merging with the index.

public
DirCacheCheckout(Repository
the repository in which we do the checkout
repo
,
DirCache
the (already locked) Dircache for this repo
dc
,
ObjectId
the id of the tree of the
mergeCommitTree
)

Constructs a DirCacheCeckout for checking out one tree, merging with the index.

Method Summary

Modifier and TypeMethod and Description
private int
public boolean

Returns:

false if this method could not delete all the files which should be deleted (e.g. because one of the files was locked). In this case getToBeDeleted() lists the files which should be tried to be deleted outside of this method. Although false is returned the checkout was successful and the working tree was updated for all other files. true is returned when no such problem occurred
checkout
()

Execute this checkout.

private static void
private static void
private void
cleanUpConflicts()

This method implements how to handle conflicts when failOnConflict is false

private void
conflict(String
the path of the conflicting entry
path
,
DirCacheEntry
the previous index entry
e
,
AbstractTreeIterator
the first tree you want to merge (the HEAD)
h
,
AbstractTreeIterator
the second tree you want to merge
m
)

A conflict is detected - add the three different stages to the index

private boolean
private boolean

Returns:

true if FileModes and ObjectIds are equal. false otherwise
equalIdAndMode
(ObjectId
id of first object
id1
,
FileMode
mode of first object
mode1
,
ObjectId
id of second object
id2
,
FileMode
mode of second object
mode2
)

Compares whether two pairs of ObjectId and FileMode are equal.

public List<String>

Returns:

a list of conflicts created by this checkout
getConflicts
()

Get a list of conflicts created by this checkout

public static void
getContent(Repository
the repository
repo
,
String
the path used to determine the correct filters for the object
path
,
DirCacheCheckout.CheckoutMetadata
containing
  • smudgeFilterCommand to be run for smudging the object
  • eolStreamType used for stream conversion (can be null)
checkoutMetadata
,
ObjectLoader
the object loader to read raw content of the object
ol
,
WorkingTreeOptions
the working tree options where only 'core.autocrlf' is used for EOL handling if 'checkoutMetadata.eolStreamType' is not valid
opt
,
OutputStream
the output stream the filtered content is written to. The caller is responsible to close the stream.
os
)

Return filtered content for a specific object (blob).

public static void
getContent(Repository
the repository
repo
,
String
the path used to determine the correct filters for the object
path
,
DirCacheCheckout.CheckoutMetadata
containing
  • smudgeFilterCommand to be run for smudging the object
  • eolStreamType used for stream conversion (can be null)
checkoutMetadata
,
DirCacheCheckout.StreamSupplier
A supplier for the raw content of the object. Each call should yield a fresh stream of the same object.
inputStream
,
WorkingTreeOptions
the working tree options where only 'core.autocrlf' is used for EOL handling if 'checkoutMetadata.eolStreamType' is not valid
opt
,
OutputStream
the output stream the filtered content is written to. The caller is responsible to close the stream.
os
)

Return filtered content for blob contents.

public List<String>

Returns:

a list of all files removed by this checkout
getRemoved
()

Get list of all files removed by this checkout

public List<String>

Returns:

a list of paths (relative to the start of the working tree) of files which couldn't be deleted during last call to checkout() . checkout() detected that these files should be deleted but the deletion in the filesystem failed (e.g. because a file was locked). To have a consistent state of the working tree these files have to be deleted by the callers of org.eclipse.jgit.dircache.DirCacheCheckout.
getToBeDeleted
()

Get list of paths of files which couldn't be deleted during last call to checkout()

public Map<String, DirCacheCheckout.CheckoutMetadata>

Returns:

a list of updated paths and smudgeFilterCommands
getUpdated
()

Get list of updated paths and smudgeFilterCommands

private static boolean
private boolean
isModified_IndexTree(String path, ObjectId iId, FileMode iMode, ObjectId tId, FileMode tMode, ObjectId rootTree)

private boolean

Returns:

true if the subtrees differ
isModifiedSubtree_IndexTree
(String
given path
path
,
ObjectId
the tree to compare
tree
)

Checks whether the subtree starting at a given path differs between Index and some tree.

private boolean

Returns:

true if the subtrees differ
isModifiedSubtree_IndexWorkingtree
(String
given subtree path
path
)

Checks whether the subtree starting at a given path differs between Index and workingtree.

private static boolean
private void
public void
prescanOneTree()

Scan index and merge tree (no HEAD).

public void
preScanTwoTrees()

Scan head, index and merge tree.

pack-priv void
processEntry(CanonicalTreeParser
the tree to merge
m
,
DirCacheBuildIterator
the index
i
,
WorkingTreeIterator
the working tree
f
)

Processing an entry in the context of prescanOneTree() when only one tree is given

pack-priv void
processEntry(CanonicalTreeParser
the entry for the head
h
,
CanonicalTreeParser
the entry for the merge
m
,
DirCacheBuildIterator
the entry for the index
i
,
WorkingTreeIterator
the file in the working tree
f
)

Here the main work is done.

private void
remove(String path)

private void
private static void
private static void
public void
setFailOnConflict(boolean
a boolean.
failOnConflict
)

If true, will scan first to see if it's possible to check out, otherwise throw org.eclipse.jgit.errors.CheckoutConflictException.

public void
setForce(boolean
a boolean.
force
)

If true, dirty worktree files may be overridden.

public void
setProgressMonitor(ProgressMonitor monitor)

Set a progress monitor which can be passed to built-in filter commands, providing progress information for long running tasks.

private void
private void
update(int index, String path, ObjectId mId, FileMode mode)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

builderback to summary
private DirCacheBuilder builder
checkoutback to summary
private Checkout checkout
conflictsback to summary
private ArrayList<String> conflicts
dcback to summary
private DirCache dc
existingback to summary
private Set<String> existing
failOnConflictback to summary
private boolean failOnConflict
forceback to summary
private boolean force
headCommitTreeback to summary
private ObjectId headCommitTree
initialCheckoutback to summary
private boolean initialCheckout
keptback to summary
private ArrayList<String> kept
LOGback to summary
private static final Logger LOG
MAX_EXCEPTION_TEXT_SIZEback to summary
private static final int MAX_EXCEPTION_TEXT_SIZE
mergeCommitTreeback to summary
private ObjectId mergeCommitTree
monitorback to summary
private ProgressMonitor monitor
performingCheckoutback to summary
private boolean performingCheckout
removedback to summary
private TreeSet<String> removed
repoback to summary
private Repository repo
toBeDeletedback to summary
private ArrayList<String> toBeDeleted
updatedback to summary
private Map<String, DirCacheCheckout.CheckoutMetadata> updated
walkback to summary
private NameConflictTreeWalk walk
workingTreeback to summary
private WorkingTreeIterator workingTree

Constructor Detail

DirCacheCheckoutback to summary
public DirCacheCheckout(Repository repo, ObjectId headCommitTree, DirCache dc, ObjectId mergeCommitTree, WorkingTreeIterator workingTree) throws IOException

Constructs a DirCacheCeckout for merging and checking out two trees (HEAD and mergeCommitTree) and the index.

Parameters
repo:Repository

the repository in which we do the checkout

headCommitTree:ObjectId

the id of the tree of the head commit

dc:DirCache

the (already locked) Dircache for this repo

mergeCommitTree:ObjectId

the id of the tree we want to fast-forward to

workingTree:WorkingTreeIterator

an iterator over the repositories Working Tree

Exceptions
IOException:
if an IO error occurred
DirCacheCheckoutback to summary
public DirCacheCheckout(Repository repo, ObjectId headCommitTree, DirCache dc, ObjectId mergeCommitTree) throws IOException

Constructs a DirCacheCeckout for merging and checking out two trees (HEAD and mergeCommitTree) and the index. As iterator over the working tree this constructor creates a standard org.eclipse.jgit.treewalk.FileTreeIterator

Parameters
repo:Repository

the repository in which we do the checkout

headCommitTree:ObjectId

the id of the tree of the head commit

dc:DirCache

the (already locked) Dircache for this repo

mergeCommitTree:ObjectId

the id of the tree we want to fast-forward to

Exceptions
IOException:
if an IO error occurred
DirCacheCheckoutback to summary
public DirCacheCheckout(Repository repo, DirCache dc, ObjectId mergeCommitTree, WorkingTreeIterator workingTree) throws IOException

Constructs a DirCacheCeckout for checking out one tree, merging with the index.

Parameters
repo:Repository

the repository in which we do the checkout

dc:DirCache

the (already locked) Dircache for this repo

mergeCommitTree:ObjectId

the id of the tree we want to fast-forward to

workingTree:WorkingTreeIterator

an iterator over the repositories Working Tree

Exceptions
IOException:
if an IO error occurred
DirCacheCheckoutback to summary
public DirCacheCheckout(Repository repo, DirCache dc, ObjectId mergeCommitTree) throws IOException

Constructs a DirCacheCeckout for checking out one tree, merging with the index. As iterator over the working tree this constructor creates a standard org.eclipse.jgit.treewalk.FileTreeIterator

Parameters
repo:Repository

the repository in which we do the checkout

dc:DirCache

the (already locked) Dircache for this repo

mergeCommitTree:ObjectId

the id of the tree of the

Exceptions
IOException:
if an IO error occurred

Method Detail

addTreeback to summary
private int addTree(TreeWalk tw, ObjectId id) throws MissingObjectException, IncorrectObjectTypeException, IOException
checkoutback to summary
public boolean checkout() throws IOException

Execute this checkout. A org.eclipse.jgit.events.WorkingTreeModifiedEvent is fired if the working tree was modified; even if the checkout fails.

Returns:boolean

false if this method could not delete all the files which should be deleted (e.g. because one of the files was locked). In this case getToBeDeleted() lists the files which should be tried to be deleted outside of this method. Although false is returned the checkout was successful and the working tree was updated for all other files. true is returned when no such problem occurred

Exceptions
IOException:
if an IO error occurred
checkValidPathback to summary
private static void checkValidPath(CanonicalTreeParser t) throws InvalidPathException
Annotations
@SuppressWarnings:deprecation
checkValidPathSegmentback to summary
private static void checkValidPathSegment(ObjectChecker chk, CanonicalTreeParser t) throws InvalidPathException
cleanUpConflictsback to summary
private void cleanUpConflicts() throws CheckoutConflictException

This method implements how to handle conflicts when failOnConflict is false

Exceptions
CheckoutConflictException:
if a conflict occurred during merge checkout
conflictback to summary
private void conflict(String path, DirCacheEntry e, AbstractTreeIterator h, AbstractTreeIterator m)

A conflict is detected - add the three different stages to the index

Parameters
path:String

the path of the conflicting entry

e:DirCacheEntry

the previous index entry

h:AbstractTreeIterator

the first tree you want to merge (the HEAD)

m:AbstractTreeIterator

the second tree you want to merge

doCheckoutback to summary
private boolean doCheckout() throws CorruptObjectException, IOException, MissingObjectException, IncorrectObjectTypeException, CheckoutConflictException, IndexWriteException, CanceledException
equalIdAndModeback to summary
private boolean equalIdAndMode(ObjectId id1, FileMode mode1, ObjectId id2, FileMode mode2)

Compares whether two pairs of ObjectId and FileMode are equal.

Parameters
id1:ObjectId

id of first object

mode1:FileMode

mode of first object

id2:ObjectId

id of second object

mode2:FileMode

mode of second object

Returns:boolean

true if FileModes and ObjectIds are equal. false otherwise

getConflictsback to summary
public List<String> getConflicts()

Get a list of conflicts created by this checkout

Returns:List<String>

a list of conflicts created by this checkout

getContentback to summary
public static void getContent(Repository repo, String path, DirCacheCheckout.CheckoutMetadata checkoutMetadata, ObjectLoader ol, WorkingTreeOptions opt, OutputStream os) throws IOException

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.

Parameters
repo:Repository

the repository

path:String

the path used to determine the correct filters for the object

checkoutMetadata:DirCacheCheckout.CheckoutMetadata

containing

  • smudgeFilterCommand to be run for smudging the object
  • eolStreamType used for stream conversion (can be null)
ol:ObjectLoader

the object loader to read raw content of the object

opt:WorkingTreeOptions

the working tree options where only 'core.autocrlf' is used for EOL handling if 'checkoutMetadata.eolStreamType' is not valid

os:OutputStream

the output stream the filtered content is written to. The caller is responsible to close the stream.

Exceptions
IOException:
if an IO error occurred
Since
5.7
getContentback to summary
public static void getContent(Repository repo, String path, DirCacheCheckout.CheckoutMetadata checkoutMetadata, DirCacheCheckout.StreamSupplier inputStream, WorkingTreeOptions opt, OutputStream os) throws IOException

Return filtered content for blob contents. EOL handling and smudge-filter handling are applied in the same way as it would be done during a checkout.

Parameters
repo:Repository

the repository

path:String

the path used to determine the correct filters for the object

checkoutMetadata:DirCacheCheckout.CheckoutMetadata

containing

  • smudgeFilterCommand to be run for smudging the object
  • eolStreamType used for stream conversion (can be null)
inputStream:DirCacheCheckout.StreamSupplier

A supplier for the raw content of the object. Each call should yield a fresh stream of the same object.

opt:WorkingTreeOptions

the working tree options where only 'core.autocrlf' is used for EOL handling if 'checkoutMetadata.eolStreamType' is not valid

os:OutputStream

the output stream the filtered content is written to. The caller is responsible to close the stream.

Exceptions
IOException:
if an IO error occurred
Since
6.3
getRemovedback to summary
public List<String> getRemoved()

Get list of all files removed by this checkout

Returns:List<String>

a list of all files removed by this checkout

getToBeDeletedback to summary
public List<String> getToBeDeleted()

Get list of paths of files which couldn't be deleted during last call to checkout()

Returns:List<String>

a list of paths (relative to the start of the working tree) of files which couldn't be deleted during last call to checkout() . checkout() detected that these files should be deleted but the deletion in the filesystem failed (e.g. because a file was locked). To have a consistent state of the working tree these files have to be deleted by the callers of org.eclipse.jgit.dircache.DirCacheCheckout.

getUpdatedback to summary
public Map<String, DirCacheCheckout.CheckoutMetadata> getUpdated()

Get list of updated paths and smudgeFilterCommands

Returns:Map<String, DirCacheCheckout.CheckoutMetadata>

a list of updated paths and smudgeFilterCommands

idEqualback to summary
private static boolean idEqual(AbstractTreeIterator a, AbstractTreeIterator b)
isModified_IndexTreeback to summary
private boolean isModified_IndexTree(String path, ObjectId iId, FileMode iMode, ObjectId tId, FileMode tMode, ObjectId rootTree) throws CorruptObjectException, IOException
isModifiedSubtree_IndexTreeback to summary
private boolean isModifiedSubtree_IndexTree(String path, ObjectId tree) throws CorruptObjectException, IOException

Checks whether the subtree starting at a given path differs between Index and some tree.

Parameters
path:String

given path

tree:ObjectId

the tree to compare

Returns:boolean

true if the subtrees differ

Exceptions
CorruptObjectException:
if a corrupt object was found
IOException:
if an IO error occurred
isModifiedSubtree_IndexWorkingtreeback to summary
private boolean isModifiedSubtree_IndexWorkingtree(String path) throws CorruptObjectException, IOException

Checks whether the subtree starting at a given path differs between Index and workingtree.

Parameters
path:String

given subtree path

Returns:boolean

true if the subtrees differ

Exceptions
CorruptObjectException:
if a corrupt object was found
IOException:
if an IO error occurred
isSamePrefixback to summary
private static boolean isSamePrefix(String a, String b)
keepback to summary
private void keep(String path, DirCacheEntry e, WorkingTreeIterator f) throws IOException
prescanOneTreeback to summary
public void prescanOneTree() throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException

Scan index and merge tree (no HEAD). Used e.g. for initial checkout when there is no head yet.

Exceptions
MissingObjectException:
if an object was found missing
IncorrectObjectTypeException:
if an object didn't have the expected type
CorruptObjectException:
if an object is corrupt
IOException:
if an IO error occurred
preScanTwoTreesback to summary
public void preScanTwoTrees() throws CorruptObjectException, IOException

Scan head, index and merge tree. Used during normal checkout or merge operations.

Exceptions
CorruptObjectException:
if a corrupt object was found
IOException:
if an IO error occurred
processEntryback to summary
pack-priv void processEntry(CanonicalTreeParser m, DirCacheBuildIterator i, WorkingTreeIterator f) throws IOException

Processing an entry in the context of prescanOneTree() when only one tree is given

Parameters
m:CanonicalTreeParser

the tree to merge

i:DirCacheBuildIterator

the index

f:WorkingTreeIterator

the working tree

Exceptions
IOException:
if an IO error occurred
processEntryback to summary
pack-priv void processEntry(CanonicalTreeParser h, CanonicalTreeParser m, DirCacheBuildIterator i, WorkingTreeIterator f) throws IOException

Here the main work is done. This method is called for each existing path in head, index and merge. This method decides what to do with the corresponding index entry: keep it, update it, remove it or mark a conflict.

Parameters
h:CanonicalTreeParser

the entry for the head

m:CanonicalTreeParser

the entry for the merge

i:DirCacheBuildIterator

the entry for the index

f:WorkingTreeIterator

the file in the working tree

Exceptions
IOException:
if an IO error occurred
removeback to summary
private void remove(String path)
removeEmptyParentsback to summary
private void removeEmptyParents(File f)
runBuiltinFilterCommandback to summary
private static void runBuiltinFilterCommand(Repository repo, DirCacheCheckout.CheckoutMetadata checkoutMetadata, DirCacheCheckout.StreamSupplier inputStream, OutputStream channel) throws MissingObjectException, IOException
runExternalFilterCommandback to summary
private static void runExternalFilterCommand(Repository repo, String path, DirCacheCheckout.CheckoutMetadata checkoutMetadata, DirCacheCheckout.StreamSupplier inputStream, OutputStream channel) throws IOException
setFailOnConflictback to summary
public void setFailOnConflict(boolean failOnConflict)

If true, will scan first to see if it's possible to check out, otherwise throw org.eclipse.jgit.errors.CheckoutConflictException. If false, it will silently deal with the problem.

Parameters
failOnConflict:boolean

a boolean.

setForceback to summary
public void setForce(boolean force)

If true, dirty worktree files may be overridden. If false dirty worktree files will not be overridden in order not to delete unsaved content. This corresponds to native git's 'git checkout -f' option. By default this option is set to false.

Parameters
force:boolean

a boolean.

Since
5.3
setProgressMonitorback to summary
public void setProgressMonitor(ProgressMonitor monitor)

Set a progress monitor which can be passed to built-in filter commands, providing progress information for long running tasks.

Parameters
monitor:ProgressMonitor

the ProgressMonitor

Since
4.11
updateback to summary
private void update(CanonicalTreeParser tree) throws IOException
updateback to summary
private void update(int index, String path, ObjectId mId, FileMode mode) throws IOException
org.eclipse.jgit.dircache back to summary

public Class DirCacheCheckout.CheckoutMetadata

extends Object
Class Inheritance

Metadata used in checkout process
Since
4.3

Field Summary

Modifier and TypeField and Description
pack-priv static DirCacheCheckout.CheckoutMetadata
public final CoreConfig.EolStreamType
eolStreamType

git attributes

public final String
smudgeFilterCommand

filter command to apply

Constructor Summary

AccessConstructor and Description
public
CheckoutMetadata(CoreConfig.EolStreamType
how to convert EOL characters during stream conversion
eolStreamType
,
String
command used as smudge filter during checkout
smudgeFilterCommand
)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

EMPTYback to summary
pack-priv static DirCacheCheckout.CheckoutMetadata EMPTY
eolStreamTypeback to summary
public final CoreConfig.EolStreamType eolStreamType

git attributes

smudgeFilterCommandback to summary
public final String smudgeFilterCommand

filter command to apply

Constructor Detail

CheckoutMetadataback to summary
public CheckoutMetadata(CoreConfig.EolStreamType eolStreamType, String smudgeFilterCommand)
Parameters
eolStreamType:CoreConfig.EolStreamType

how to convert EOL characters during stream conversion

smudgeFilterCommand:String

command used as smudge filter during checkout

org.eclipse.jgit.dircache back to summary

public Interface DirCacheCheckout.StreamSupplier


Something that can supply an InputStream.
Since
6.3

Method Summary

Modifier and TypeMethod and Description
public InputStream

Returns:

the loaded stream
load
()

Loads the input stream.

Method Detail

loadback to summary
public InputStream load() throws IOException

Loads the input stream.

Returns:InputStream

the loaded stream

Exceptions
IOException:
if any reading error occurs