Package com.google.gerrit.server.notedb
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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CommitRewriter.BackfillResult
Result of the backfill run for a project.static class
CommitRewriter.CommitDiff
Diff result of a single commit rewritestatic class
CommitRewriter.RunOptions
-
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_ACCOUNT_REPLACEMENT
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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)
Walks the ref history from oldest update to the most recent update, fixing the commits that contain user data case by case.CommitRewriter.BackfillResult
backfillProject(Project.NameKey project, org.eclipse.jgit.lib.Repository repo, CommitRewriter.RunOptions options)
Rewrites commit history ofRefNames.changeMetaRef(com.google.gerrit.entities.Change.Id)
s in singlerepo
.static byte[]
cutTreeAndParents(byte[] b)
Cuts tree and parent lines from raw unparsed commit body, so they are not included in diff comparison.
-
-
-
Field Detail
-
DEFAULT_ACCOUNT_REPLACEMENT
public static final String DEFAULT_ACCOUNT_REPLACEMENT
- See Also:
- Constant Field Values
-
-
Method Detail
-
backfillProject
public CommitRewriter.BackfillResult backfillProject(Project.NameKey project, org.eclipse.jgit.lib.Repository repo, CommitRewriter.RunOptions options)
Rewrites commit history ofRefNames.changeMetaRef(com.google.gerrit.entities.Change.Id)
s in singlerepo
. 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 backfillrepo
- repo to backfilloptions
-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 inCommitRewriter.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, seeRevCommit.getRawBuffer()
.For parsing, see
RawParseUtils.author(byte[], int)
,RawParseUtils.commitMessage(byte[], int)
, etc.- Returns:
- raw unparsed commit body, without tree and parent lines.
-
-