def parse_diff(self):
        sections = []
        state = None

        prev_file = None
        current_file = {}
        current_hunks = []

        prev_hunk = None
        current_hunk = None

        for line in self.view.lines(sublime.Region(0, self.view.size())):
            linetext = self.view.substr(line)

            if linetext.startswith('diff --git'):
                state = 'header'
                # new file starts
                if prev_file != line:
                    if prev_file is not None:
                        if current_hunk:
                            current_hunks.append(current_hunk)
                        sections.append((current_file, current_hunks))
                    prev_file = line
                    prev_hunk = None

                current_file = line
                current_hunks = []
            elif state == 'header' and RE_DIFF_HEAD.match(linetext):
                current_file = current_file.cover(line)
            elif linetext.startswith('@@'):
                state = 'hunk'
                # new hunk starts
                if prev_hunk != line:
                    if prev_hunk is not None:
                        current_hunks.append(current_hunk)
                    prev_hunk = line

                current_hunk = line
            elif state == 'hunk' and linetext[0] in (' ', '-', '+'):
                current_hunk = current_hunk.cover(line)
            elif state == 'header':
                current_file = current_file.cover(line)

        if current_file and current_hunk:
            current_hunks.append(current_hunk)
            sections.append((current_file, current_hunks))
        return sections
dataset/ETHPy150Open SublimeGit/SublimeGit/sgit/diff.py/GitDiffTextCmd.parse_diff/original