Class CommitRewriter


  • public class CommitRewriter
    extends Object
    Rewrites ('backfills') commit history of change in NoteDb to not contain user data. Only fixes known cases, rewriting commits case by case.

    The cases where we used to put user data in NoteDb can be found by https://gerrit-review.googlesource.com/q/hashtag:user-data-cleanup

    As opposed to NoteDbRewriter implementations, which target a specific change and are used by REST endpoints, this rewriter is used as standalone tool, that bulk backfills changes by project.

    • Method Detail

      • backfillChange

        public com.google.gerrit.server.notedb.CommitRewriter.ChangeFixProgress backfillChange​(com.google.gerrit.server.notedb.CommitRewriter.RefsUpdate refsUpdate,
                                                                                               org.eclipse.jgit.lib.Ref ref,
                                                                                               com.google.common.collect.ImmutableSet<AccountState> accountsInChange,
                                                                                               CommitRewriter.RunOptions options)
                                                                                        throws IOException,
                                                                                               org.eclipse.jgit.errors.ConfigInvalidException
        Walks the ref history from oldest update to the most recent update, fixing the commits that contain user data case by case. Commit history is rewritten from the first commit, that needs to be updated, for all subsequent updates. The new ref tip is returned in CommitRewriter.ChangeFixProgress.newTipId.
        Throws:
        IOException
        org.eclipse.jgit.errors.ConfigInvalidException
      • cutTreeAndParents

        public static byte[] cutTreeAndParents​(byte[] b)
        Cuts tree and parent lines from raw unparsed commit body, so they are not included in diff comparison.
        Parameters:
        b - raw unparsed commit body, see RevCommit.getRawBuffer().

        For parsing, see RawParseUtils.author(byte[], int), RawParseUtils.commitMessage(byte[], int), etc.

        Returns:
        raw unparsed commit body, without tree and parent lines.