Class GitPositionTransformer
GitPositionTransformer.Positions in one Git tree to GitPositionTransformer.Positions in another Git tree given
the GitPositionTransformer.Mappings between the trees.
The base idea is that a GitPositionTransformer.Position in the source tree can be translated/mapped to a
corresponding GitPositionTransformer.Position in the target tree when we know how the target tree changed
compared to the source tree. As long as GitPositionTransformer.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 ClassesModifier and TypeClassDescriptionstatic enumA strategy which tries to select the next suitableGitPositionTransformer.Positionon a conflicting mapping.static classA mapping of attributes from a file in one Git tree (source) to a file in another Git tree (target).static classA mapping from aGitPositionTransformer.Positionin one Git commit/tree (source) to aGitPositionTransformer.Positionin another Git commit/tree (target).static enumA strategy which drops anyGitPositionTransformer.Positions on a conflicting mapping.static classA position within the tree of a Git commit.static interfaceStrategy indicating how to handleGitPositionTransformer.Positions for which mapping conflicts exist.static classWrapper around an instance ofTwhich annotates it with aGitPositionTransformer.Position.static classA range.static classA mapping of a line range in one Git tree (source) to the corresponding line range in another Git tree (target). -
Constructor Summary
ConstructorsConstructorDescriptionGitPositionTransformer(GitPositionTransformer.PositionConflictStrategy positionConflictStrategy) Creates a newGitPositionTransformerwhich uses the specified strategy for conflicts. -
Method Summary
Modifier and TypeMethodDescription<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 Details
-
GitPositionTransformer
public GitPositionTransformer(GitPositionTransformer.PositionConflictStrategy positionConflictStrategy) Creates a newGitPositionTransformerwhich uses the specified strategy for conflicts.
-
-
Method Details
-
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.
-