Class GitPositionTransformer


  • public class GitPositionTransformer
    extends Object
    Transformer of 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:

    1. 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).
    2. 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).