<commit_before>import re
from subprocess import Popen, PIPE


class AdditionsFinder(object):
    @staticmethod
    def get_additions_for_base(base, repository_path):
        additions = {}

        command = ['git', 'diff', base, '--unified=0']

        process = Popen(command, stdout=PIPE, cwd=repository_path)
        raw_diff = process.communicate()[0]

        raw_diff_files = re.split('\ndiff', raw_diff)
        raw_diff_files = filter(None, raw_diff_files)  # remove empty elements from list

        for raw_diff_file in raw_diff_files:
            file_name_matches = re.findall(r'\nindex .*\n.*\n\+\+\+ b/(.*)\n', raw_diff_file, re.MULTILINE)

            # /dev/null matches
            if len(file_name_matches) == 0:
                continue

            file_name = file_name_matches[0]
            additions[file_name] = []
            chunks = re.findall(r'^@@ .* \+(.*[^,0]) @@', raw_diff_file, re.MULTILINE)
            for chunk in reversed(chunks):
                lines_range = chunk.split(',')
                if len(lines_range) == 2:
                    additions[file_name] += range(int(lines_range[0]), int(lines_range[0]) + int(lines_range[1]))<commit_msg>fix regex for '@@ -a,b +c,d @@'<commit_after>import re
from subprocess import Popen, PIPE


class AdditionsFinder(object):
    @staticmethod
    def get_additions_for_base(base, repository_path):
        additions = {}

        command = ['git', 'diff', base, '--unified=0']

        process = Popen(command, stdout=PIPE, cwd=repository_path)
        raw_diff = process.communicate()[0]

        raw_diff_files = re.split('\ndiff', raw_diff)
        raw_diff_files = filter(None, raw_diff_files)  # remove empty elements from list

        for raw_diff_file in raw_diff_files:
            file_name_matches = re.findall(r'\nindex .*\n.*\n\+\+\+ b/(.*)\n', raw_diff_file, re.MULTILINE)

            # /dev/null matches
            if len(file_name_matches) == 0:
                continue

            file_name = file_name_matches[0]
            additions[file_name] = []
            chunks = re.findall(r'^@@ .* \+(\d+,[1-9]\d*) @@', raw_diff_file, re.MULTILINE)
            for chunk in reversed(chunks):
                lines_range = chunk.split(',')
                if len(lines_range) == 2:
                    additions[file_name] += range(int(lines_range[0]), int(lines_range[0]) + int(lines_range[1]))
{'fraction_non_alphanumeric': 0.1404095277893857, 'fraction_numerical': 0.007939824488090262, 'mean_word_length': 2.4297994269340975, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3465943', 'n_tokens_mistral': 805, 'n_tokens_neox': 768, 'n_words': 150}