docs: private static boolean applyDirectoryEdits(DirCache dirCache,
                                                 String oldDir, @Nullable String newDir, Change<?> change) {
  
          if (!oldDir.endsWith("/")) {
              oldDir += '/';
          }
          if (newDir != null && !newDir.endsWith("/")) {
              newDir += '/';
          }
  
          final byte[] rawOldDir = Constants.encode(oldDir);
          final byte[] rawNewDir = newDir != null ? Constants.encode(newDir) : null;
          final int numEntries = dirCache.getEntryCount();
          DirCacheEditor editor = null;
  
          loop:
          for (int i = 0; i < numEntries; i++) {
              final DirCacheEntry e = dirCache.getEntry(i);
              final byte[] rawPath = e.getRawPath();
  
              // Ensure that there are no entries under the newDir; we have a conflict otherwise.
              if (rawNewDir != null) {
                  boolean conflict = true;
                  if (rawPath.length > rawNewDir.length) {
                      // Check if there is a file whose path starts with 'newDir'.
                      for (int j = 0; j < rawNewDir.length; j++) {
                          if (rawNewDir[j] != rawPath[j]) {
                              conflict = false;
                              break;
                          }
                      }
                  } else if (rawPath.length == rawNewDir.length - 1) {
                      // Check if there is a file whose path is exactly same with newDir without trailing '/'.
                      for (int j = 0; j < rawNewDir.length - 1; j++) {
                          if (rawNewDir[j] != rawPath[j]) {
                              conflict = false;
                              break;
                          }
                      }
                  } else {
                      conflict = false;
                  }
  
                  if (conflict) {
                      throw new ChangeConflictException("target directory exists already: " + change);
                  }
              }
  
              // Skip the entries that do not belong to the oldDir.
              if (rawPath.length <= rawOldDir.length) {
                  continue;
              }
              for (int j = 0; j < rawOldDir.length; j++) {
                  if (rawOldDir[j] != rawPath[j]) {
                      continue loop;
                  }
              }
  
              // Do not create an editor until we find an entry to rename/remove.
              // We can tell if there was any matching entries or not from the nullness of editor later.
              if (editor == null) {
                  editor = dirCache.editor();
                  editor.add(new DeleteTree(oldDir));
                  if (newDir == null) {
                      // Recursive removal
                      break;
                  }
              }
  
              assert newDir != null; // We should get here only when it's a recursive rename.
  
              final String oldPath = e.getPathString();
              final String newPath = newDir + oldPath.substring(oldDir.length());
              editor.add(new CopyOldEntry(newPath, e));
          }
  
          if (editor != null) {
              editor.finish();
              return true;
          } else {
              return false;
          }
      }