public class DirCacheCheckout
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
DirCacheCheckout.CheckoutMetadata
Metadata used in checkout process
|
Modifier and Type | Field and Description |
---|---|
private DirCacheBuilder |
builder |
private java.util.ArrayList<java.lang.String> |
conflicts |
private DirCache |
dc |
private boolean |
failOnConflict |
private boolean |
force |
private ObjectId |
headCommitTree |
private boolean |
initialCheckout |
private static org.slf4j.Logger |
LOG |
private static int |
MAX_EXCEPTION_TEXT_SIZE |
private ObjectId |
mergeCommitTree |
private ProgressMonitor |
monitor |
private boolean |
performingCheckout |
private java.util.ArrayList<java.lang.String> |
removed |
private Repository |
repo |
private java.util.ArrayList<java.lang.String> |
toBeDeleted |
private java.util.HashMap<java.lang.String,DirCacheCheckout.CheckoutMetadata> |
updated |
private NameConflictTreeWalk |
walk |
private WorkingTreeIterator |
workingTree |
Constructor and Description |
---|
DirCacheCheckout(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.
|
Modifier and Type | Method and Description |
---|---|
private void |
addTree(TreeWalk tw,
ObjectId id) |
boolean |
checkout()
Execute this checkout.
|
static void |
checkoutEntry(Repository repo,
DirCacheEntry entry,
ObjectReader or)
Deprecated.
since 5.1, use
checkoutEntry(Repository, DirCacheEntry, ObjectReader, boolean, CheckoutMetadata)
instead |
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 void |
checkoutGitlink(java.lang.String path,
DirCacheEntry entry) |
private static void |
checkValidPath(CanonicalTreeParser t) |
private static void |
checkValidPathSegment(ObjectChecker chk,
CanonicalTreeParser t) |
private void |
cleanUpConflicts()
This method implements how to handle conflicts when
failOnConflict is false |
private void |
conflict(java.lang.String path,
DirCacheEntry e,
AbstractTreeIterator h,
AbstractTreeIterator m)
A conflict is detected - add the three different stages to the index
|
private boolean |
doCheckout() |
private boolean |
equalIdAndMode(ObjectId id1,
FileMode mode1,
ObjectId id2,
FileMode mode2)
Compares whether two pairs of ObjectId and FileMode are equal.
|
private static java.util.ArrayList<java.lang.String> |
filterOut(java.util.ArrayList<java.lang.String> strings,
IntList indicesToRemove) |
java.util.List<java.lang.String> |
getConflicts()
Get a list of conflicts created by this checkout
|
java.util.List<java.lang.String> |
getRemoved()
Get list of all files removed by this checkout
|
java.util.List<java.lang.String> |
getToBeDeleted()
Get list of paths of files which couldn't be deleted during last call to
checkout() |
java.util.Map<java.lang.String,DirCacheCheckout.CheckoutMetadata> |
getUpdated()
Get list of updated paths and smudgeFilterCommands
|
private static boolean |
idEqual(AbstractTreeIterator a,
AbstractTreeIterator b) |
private boolean |
isModified_IndexTree(java.lang.String path,
ObjectId iId,
FileMode iMode,
ObjectId tId,
FileMode tMode,
ObjectId rootTree) |
private boolean |
isModifiedSubtree_IndexTree(java.lang.String path,
ObjectId tree)
Checks whether the subtree starting at a given path differs between Index and
some tree.
|
private boolean |
isModifiedSubtree_IndexWorkingtree(java.lang.String path)
Checks whether the subtree starting at a given path differs between Index and
workingtree.
|
private static boolean |
isSamePrefix(java.lang.String a,
java.lang.String b) |
private void |
keep(DirCacheEntry e,
WorkingTreeIterator f) |
void |
prescanOneTree()
Scan index and merge tree (no HEAD).
|
void |
preScanTwoTrees()
Scan head, index and merge tree.
|
(package private) void |
processEntry(CanonicalTreeParser h,
CanonicalTreeParser m,
DirCacheBuildIterator i,
WorkingTreeIterator f)
Here the main work is done.
|
(package private) void |
processEntry(CanonicalTreeParser m,
DirCacheBuildIterator i,
WorkingTreeIterator f)
Processing an entry in the context of
prescanOneTree() when only
one tree is given |
private void |
remove(java.lang.String path) |
private void |
removeEmptyParents(java.io.File f) |
private static void |
runBuiltinFilterCommand(Repository repo,
DirCacheCheckout.CheckoutMetadata checkoutMetadata,
ObjectLoader ol,
java.io.OutputStream channel) |
private static void |
runExternalFilterCommand(Repository repo,
DirCacheEntry entry,
DirCacheCheckout.CheckoutMetadata checkoutMetadata,
ObjectLoader ol,
FS fs,
java.io.OutputStream channel) |
void |
setFailOnConflict(boolean failOnConflict)
If
true , will scan first to see if it's possible to check
out, otherwise throw
CheckoutConflictException . |
void |
setForce(boolean force)
If
true , 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 |
update(java.lang.String path,
ObjectId mId,
FileMode mode) |
private static org.slf4j.Logger LOG
private static final int MAX_EXCEPTION_TEXT_SIZE
private Repository repo
private java.util.HashMap<java.lang.String,DirCacheCheckout.CheckoutMetadata> updated
private java.util.ArrayList<java.lang.String> conflicts
private java.util.ArrayList<java.lang.String> removed
private ObjectId mergeCommitTree
private DirCache dc
private DirCacheBuilder builder
private NameConflictTreeWalk walk
private ObjectId headCommitTree
private WorkingTreeIterator workingTree
private boolean failOnConflict
private boolean force
private java.util.ArrayList<java.lang.String> toBeDeleted
private boolean initialCheckout
private boolean performingCheckout
private ProgressMonitor monitor
public DirCacheCheckout(Repository repo, ObjectId headCommitTree, DirCache dc, ObjectId mergeCommitTree, WorkingTreeIterator workingTree) throws java.io.IOException
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 Treejava.io.IOException
public DirCacheCheckout(Repository repo, ObjectId headCommitTree, DirCache dc, ObjectId mergeCommitTree) throws java.io.IOException
FileTreeIterator
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 tojava.io.IOException
public DirCacheCheckout(Repository repo, DirCache dc, ObjectId mergeCommitTree, WorkingTreeIterator workingTree) throws java.io.IOException
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 Treejava.io.IOException
public DirCacheCheckout(Repository repo, DirCache dc, ObjectId mergeCommitTree) throws java.io.IOException
FileTreeIterator
repo
- the repository in which we do the checkoutdc
- the (already locked) Dircache for this repomergeCommitTree
- the id of the tree of thejava.io.IOException
public java.util.Map<java.lang.String,DirCacheCheckout.CheckoutMetadata> getUpdated()
public java.util.List<java.lang.String> getConflicts()
public java.util.List<java.lang.String> getToBeDeleted()
checkout()
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
DirCacheCheckout
.public java.util.List<java.lang.String> getRemoved()
public void setProgressMonitor(ProgressMonitor monitor)
monitor
- the ProgressMonitor
public void preScanTwoTrees() throws CorruptObjectException, java.io.IOException
CorruptObjectException
java.io.IOException
private void addTree(TreeWalk tw, ObjectId id) throws MissingObjectException, IncorrectObjectTypeException, java.io.IOException
MissingObjectException
IncorrectObjectTypeException
java.io.IOException
public void prescanOneTree() throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, java.io.IOException
MissingObjectException
IncorrectObjectTypeException
CorruptObjectException
java.io.IOException
void processEntry(CanonicalTreeParser m, DirCacheBuildIterator i, WorkingTreeIterator f) throws java.io.IOException
prescanOneTree()
when only
one tree is givenm
- the tree to mergei
- the indexf
- the working treejava.io.IOException
public boolean checkout() throws java.io.IOException
WorkingTreeModifiedEvent
is fired if the
working tree was modified; even if the checkout fails.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 occurredjava.io.IOException
private boolean doCheckout() throws CorruptObjectException, java.io.IOException, MissingObjectException, IncorrectObjectTypeException, CheckoutConflictException, IndexWriteException, CanceledException
private void checkoutGitlink(java.lang.String path, DirCacheEntry entry) throws java.io.IOException
java.io.IOException
private static java.util.ArrayList<java.lang.String> filterOut(java.util.ArrayList<java.lang.String> strings, IntList indicesToRemove)
private static boolean isSamePrefix(java.lang.String a, java.lang.String b)
private void removeEmptyParents(java.io.File f)
private boolean equalIdAndMode(ObjectId id1, FileMode mode1, ObjectId id2, FileMode mode2)
id1
- mode1
- id2
- mode2
- true
if FileModes and ObjectIds are equal.
false
otherwisevoid processEntry(CanonicalTreeParser h, CanonicalTreeParser m, DirCacheBuildIterator i, WorkingTreeIterator f) throws java.io.IOException
h
- the entry for the headm
- the entry for the mergei
- the entry for the indexf
- the file in the working treejava.io.IOException
private static boolean idEqual(AbstractTreeIterator a, AbstractTreeIterator b)
private void conflict(java.lang.String path, DirCacheEntry e, AbstractTreeIterator h, AbstractTreeIterator m)
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 mergeprivate void keep(DirCacheEntry e, WorkingTreeIterator f) throws java.io.IOException
java.io.IOException
private void remove(java.lang.String path)
private void update(java.lang.String path, ObjectId mId, FileMode mode) throws java.io.IOException
java.io.IOException
public void setFailOnConflict(boolean failOnConflict)
true
, will scan first to see if it's possible to check
out, otherwise throw
CheckoutConflictException
. If
false
, it will silently deal with the problem.failOnConflict
- a boolean.public void setForce(boolean force)
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.force
- a boolean.private void cleanUpConflicts() throws CheckoutConflictException
failOnConflict
is falseCheckoutConflictException
private boolean isModifiedSubtree_IndexWorkingtree(java.lang.String path) throws CorruptObjectException, java.io.IOException
path
- CorruptObjectException
java.io.IOException
private boolean isModified_IndexTree(java.lang.String path, ObjectId iId, FileMode iMode, ObjectId tId, FileMode tMode, ObjectId rootTree) throws CorruptObjectException, java.io.IOException
CorruptObjectException
java.io.IOException
private boolean isModifiedSubtree_IndexTree(java.lang.String path, ObjectId tree) throws CorruptObjectException, java.io.IOException
path
- tree
- the tree to compareCorruptObjectException
java.io.IOException
@Deprecated public static void checkoutEntry(Repository repo, DirCacheEntry entry, ObjectReader or) throws java.io.IOException
checkoutEntry(Repository, DirCacheEntry, ObjectReader, boolean, CheckoutMetadata)
instead
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
repo
- repository managing the destination work tree.entry
- the entry containing new mode and contentor
- object reader to use for checkoutjava.io.IOException
public static void checkoutEntry(Repository repo, DirCacheEntry entry, ObjectReader or, boolean deleteRecursive, DirCacheCheckout.CheckoutMetadata checkoutMetadata) throws java.io.IOException
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
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
java.io.IOException
private static void runExternalFilterCommand(Repository repo, DirCacheEntry entry, DirCacheCheckout.CheckoutMetadata checkoutMetadata, ObjectLoader ol, FS fs, java.io.OutputStream channel) throws java.io.IOException
java.io.IOException
private static void runBuiltinFilterCommand(Repository repo, DirCacheCheckout.CheckoutMetadata checkoutMetadata, ObjectLoader ol, java.io.OutputStream channel) throws MissingObjectException, java.io.IOException
MissingObjectException
java.io.IOException
private static void checkValidPath(CanonicalTreeParser t) throws InvalidPathException
InvalidPathException
private static void checkValidPathSegment(ObjectChecker chk, CanonicalTreeParser t) throws InvalidPathException
InvalidPathException