def get_diff_index(patch, line_nr):
    """
    Takes a patch and receives the position of the given line number in it.

    >>> patch = ('---/version/a\\n'
    ...          '+++/version/b\\n'
    ...          '@@ -1,2 +1,4 @@\\n'
    ...          ' # test\\n'  # Line 1
    ...          '+\\n'  # Line 2
    ...          '-a test repo\\n'  # Line 3
    ...          '+something new\\n'  # Line 3
    ...          ' something old\\n')  # Line 4
    >>> get_diff_index(patch, 1)
    1
    >>> get_diff_index(patch, 3)
    4
    >>> get_diff_index(patch, 4)
    5

    If the line isn't covered in the patch, it'll return None:

    >>> get_diff_index(patch, 8)

    Sometimes patches contain the function and shall still be interpreted
    correctly:

    >>> patch = ('@@ -464,11 +464,10 @@ def get_action_info(section, action):\\n'
    ...          ' line 464\\n'
    ...          ' line 465\\n'
    ...          ' line 466\\n'
    ...          '-line 467\\n'
    ...          '-line 468\\n'
    ...          '+line 467\\n'
    ...          '+line 468\\n'
    ...          ' line 469\\n')
    >>> get_diff_index(patch, 465)
    2
    >>> get_diff_index(patch, 467)
    6

    :param patch: A list of lines of a unified diff.
    :param line_nr: The line number to identify.
    :return: The position in the Patch or None
    """
    patch = patch.splitlines(True)
    current_line_added = 0
    current_diff_index = 0
    for line in patch:
        if line.startswith('---') or line.startswith('+++'):
            continue
        if line.startswith('@@'):
            values = line[line.find('-'):line.find(' @@', 3)]
            _, added = tuple(values.split(' '))
            current_line_added = int(added.split(',')[0][1:])
        elif line.startswith('+') or line.startswith(' '):
            if current_line_added == line_nr:
                return current_diff_index
            current_line_added += 1
        current_diff_index += 1
    return None
