Class GitPositionTransformer
- java.lang.Object
-
- com.google.gerrit.server.patch.GitPositionTransformer
-
public class GitPositionTransformer extends Object
Transformer ofGitPositionTransformer.Positions in one Git tree toGitPositionTransformer.Positions in another Git tree given theGitPositionTransformer.Mappings between the trees.The base idea is that a
GitPositionTransformer.Positionin the source tree can be translated/mapped to a correspondingGitPositionTransformer.Positionin the target tree when we know how the target tree changed compared to the source tree. As long asGitPositionTransformer.Positions 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 classGitPositionTransformer.BestPositionOnConflictA strategy which tries to select the next suitableGitPositionTransformer.Positionon a conflicting mapping.static classGitPositionTransformer.FileMappingA mapping of attributes from a file in one Git tree (source) to a file in another Git tree (target).static classGitPositionTransformer.MappingA mapping from aGitPositionTransformer.Positionin one Git commit/tree (source) to aGitPositionTransformer.Positionin another Git commit/tree (target).static classGitPositionTransformer.OmitPositionOnConflictA strategy which drops anyGitPositionTransformer.Positions on a conflicting mapping.static classGitPositionTransformer.PositionA position within the tree of a Git commit.static interfaceGitPositionTransformer.PositionConflictStrategyStrategy indicating how to handleGitPositionTransformer.Positions for which mapping conflicts exist.static classGitPositionTransformer.PositionedEntity<T>Wrapper around an instance ofTwhich annotates it with aGitPositionTransformer.Position.static classGitPositionTransformer.RangeA range.static classGitPositionTransformer.RangeMappingA 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 newGitPositionTransformerwhich 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.Positions of the specified entities as indicated via theGitPositionTransformer.Mappings.
-
-
-
Constructor Detail
-
GitPositionTransformer
public GitPositionTransformer(GitPositionTransformer.PositionConflictStrategy positionConflictStrategy)
Creates a newGitPositionTransformerwhich 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.Positions of the specified entities as indicated via theGitPositionTransformer.Mappings.This is typically used to transform the
GitPositionTransformer.Positions in one Git tree (source) to the correspondingGitPositionTransformer.Positions in another Git tree (target). TheGitPositionTransformer.Mappings need to indicate all relevant changes between the source and target tree.GitPositionTransformer.Mappings for files not referenced by the givenGitPositionTransformer.Positions 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.Positionshould 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.
-
-