Example #1
0
def print_diff(diff):
    """Prints colored diff.
    """
    for line in diff.split("\n"):
        line = unicode(line).encode("utf-8")
        if line.startswith("+"):
            puts(colored.green(line))
        elif line.startswith("-"):
            puts(colored.red(line))
        else:
            puts(line)
Example #2
0
def clean_diff(diff):
    """Removes diff header from a diff.
    """
    res = []
    skip = True
    for line in diff.split("\n"):
        if line.startswith("diff --git"):
            skip = True
        if line.startswith("@@ "):
            skip = False
        if not skip:
            res.append(line)
    return "\n".join(res)
Example #3
0
def get_chunks(diff):
    """Returns a list with all the chunks in this diff.
    """
    diff = clean_diff(diff)
    chunk = []
    chunks = []
    for line in diff.split("\n"):
        if not line:
            continue
        if line.startswith("@@ "):
            if chunk:
                chunks.append("\n".join(chunk) + "\n")
            chunk = [line]
        else:
            chunk.append(line)
    if chunk:
        chunks.append("\n".join(chunk) + "\n")
    return chunks