<commit_before>import json

from dvc.command.base import CmdBase, DvcLock
from dvc.logger import Logger
from dvc.state_file import StateFile

class CmdMerge(CmdBase):
    def __init__(self, settings):
        super(CmdMerge, self).__init__(settings)

    def print_info(self, targets):
        for item in targets:
            Logger.info('Restored original data after merge:')
            Logger.info(' {}'.format(item.data.relative))

    def collect_targets(self):
        targets = []
        flist = self.git.get_last_merge_changed_files()
        items = self.settings.path_factory.to_data_items(flist)[0]

        for item in items:
            try:
                state = StateFile.load(item, self.git)
            except Exception as ex:
                Logger.error('Failed to load state file for {}'.format(item.data.relative), exc_info=True)
                return None

            if not state.command == StateFile.COMMAND_IMPORT_FILE:
                continue

            targets.append(item)

        return targets

    def checkout_targets(self, targets):
        data = []
        for item in targets:
            self.git.checkout_file_before_last_merge(item.data.relative)
            self.git.checkout_file_before_last_merge(item.state.relative)
            data.append(item.data.relative)

        msg = 'DVC merge files: {}'.format(' '.join(data))
        self.commit_if_needed(msg)

    def run(self):
        with DvcLock(self.is_locker, self.git):
            targets = self.collect_targets()
            if not targets:
                return 1

            self.checkout_targets(targets)
            self.print_info(targets)

            return 0
<commit_msg>dvc: fix 'dvc merge' command<commit_after>import os
import json

from dvc.command.base import CmdBase, DvcLock
from dvc.logger import Logger
from dvc.state_file import StateFile
from dvc.path.data_item import DataItem
from dvc.system import System

class CmdMerge(CmdBase):
    def __init__(self, settings):
        super(CmdMerge, self).__init__(settings)

    def print_info(self, targets):
        for item in targets:
            Logger.info('Restored original data after merge:')
            Logger.info(' {}'.format(item.data.relative))

    def collect_data(self):
        dlist = []
        flist = self.git.get_last_merge_changed_files()
        for fname in flist:
            if fname.startswith(self.settings.config.state_dir) and fname.endswith(DataItem.STATE_FILE_SUFFIX):
                data = os.path.relpath(fname, self.settings.config.state_dir)[:-len(DataItem.STATE_FILE_SUFFIX)]
                dlist.append(data)
        return dlist

    def collect_targets(self):
        targets = []
        flist = self.collect_data()
        items = self.settings.path_factory.to_data_items(flist)[0]

        for item in items:
            try:
                state = StateFile.load(item, self.git)
            except Exception as ex:
                Logger.error('Failed to load state file for {}'.format(item.data.relative), exc_info=True)
                return None

            if not state.command == StateFile.COMMAND_IMPORT_FILE:
                continue

            targets.append(item)

        return targets

    def checkout_targets(self, targets):
        data = []
        for item in targets:
            self.git.checkout_file_before_last_merge(item.state.relative)

            # Reload data item, so we can get restored cache
            new_item = self.settings.path_factory.data_item(item.data.relative)
            if os.path.isfile(new_item.data.relative):
                os.remove(new_item.data.relative)

            System.hardlink(new_item.cache.relative, new_item.data.relative)

            data.append(item.data.relative)

        msg = 'DVC merge files: {}'.format(' '.join(data))
        self.commit_if_needed(msg)

    def run(self):
        with DvcLock(self.is_locker, self.git):
            targets = self.collect_targets()
            if not targets:
                return 1

            self.checkout_targets(targets)
            self.print_info(targets)

            return 0

{'fraction_non_alphanumeric': 0.09293860713419073, 'fraction_numerical': 0.001455957291919437, 'mean_word_length': 2.1805555555555554, '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': '1029438', 'n_tokens_mistral': 1218, 'n_tokens_neox': 1160, 'n_words': 262}