Class ResolveMerger.WorkTreeUpdater

java.lang.Object
org.eclipse.jgit.merge.ResolveMerger.WorkTreeUpdater
All Implemented Interfaces:
Closeable, AutoCloseable
Enclosing class:
ResolveMerger

protected static class ResolveMerger.WorkTreeUpdater extends Object implements Closeable
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
  • Method Details

    • createWorkTreeUpdater

      public static ResolveMerger.WorkTreeUpdater createWorkTreeUpdater(Repository repo, DirCache dirCache)
      Creates a new ResolveMerger.WorkTreeUpdater for the given repository.
      Parameters:
      repo - the Repository.
      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 new ResolveMerger.WorkTreeUpdater that works in memory only.
      Parameters:
      repo - the Repository.
      dirCache - if set, use the provided dir cache. Otherwise, creates a new one
      oi - 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

      public DirCache getLockedDirCache() throws IOException
      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

      public DirCacheBuildIterator createDirCacheBuildIterator()
      Creates a DirCacheBuildIterator for the builder of this ResolveMerger.WorkTreeUpdater.
      Returns:
      the DirCacheBuildIterator
    • writeWorkTreeChanges

      public void writeWorkTreeChanges(boolean shouldCheckoutTheirs) throws IOException
      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

      public ResolveMerger.WorkTreeUpdater.Result writeIndexChanges() throws IOException
      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 a DirCacheEntry for direct checkout and remembers its DirCacheCheckout.CheckoutMetadata.
      Parameters:
      path - of the entry
      entry - to add
      cleanupStreamType - to use for the cleanup metadata
      cleanupSmudgeCommand - to use for the cleanup metadata
      checkoutStreamType - to use for the checkout metadata
      checkoutSmudgeCommand - to use for the checkout metadata
    • getToBeCheckedOut

      public Map<String,DirCacheEntry> 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 deleted
      file - to be deleted
      streamType - to use for cleanup metadata
      smudgeCommand - to use for cleanup metadata
    • detectCheckoutStreamType

      public CoreConfig.EolStreamType detectCheckoutStreamType(Attributes attributes)
      Parameters:
      attributes - of the file for which the type is to be detected
      Returns:
      the detected type
    • markAsModified

      public void markAsModified(String path)
      Marks the given path as modified in the operation.
      Parameters:
      path - to mark as modified
    • getModifiedFiles

      public List<String> getModifiedFiles()
      Gets the list of files which were modified in this operation.
      Returns:
      the list
    • revertModifiedFiles

      public void revertModifiedFiles() throws IOException
      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

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      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 updated
      streamType - for parsing the content
      smudgeCommand - for formatting the content
      path - of the file to be updated
      file - 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 updated
      path - of the file to be updated
      fileMode - of the modified file
      entryStage - of the new entry
      lastModified - instant of the modified file
      len - of the content
      lfsAttribute - 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 add
      path - of the modified file
      fileMode - of the modified file
      entryStage - of the new entry
      lastModified - instant of the modified file
      len - of the modified file content
      Returns:
      the entry which was added to the index