Class 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 Detail

      • 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
      • 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
      • 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
      • 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
      • 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