Class CommitRewriter

java.lang.Object
com.google.gerrit.server.notedb.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.

  • Field Details

    • DEFAULT_ACCOUNT_REPLACEMENT

      public static final String DEFAULT_ACCOUNT_REPLACEMENT
      See Also:
  • Method Details

    • backfillProject

      public CommitRewriter.BackfillResult backfillProject(Project.NameKey project, org.eclipse.jgit.lib.Repository repo, CommitRewriter.RunOptions options)
      Rewrites commit history of RefNames.changeMetaRef(com.google.gerrit.entities.Change.Id)s in single repo. Only rewrites branch if necessary, i.e. if there were any commits that contained user data.

      See CommitRewriter.RunOptions for the execution and output options.

      Parameters:
      project - project to backfill
      repo - repo to backfill
      options - CommitRewriter.RunOptions to control how the run is executed.
      Returns:
      BackfillResult
    • 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.