java.lang.Object
org.eclipse.jgit.merge.ResolveMerger.WorkTreeUpdater
- All Implemented Interfaces:
Closeable
,AutoCloseable
- Enclosing class:
- ResolveMerger
Handles work tree updates on both the checkout and the index.
You should use a single instance for all of your file changes. In case of an error, make sure your instance is released, and initiate a new one if necessary.
- Since:
- 6.3.1
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
The result of writing the index changes. -
Method Summary
Modifier and TypeMethodDescriptionaddExistingToIndex
(ObjectId objectId, byte[] path, FileMode fileMode, int entryStage, Instant lastModified, int len) Adds a path with the specified stage to the index builder.void
addToCheckout
(String path, DirCacheEntry entry, CoreConfig.EolStreamType cleanupStreamType, String cleanupSmudgeCommand, CoreConfig.EolStreamType checkoutStreamType, String checkoutSmudgeCommand) Adds aDirCacheEntry
for direct checkout and remembers itsDirCacheCheckout.CheckoutMetadata
.void
close()
Creates aDirCacheBuildIterator
for the builder of thisResolveMerger.WorkTreeUpdater
.createInCoreWorkTreeUpdater
(Repository repo, DirCache dirCache, ObjectInserter oi) Creates a newResolveMerger.WorkTreeUpdater
that works in memory only.createWorkTreeUpdater
(Repository repo, DirCache dirCache) Creates a newResolveMerger.WorkTreeUpdater
for the given repository.void
deleteFile
(String path, File file, CoreConfig.EolStreamType streamType, String smudgeCommand) Remembers the given file to be deleted.detectCheckoutStreamType
(Attributes attributes) Detects if CRLF conversion has been configured.int
Gets the size limit for in-core files in this config.Gets dir cache for the repo.Gets the list of files which were modified in this operation.Gets a map which maps the paths of files which have to be checked out because the operation created new fully-merged content for this file into the index.insertToIndex
(InputStream input, byte[] path, FileMode fileMode, int entryStage, Instant lastModified, int len, Attribute lfsAttribute) Creates a path with the given content, and adds it to the specified stage to the index builder.void
markAsModified
(String path) Marks the given path as modified in the operation.void
Reverts any uncommitted changes in the worktree.void
updateFileWithContent
(DirCacheCheckout.StreamSupplier inputStream, CoreConfig.EolStreamType streamType, String smudgeCommand, String path, File file) Updates the file in the checkout with the given content.Writes the changes to the index.void
writeWorkTreeChanges
(boolean shouldCheckoutTheirs) Writes the changes to the working tree (but not to the index).
-
Method Details
-
createWorkTreeUpdater
public static ResolveMerger.WorkTreeUpdater createWorkTreeUpdater(Repository repo, DirCache dirCache) Creates a newResolveMerger.WorkTreeUpdater
for the given repository.- Parameters:
repo
- theRepository
.dirCache
- if set, use the provided dir cache. Otherwise, use the default repository one- Returns:
- the
ResolveMerger.WorkTreeUpdater
.
-
createInCoreWorkTreeUpdater
public static ResolveMerger.WorkTreeUpdater createInCoreWorkTreeUpdater(Repository repo, DirCache dirCache, ObjectInserter oi) Creates a newResolveMerger.WorkTreeUpdater
that works in memory only.- Parameters:
repo
- theRepository
.dirCache
- if set, use the provided dir cache. Otherwise, creates a new oneoi
- to use for writing the modified objects with.- Returns:
- the
ResolveMerger.WorkTreeUpdater
-
getInCoreFileSizeLimit
public int getInCoreFileSizeLimit()Gets the size limit for in-core files in this config.- Returns:
- the size
-
getLockedDirCache
Gets dir cache for the repo. Locked if not inCore.- Returns:
- the result dir cache
- Throws:
IOException
- is case the dir cache cannot be read
-
createDirCacheBuildIterator
Creates aDirCacheBuildIterator
for the builder of thisResolveMerger.WorkTreeUpdater
.- Returns:
- the
DirCacheBuildIterator
-
writeWorkTreeChanges
Writes the changes to the working tree (but not to the index).- Parameters:
shouldCheckoutTheirs
- before committing the changes- Throws:
IOException
- if any of the writes fail
-
writeIndexChanges
Writes the changes to the index.- Returns:
- the
ResolveMerger.WorkTreeUpdater.Result
of the operation. - Throws:
IOException
- if any of the writes fail
-
addToCheckout
public void addToCheckout(String path, DirCacheEntry entry, CoreConfig.EolStreamType cleanupStreamType, String cleanupSmudgeCommand, CoreConfig.EolStreamType checkoutStreamType, String checkoutSmudgeCommand) Adds aDirCacheEntry
for direct checkout and remembers itsDirCacheCheckout.CheckoutMetadata
.- Parameters:
path
- of the entryentry
- to addcleanupStreamType
- to use for the cleanup metadatacleanupSmudgeCommand
- to use for the cleanup metadatacheckoutStreamType
- to use for the checkout metadatacheckoutSmudgeCommand
- to use for the checkout metadata
-
getToBeCheckedOut
Gets a map which maps the paths of files which have to be checked out because the operation created new fully-merged content for this file into the index.This means: the operation wrote a new stage 0 entry for this path.
- Returns:
- the map
-
deleteFile
public void deleteFile(String path, File file, CoreConfig.EolStreamType streamType, String smudgeCommand) Remembers the given file to be deleted.Note the actual deletion is only done in
writeWorkTreeChanges(boolean)
.- Parameters:
path
- of the file to be deletedfile
- to be deletedstreamType
- to use for cleanup metadatasmudgeCommand
- to use for cleanup metadata
-
detectCheckoutStreamType
Detects if CRLF conversion has been configured.See
EolStreamTypeUtil.detectStreamType(org.eclipse.jgit.treewalk.TreeWalk.OperationType, org.eclipse.jgit.treewalk.WorkingTreeOptions, org.eclipse.jgit.attributes.Attributes)
for more info.- Parameters:
attributes
- of the file for which the type is to be detected- Returns:
- the detected type
-
markAsModified
Marks the given path as modified in the operation.- Parameters:
path
- to mark as modified
-
getModifiedFiles
Gets the list of files which were modified in this operation.- Returns:
- the list
-
revertModifiedFiles
Reverts any uncommitted changes in the worktree. We know that for all modified files the old content was in the old index and the index contained only stage 0. In case of inCore operation just clear the history of modified files.- Throws:
IOException
- in case the cleaning up failed
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
updateFileWithContent
public void updateFileWithContent(DirCacheCheckout.StreamSupplier inputStream, CoreConfig.EolStreamType streamType, String smudgeCommand, String path, File file) throws IOException Updates the file in the checkout with the given content.- Parameters:
inputStream
- the content to be updatedstreamType
- for parsing the contentsmudgeCommand
- for formatting the contentpath
- of the file to be updatedfile
- to be updated- Throws:
IOException
- if the file cannot be updated
-
insertToIndex
public DirCacheEntry insertToIndex(InputStream input, byte[] path, FileMode fileMode, int entryStage, Instant lastModified, int len, Attribute lfsAttribute) throws IOException Creates a path with the given content, and adds it to the specified stage to the index builder.- Parameters:
input
- the content to be updatedpath
- of the file to be updatedfileMode
- of the modified fileentryStage
- of the new entrylastModified
- instant of the modified filelen
- of the contentlfsAttribute
- for checking for LFS enablement- Returns:
- the entry which was added to the index
- Throws:
IOException
- if inserting the content fails
-
addExistingToIndex
public DirCacheEntry addExistingToIndex(ObjectId objectId, byte[] path, FileMode fileMode, int entryStage, Instant lastModified, int len) Adds a path with the specified stage to the index builder.- Parameters:
objectId
- of the existing object to addpath
- of the modified filefileMode
- of the modified fileentryStage
- of the new entrylastModified
- instant of the modified filelen
- of the modified file content- Returns:
- the entry which was added to the index
-