<commit_before>package de.setsoftware.reviewtool.changesources.svn;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;

import org.eclipse.core.runtime.OperationCanceledException;
import org.tmatesoft.svn.core.SVNDepth;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.wc.ISVNStatusHandler;
import org.tmatesoft.svn.core.wc.SVNClientManager;
import org.tmatesoft.svn.core.wc.SVNInfo;
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.wc.SVNStatus;

import de.setsoftware.reviewtool.base.Pair;
import de.setsoftware.reviewtool.diffalgorithms.DiffAlgorithmFactory;
import de.setsoftware.reviewtool.model.api.IChangeSourceUi;
import de.setsoftware.reviewtool.model.api.IMutableFileHistoryGraph;
import de.setsoftware.reviewtool.model.changestructure.FileHistoryGraph;

/**
 * Manages all known local working copies.
 */
final class SvnWorkingCopyManager {

    private static final SvnWorkingCopyManager INSTANCE = new SvnWorkingCopyManager();

    private final Map<String, SvnWorkingCopy> wcPerRootDirectory;
    private SVNClientManager mgr;

    /**
     * Constructor.
     */
    private SvnWorkingCopyManager() {
        this.wcPerRootDirectory = new LinkedHashMap<>();
    }

    /**
     * Returns the singleton instance of this class.
     */
    static SvnWorkingCopyManager getInstance() {
        return INSTANCE;
    }

    /**
     * Initializes the cache.
     * @param mgr The {@link SVNClientManager} for retrieving information about working copies.
     */
    void init(final SVNClientManager mgr) {
        this.mgr = mgr;
    }

    /**
     * Returns a read-only view of all known Subversion working copies.
     */
    synchronized Collection<SvnWorkingCopy> getWorkingCopies() {
        return Collections.unmodifiableCollection(this.wcPerRootDirectory.values());
    }

    /**
     * Returns a repository by its working copy root.
     * @param workingCopyRoot The root directory of the working copy.
     * @return A {@link SvnRepo} or {@code null} if not found.
     */
    synchronized SvnWorkingCopy getWorkingCopy(final File workingCopyRoot) {
        SvnWorkingCopy wc = this.wcPerRootDirectory.get(workingCopyRoot.toString());
        if (wc == null) {
            final SVNInfo wcInfo;
            try {
                wcInfo = this.mgr.getWCClient().doInfo(workingCopyRoot, SVNRevision.WORKING);
            } catch (final SVNException e) {
                // not a working copy
                // don't log this one as it is probably an unversioned project and hence not an error
                return null;
            }

            final SVNURL wcUrl = wcInfo.getURL();
            final SvnRepo repo = SvnRepositoryManager.getInstance().getRepo(wcUrl);
            if (repo == null) {
                return null;
            }

            wc = new SvnWorkingCopy(repo, workingCopyRoot);
            this.wcPerRootDirectory.put(workingCopyRoot.toString(), wc);
        }
        return wc;
    }
<commit_msg>fixed synchronisation bug<commit_after>package de.setsoftware.reviewtool.changesources.svn;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;

import org.eclipse.core.runtime.OperationCanceledException;
import org.tmatesoft.svn.core.SVNDepth;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.wc.ISVNStatusHandler;
import org.tmatesoft.svn.core.wc.SVNClientManager;
import org.tmatesoft.svn.core.wc.SVNInfo;
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.wc.SVNStatus;

import de.setsoftware.reviewtool.base.Pair;
import de.setsoftware.reviewtool.diffalgorithms.DiffAlgorithmFactory;
import de.setsoftware.reviewtool.model.api.IChangeSourceUi;
import de.setsoftware.reviewtool.model.api.IMutableFileHistoryGraph;
import de.setsoftware.reviewtool.model.changestructure.FileHistoryGraph;

/**
 * Manages all known local working copies.
 */
final class SvnWorkingCopyManager {

    private static final SvnWorkingCopyManager INSTANCE = new SvnWorkingCopyManager();

    private final Map<String, SvnWorkingCopy> wcPerRootDirectory;
    private SVNClientManager mgr;

    /**
     * Constructor.
     */
    private SvnWorkingCopyManager() {
        this.wcPerRootDirectory = new LinkedHashMap<>();
    }

    /**
     * Returns the singleton instance of this class.
     */
    static SvnWorkingCopyManager getInstance() {
        return INSTANCE;
    }

    /**
     * Initializes the cache.
     * @param mgr The {@link SVNClientManager} for retrieving information about working copies.
     */
    void init(final SVNClientManager mgr) {
        this.mgr = mgr;
    }

    /**
     * Returns a read-only view of all known Subversion working copies.
     */
    synchronized Collection<SvnWorkingCopy> getWorkingCopies() {
        return Collections.unmodifiableCollection(new ArrayList<>(this.wcPerRootDirectory.values()));
    }

    /**
     * Returns a repository by its working copy root.
     * @param workingCopyRoot The root directory of the working copy.
     * @return A {@link SvnRepo} or {@code null} if not found.
     */
    synchronized SvnWorkingCopy getWorkingCopy(final File workingCopyRoot) {
        SvnWorkingCopy wc = this.wcPerRootDirectory.get(workingCopyRoot.toString());
        if (wc == null) {
            final SVNInfo wcInfo;
            try {
                wcInfo = this.mgr.getWCClient().doInfo(workingCopyRoot, SVNRevision.WORKING);
            } catch (final SVNException e) {
                // not a working copy
                // don't log this one as it is probably an unversioned project and hence not an error
                return null;
            }

            final SVNURL wcUrl = wcInfo.getURL();
            final SvnRepo repo = SvnRepositoryManager.getInstance().getRepo(wcUrl);
            if (repo == null) {
                return null;
            }

            wc = new SvnWorkingCopy(repo, workingCopyRoot);
            this.wcPerRootDirectory.put(workingCopyRoot.toString(), wc);
        }
        return wc;
    }

{'fraction_non_alphanumeric': 0.09315733576088606, 'fraction_numerical': 0.0, 'mean_word_length': 2.995151515151515, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '836940', 'n_tokens_mistral': 1991, 'n_tokens_neox': 1933, 'n_words': 445}