Ejemplo n.º 1
0
    def test_diff_modifications(self):
        self.assertEqual(
            convert_line_numbers(['-', '-', '<', '>', '-', '-'], range(1, 6)),
            [1, 2, None, 4, 5])

        self.assertEqual(
            convert_line_numbers(['-', '-', '<', '<', '>', '-', '-'],
                                 range(2, 6)), [2, None, None, 4])

        self.assertEqual(
            convert_line_numbers(
                ['-', '-', '<', '<', '>', '>', '>', '-', '-', '-', '-'],
                range(5, 9)), [6, 7, 8, 9])
Ejemplo n.º 2
0
    def test_diff_modifications(self):
        self.assertEqual(convert_line_numbers(
            ['-', '-', '<', '>', '-', '-'],
            range(1, 6)),
            [1, 2, None, 4, 5])

        self.assertEqual(convert_line_numbers(
            ['-', '-', '<', '<', '>', '-', '-'],
            range(2, 6)),
            [2, None, None, 4])

        self.assertEqual(convert_line_numbers(
            ['-', '-', '<', '<', '>', '>', '>', '-', '-', '-', '-'],
            range(5, 9)),
            [6, 7, 8, 9])
Ejemplo n.º 3
0
def translate(old_commit, new_commit, filename, repo_path, inp):
    filename = relpath(filename, repo_path)
    repo_path = relpath(repo_path)

    try:
        git = Git(repo_path)
    except Exception as e:
        stderr.write(str(e))
        return

    # Load the line numbers and the times they have been looked at
    line_counts = loads(sub('\s', '', inp))
    # Put those line numbers in a dictionary so we can translate them to the new diff
    line_counts = dict((int(k), v) for k, v in line_counts.iteritems())

    diff = create_diff(old_content=git.get_file_content(filename, old_commit),
                       new_content=git.get_file_content(filename, new_commit))
    new_lines = convert_line_numbers(diff, line_counts.keys())

    result = {}

    for i, v in enumerate(line_counts.values()):
        if new_lines[i] is not None:
            result[new_lines[i]] = v

    return dumps(result)
Ejemplo n.º 4
0
def translate(old_commit, new_commit, filename, repo_path, inp):
    filename = relpath(filename, repo_path)
    repo_path = relpath(repo_path)

    try:
        git = Git(repo_path)
    except Exception as e:
        stderr.write(str(e))
        return

    # Load the line numbers and the times they have been looked at
    line_counts = loads(sub('\s', '', inp))
    # Put those line numbers in a dictionary so we can translate them to the new diff
    line_counts = dict((int(k), v) for k, v in line_counts.iteritems())

    diff = create_diff(
        old_content=git.get_file_content(filename, old_commit),
        new_content=git.get_file_content(filename, new_commit))
    new_lines = convert_line_numbers(diff, line_counts.keys())

    result = {}

    for i, v in enumerate(line_counts.values()):
        if new_lines[i] is not None:
            result[new_lines[i]] = v

    return dumps(result)
Ejemplo n.º 5
0
def send(filename, start, end, buffer, debug=False, use_repo_path=None):
    repo_path, server_url, new_filename = repo_url(filename)

    if use_repo_path:
        # we want to override the repo_path for some reason (testing usually)
        repo_path = use_repo_path

    if new_filename:
        filename = new_filename

    if use_repo_path:
        # if we have overriden it, our filepath is no longer relative
        filename = relpath(filename, repo_path)

    if server_url is None and not debug:
        return False

    try:
        git = Git(repo_path)
    except Exception as e:
        stderr.write(str(e))
        return None

    commit = git.get_last_pushed_commit()

    f = open(buffer, "r")
    wip = f.read()

    lines = convert_line_numbers(
        create_diff(
            old_content=wip,
            new_content=git.get_file_content(filename, commit)),
        lines=range(start, end + 1))
    lines = [x for x in lines if x is not None]

    payload = {
        "timestamp": int(time() * 1000),
        "file": normpath(filename).replace('\\', '/'),
        "name": git.name,
        "email": git.email,
        "branch": git.branch,
        "commit": commit,
        "lines[]": lines,
    }

    if not debug:
        try:
            conn = Connection(server_url)
            conn.post(path="/api/snapshot", payload=payload)
        except Exception as e:
            stderr.write(str(e))
            return False
    return dumps(payload)
Ejemplo n.º 6
0
 def test_diff_additions(self):
     self.assertEqual(
         convert_line_numbers(['-', '-', '>', '>', '-', '-'], range(1, 4)),
         [1, 2, 5])
Ejemplo n.º 7
0
 def test_diff_subtractions(self):
     self.assertEqual(
         convert_line_numbers(['-', '-', '<', '-', '<', '-', '-'],
                              range(2, 7)), [2, None, 3, None, 4])
Ejemplo n.º 8
0
 def test_diff_additions(self):
     self.assertEqual(convert_line_numbers(
         ['-', '-', '>', '>', '-', '-'],
         range(1, 4)),
         [1, 2, 5])
Ejemplo n.º 9
0
 def test_diff_subtractions(self):
     self.assertEqual(convert_line_numbers(
         ['-', '-', '<', '-', '<', '-', '-'],
         range(2, 7)),
         [2, None, 3, None, 4])