Class GitRatchet<Project>

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    public abstract class GitRatchet<Project>
    extends java.lang.Object
    implements java.lang.AutoCloseable
    How to use: - For best performance, you should have one instance of GitRatchet, shared by all projects. - Use rootTreeShaOf(Object, String) to turn origin/master into the SHA of the tree object at that reference - Use isClean(Object, ObjectId, File) to see if the given file is "git clean" relative to that tree - If you have up-to-date checking and want the best possible performance, use subtreeShaOf(Object, ObjectId) to optimize up-to-date checks on a per-project basis.
    • Constructor Summary

      Constructors 
      Constructor Description
      GitRatchet()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      protected abstract java.io.File getDir​(Project project)  
      protected abstract Project getParent​(Project project)  
      boolean isClean​(Project project, org.eclipse.jgit.lib.ObjectId treeSha, java.io.File file)  
      boolean isClean​(Project project, org.eclipse.jgit.lib.ObjectId treeSha, java.lang.String relativePathUnix)
      This is the highest-level method, which all the others serve.
      protected org.eclipse.jgit.lib.Repository repositoryFor​(Project project)
      The first part of making this fast is finding the appropriate git repository quickly.
      org.eclipse.jgit.lib.ObjectId rootTreeShaOf​(Project project, java.lang.String reference)
      Fast way to return treeSha of the given ref against the git repository which stores the given project.
      org.eclipse.jgit.lib.ObjectId subtreeShaOf​(Project project, org.eclipse.jgit.lib.ObjectId rootTreeSha)
      Returns the sha of the git subtree which represents the root of the given project, or ObjectId.zeroId() if there is no git subtree at the project root.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • GitRatchet

        public GitRatchet()
    • Method Detail

      • isClean

        public boolean isClean​(Project project,
                               org.eclipse.jgit.lib.ObjectId treeSha,
                               java.io.File file)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • isClean

        public boolean isClean​(Project project,
                               org.eclipse.jgit.lib.ObjectId treeSha,
                               java.lang.String relativePathUnix)
                        throws java.io.IOException
        This is the highest-level method, which all the others serve. Given the sha of a git tree (not a commit!), and the file in question, this method returns true if that file is clean relative to that tree. A naive implementation of this could be verrrry slow, so the rest of this is about speeding this up.
        Throws:
        java.io.IOException
      • repositoryFor

        protected org.eclipse.jgit.lib.Repository repositoryFor​(Project project)
                                                         throws java.io.IOException
        The first part of making this fast is finding the appropriate git repository quickly. Because of composite builds and submodules, it's quite possible that a single Gradle project will span across multiple git repositories. We cache the Repository for every Project in gitRoots, and use dynamic programming to populate it.
        Throws:
        java.io.IOException
      • getDir

        protected abstract java.io.File getDir​(Project project)
      • getParent

        @Nullable
        protected abstract Project getParent​(Project project)
      • rootTreeShaOf

        public org.eclipse.jgit.lib.ObjectId rootTreeShaOf​(Project project,
                                                           java.lang.String reference)
        Fast way to return treeSha of the given ref against the git repository which stores the given project. Because of parallel project evaluation, there may be races here, so we synchronize on ourselves. However, this method is the only method which can trigger any changes, and it is only called during project evaluation. That means our state is final/read-only during task execution, so we don't need any locks during the heavy lifting.
      • subtreeShaOf

        public org.eclipse.jgit.lib.ObjectId subtreeShaOf​(Project project,
                                                          org.eclipse.jgit.lib.ObjectId rootTreeSha)
        Returns the sha of the git subtree which represents the root of the given project, or ObjectId.zeroId() if there is no git subtree at the project root.
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable