Class DirCacheCheckout
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Metadata used in checkout process -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate DirCacheBuilder
private Checkout
private DirCache
private boolean
private boolean
private ObjectId
private boolean
private static final org.slf4j.Logger
private static final int
private ObjectId
private ProgressMonitor
private boolean
private Repository
private NameConflictTreeWalk
private WorkingTreeIterator
-
Constructor Summary
ConstructorsConstructorDescriptionDirCacheCheckout
(Repository repo, DirCache dc, ObjectId mergeCommitTree) Constructs a DirCacheCeckout for checking out one tree, merging with the index.DirCacheCheckout
(Repository repo, DirCache dc, ObjectId mergeCommitTree, WorkingTreeIterator workingTree) Constructs a DirCacheCeckout for checking out one tree, merging with the index.DirCacheCheckout
(Repository repo, ObjectId headCommitTree, DirCache dc, ObjectId mergeCommitTree) Constructs a DirCacheCeckout for merging and checking out two trees (HEAD and mergeCommitTree) and the index.DirCacheCheckout
(Repository repo, ObjectId headCommitTree, DirCache dc, ObjectId mergeCommitTree, WorkingTreeIterator workingTree) Constructs a DirCacheCeckout for merging and checking out two trees (HEAD and mergeCommitTree) and the index. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
boolean
checkout()
Execute this checkout.static void
checkoutEntry
(Repository repo, DirCacheEntry entry, ObjectReader or) Deprecated.static void
checkoutEntry
(Repository repo, DirCacheEntry entry, ObjectReader or, boolean deleteRecursive, DirCacheCheckout.CheckoutMetadata checkoutMetadata) Updates the file in the working tree with content and mode from an entry in the index.private static void
private static void
private void
This method implements how to handle conflicts whenfailOnConflict
is falseprivate void
conflict
(String path, DirCacheEntry e, AbstractTreeIterator h, AbstractTreeIterator m) A conflict is detected - add the three different stages to the indexprivate boolean
private boolean
equalIdAndMode
(ObjectId id1, FileMode mode1, ObjectId id2, FileMode mode2) Compares whether two pairs of ObjectId and FileMode are equal.Get a list of conflicts created by this checkoutstatic void
getContent
(Repository repo, String path, DirCacheCheckout.CheckoutMetadata checkoutMetadata, ObjectLoader ol, WorkingTreeOptions opt, OutputStream os) Return filtered content for a specific object (blob).Get list of all files removed by this checkoutGet list of paths of files which couldn't be deleted during last call tocheckout()
Get list of updated paths and smudgeFilterCommandsprivate static boolean
private boolean
isModified_IndexTree
(String path, ObjectId iId, FileMode iMode, ObjectId tId, FileMode tMode, ObjectId rootTree) private boolean
isModifiedSubtree_IndexTree
(String path, ObjectId tree) Checks whether the subtree starting at a given path differs between Index and some tree.private boolean
Checks whether the subtree starting at a given path differs between Index and workingtree.private static boolean
isSamePrefix
(String a, String b) private void
keep
(String path, DirCacheEntry e, WorkingTreeIterator f) void
Scan index and merge tree (no HEAD).void
Scan head, index and merge tree.(package private) void
Processing an entry in the context ofprescanOneTree()
when only one tree is given(package private) void
processEntry
(CanonicalTreeParser h, CanonicalTreeParser m, DirCacheBuildIterator i, WorkingTreeIterator f) Here the main work is done.private void
private void
private static void
runBuiltinFilterCommand
(Repository repo, DirCacheCheckout.CheckoutMetadata checkoutMetadata, ObjectLoader ol, OutputStream channel) private static void
runExternalFilterCommand
(Repository repo, String path, DirCacheCheckout.CheckoutMetadata checkoutMetadata, ObjectLoader ol, OutputStream channel) void
setFailOnConflict
(boolean failOnConflict) Iftrue
, will scan first to see if it's possible to check out, otherwise throwCheckoutConflictException
.void
setForce
(boolean force) Iftrue
, dirty worktree files may be overridden.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
-
Field Details
-
LOG
private static final org.slf4j.Logger LOG -
MAX_EXCEPTION_TEXT_SIZE
private static final int MAX_EXCEPTION_TEXT_SIZE- See Also:
-
repo
-
updated
-
conflicts
-
removed
-
kept
-
mergeCommitTree
-
dc
-
builder
-
walk
-
headCommitTree
-
workingTree
-
failOnConflict
private boolean failOnConflict -
force
private boolean force -
toBeDeleted
-
initialCheckout
private boolean initialCheckout -
performingCheckout
private boolean performingCheckout -
checkout
-
monitor
-
-
Constructor Details
-
DirCacheCheckout
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
- the repository in which we do the checkoutheadCommitTree
- the id of the tree of the head commitdc
- the (already locked) Dircache for this repomergeCommitTree
- the id of the tree we want to fast-forward toworkingTree
- an iterator over the repositories Working Tree- Throws:
IOException
-
DirCacheCheckout
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 standardFileTreeIterator
- Parameters:
repo
- the repository in which we do the checkoutheadCommitTree
- the id of the tree of the head commitdc
- the (already locked) Dircache for this repomergeCommitTree
- the id of the tree we want to fast-forward to- Throws:
IOException
-
DirCacheCheckout
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
- the repository in which we do the checkoutdc
- the (already locked) Dircache for this repomergeCommitTree
- the id of the tree we want to fast-forward toworkingTree
- an iterator over the repositories Working Tree- Throws:
IOException
-
DirCacheCheckout
Constructs a DirCacheCeckout for checking out one tree, merging with the index. As iterator over the working tree this constructor creates a standardFileTreeIterator
- Parameters:
repo
- the repository in which we do the checkoutdc
- the (already locked) Dircache for this repomergeCommitTree
- the id of the tree of the- Throws:
IOException
-
-
Method Details
-
getUpdated
Get list of updated paths and smudgeFilterCommands- Returns:
- a list of updated paths and smudgeFilterCommands
-
getConflicts
Get a list of conflicts created by this checkout- Returns:
- a list of conflicts created by this checkout
-
getToBeDeleted
Get list of paths of files which couldn't be deleted during last call tocheckout()
- 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 ofDirCacheCheckout
.
-
getRemoved
Get list of all files removed by this checkout- Returns:
- a list of all files removed by this checkout
-
setProgressMonitor
Set a progress monitor which can be passed to built-in filter commands, providing progress information for long running tasks.- Parameters:
monitor
- theProgressMonitor
- Since:
- 4.11
-
preScanTwoTrees
Scan head, index and merge tree. Used during normal checkout or merge operations.- Throws:
CorruptObjectException
IOException
-
addTree
private void addTree(TreeWalk tw, ObjectId id) throws MissingObjectException, IncorrectObjectTypeException, IOException -
prescanOneTree
public void prescanOneTree() throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOExceptionScan index and merge tree (no HEAD). Used e.g. for initial checkout when there is no head yet. -
processEntry
void processEntry(CanonicalTreeParser m, DirCacheBuildIterator i, WorkingTreeIterator f) throws IOException Processing an entry in the context ofprescanOneTree()
when only one tree is given- Parameters:
m
- the tree to mergei
- the indexf
- the working tree- Throws:
IOException
-
checkout
Execute this checkout. AWorkingTreeModifiedEvent
is fired if the working tree was modified; even if the checkout fails.- 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 casegetToBeDeleted()
lists the files which should be tried to be deleted outside of this method. Althoughfalse
is returned the checkout was successful and the working tree was updated for all other files.true
is returned when no such problem occurred- Throws:
IOException
-
doCheckout
private boolean doCheckout() throws CorruptObjectException, IOException, MissingObjectException, IncorrectObjectTypeException, CheckoutConflictException, IndexWriteException, CanceledException -
filterOut
-
isSamePrefix
-
removeEmptyParents
-
equalIdAndMode
Compares whether two pairs of ObjectId and FileMode are equal.- Parameters:
id1
-mode1
-id2
-mode2
-- Returns:
true
if FileModes and ObjectIds are equal.false
otherwise
-
processEntry
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
- the entry for the headm
- the entry for the mergei
- the entry for the indexf
- the file in the working tree- Throws:
IOException
-
idEqual
-
conflict
A conflict is detected - add the three different stages to the index- Parameters:
path
- the path of the conflicting entrye
- the previous index entryh
- the first tree you want to merge (the HEAD)m
- the second tree you want to merge
-
keep
- Throws:
IOException
-
remove
-
update
- Throws:
IOException
-
setFailOnConflict
public void setFailOnConflict(boolean failOnConflict) Iftrue
, will scan first to see if it's possible to check out, otherwise throwCheckoutConflictException
. Iffalse
, it will silently deal with the problem.- Parameters:
failOnConflict
- a boolean.
-
setForce
public void setForce(boolean force) Iftrue
, dirty worktree files may be overridden. Iffalse
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
- a boolean.- Since:
- 5.3
-
cleanUpConflicts
This method implements how to handle conflicts whenfailOnConflict
is false- Throws:
CheckoutConflictException
-
isModifiedSubtree_IndexWorkingtree
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
-- Returns:
- true if the subtrees differ
- Throws:
CorruptObjectException
IOException
-
isModified_IndexTree
private boolean isModified_IndexTree(String path, ObjectId iId, FileMode iMode, ObjectId tId, FileMode tMode, ObjectId rootTree) throws CorruptObjectException, IOException - Throws:
CorruptObjectException
IOException
-
isModifiedSubtree_IndexTree
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
-tree
- the tree to compare- Returns:
- true if the subtrees differ
- Throws:
CorruptObjectException
IOException
-
checkoutEntry
@Deprecated public static void checkoutEntry(Repository repo, DirCacheEntry entry, ObjectReader or) throws IOException Deprecated.since 5.1, usecheckoutEntry(Repository, DirCacheEntry, ObjectReader, boolean, CheckoutMetadata)
insteadUpdates the file in the working tree with content and mode from an entry in the index. The new content is first written to a new temporary file in the same directory as the real file. Then that new file is renamed to the final filename.Note: if the entry path on local file system exists as a non-empty directory, and the target entry type is a link or file, the checkout will fail with
IOException
since existing non-empty directory cannot be renamed to file or link without deleting it recursively.TODO: this method works directly on File IO, we may need another abstraction (like WorkingTreeIterator). This way we could tell e.g. Eclipse that Files in the workspace got changed
- Parameters:
repo
- repository managing the destination work tree.entry
- the entry containing new mode and contentor
- object reader to use for checkout- Throws:
IOException
- Since:
- 3.6
-
checkoutEntry
public static void checkoutEntry(Repository repo, DirCacheEntry entry, ObjectReader or, boolean deleteRecursive, DirCacheCheckout.CheckoutMetadata checkoutMetadata) throws IOException Updates the file in the working tree with content and mode from an entry in the index. The new content is first written to a new temporary file in the same directory as the real file. Then that new file is renamed to the final filename.Note: if the entry path on local file system exists as a file, it will be deleted and if it exists as a directory, it will be deleted recursively, independently if has any content.
TODO: this method works directly on File IO, we may need another abstraction (like WorkingTreeIterator). This way we could tell e.g. Eclipse that Files in the workspace got changed
- Parameters:
repo
- repository managing the destination work tree.entry
- the entry containing new mode and contentor
- object reader to use for checkoutdeleteRecursive
- true to recursively delete final path if it exists on the file systemcheckoutMetadata
- containing- smudgeFilterCommand to be run for smudging the entry to be checked out
- eolStreamType used for stream conversion
- Throws:
IOException
- Since:
- 4.2
-
getContent
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
- the repositorypath
- the path used to determine the correct filters for the objectcheckoutMetadata
- containing- smudgeFilterCommand to be run for smudging the object
- eolStreamType used for stream conversion (can be null)
ol
- the object loader to read raw content of the objectopt
- the working tree options where only 'core.autocrlf' is used for EOL handling if 'checkoutMetadata.eolStreamType' is not validos
- the output stream the filtered content is written to. The caller is responsible to close the stream.- Throws:
IOException
- Since:
- 5.7
-
runExternalFilterCommand
private static void runExternalFilterCommand(Repository repo, String path, DirCacheCheckout.CheckoutMetadata checkoutMetadata, ObjectLoader ol, OutputStream channel) throws IOException - Throws:
IOException
-
runBuiltinFilterCommand
private static void runBuiltinFilterCommand(Repository repo, DirCacheCheckout.CheckoutMetadata checkoutMetadata, ObjectLoader ol, OutputStream channel) throws MissingObjectException, IOException - Throws:
MissingObjectException
IOException
-
checkValidPath
- Throws:
InvalidPathException
-
checkValidPathSegment
private static void checkValidPathSegment(ObjectChecker chk, CanonicalTreeParser t) throws InvalidPathException - Throws:
InvalidPathException
-
checkoutEntry(Repository, DirCacheEntry, ObjectReader, boolean, CheckoutMetadata)
instead