Class GitPositionTransformer
- java.lang.Object
-
- com.google.gerrit.server.patch.GitPositionTransformer
-
public class GitPositionTransformer extends Object
Transformer ofGitPositionTransformer.Position
s in one Git tree toGitPositionTransformer.Position
s in another Git tree given theGitPositionTransformer.Mapping
s between the trees.The base idea is that a
GitPositionTransformer.Position
in the source tree can be translated/mapped to a correspondingGitPositionTransformer.Position
in the target tree when we know how the target tree changed compared to the source tree. As long asGitPositionTransformer.Position
s are only defined via file path and line range, we only need to know which file path in the source tree corresponds to which file path in the target tree and how the lines within that file changed from the source to the target tree.The algorithm is roughly:
- Go over all positions and replace the file path for each of them with the corresponding one in the target tree. If a file path maps to two file paths in the target tree (copied file), duplicate the position entry and use each of the new file paths with it. If a file path maps to no file in the target tree (deleted file), apply the specified conflict strategy (e.g. drop position completely or map to next best guess).
- Per file path, go through the file from top to bottom and keep track of how the range mappings for that file shift the lines. Derive the shifted amount by comparing the number of lines between source and target in the range mapping. While going through the file, shift each encountered position by the currently tracked amount. If a position overlaps with the lines of a range mapping, apply the specified conflict strategy (e.g. drop position completely or map to next best guess).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
GitPositionTransformer.BestPositionOnConflict
A strategy which tries to select the next suitableGitPositionTransformer.Position
on a conflicting mapping.static class
GitPositionTransformer.FileMapping
A mapping of attributes from a file in one Git tree (source) to a file in another Git tree (target).static class
GitPositionTransformer.Mapping
A mapping from aGitPositionTransformer.Position
in one Git commit/tree (source) to aGitPositionTransformer.Position
in another Git commit/tree (target).static class
GitPositionTransformer.OmitPositionOnConflict
A strategy which drops anyGitPositionTransformer.Position
s on a conflicting mapping.static class
GitPositionTransformer.Position
A position within the tree of a Git commit.static interface
GitPositionTransformer.PositionConflictStrategy
Strategy indicating how to handleGitPositionTransformer.Position
s for which mapping conflicts exist.static class
GitPositionTransformer.PositionedEntity<T>
Wrapper around an instance ofT
which annotates it with aGitPositionTransformer.Position
.static class
GitPositionTransformer.Range
A range.static class
GitPositionTransformer.RangeMapping
A mapping of a line range in one Git tree (source) to the corresponding line range in another Git tree (target).
-
Constructor Summary
Constructors Constructor Description GitPositionTransformer(GitPositionTransformer.PositionConflictStrategy positionConflictStrategy)
Creates a newGitPositionTransformer
which uses the specified strategy for conflicts.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> com.google.common.collect.ImmutableList<GitPositionTransformer.PositionedEntity<T>>
transform(Collection<GitPositionTransformer.PositionedEntity<T>> entities, Set<GitPositionTransformer.Mapping> mappings)
Transforms theGitPositionTransformer.Position
s of the specified entities as indicated via theGitPositionTransformer.Mapping
s.
-
-
-
Constructor Detail
-
GitPositionTransformer
public GitPositionTransformer(GitPositionTransformer.PositionConflictStrategy positionConflictStrategy)
Creates a newGitPositionTransformer
which uses the specified strategy for conflicts.
-
-
Method Detail
-
transform
public <T> com.google.common.collect.ImmutableList<GitPositionTransformer.PositionedEntity<T>> transform(Collection<GitPositionTransformer.PositionedEntity<T>> entities, Set<GitPositionTransformer.Mapping> mappings)
Transforms theGitPositionTransformer.Position
s of the specified entities as indicated via theGitPositionTransformer.Mapping
s.This is typically used to transform the
GitPositionTransformer.Position
s in one Git tree (source) to the correspondingGitPositionTransformer.Position
s in another Git tree (target). TheGitPositionTransformer.Mapping
s need to indicate all relevant changes between the source and target tree.GitPositionTransformer.Mapping
s for files not referenced by the givenGitPositionTransformer.Position
s need not be specified. They can be included, though, as they aren't harmful.- Type Parameters:
T
- an entity which has aGitPositionTransformer.Position
- Parameters:
entities
- the entities whoseGitPositionTransformer.Position
should be mapped to the target treemappings
- the mappings describing all relevant changes between the source and the target tree- Returns:
- a list of entities with transformed positions. There are no guarantees about the order of the returned elements.
-
-