# Path: meld/vc/_vc.py
# (STATE_IGNORED, STATE_NONE, STATE_NORMAL, STATE_NOCHANGE,
#     STATE_ERROR, STATE_EMPTY, STATE_NEW,
#     STATE_MODIFIED, STATE_RENAMED, STATE_CONFLICT, STATE_REMOVED,
#     STATE_MISSING, STATE_NONEXIST, STATE_SPINNER, STATE_MAX) = list(range(15))
# (CONFLICT_MERGED, CONFLICT_BASE, CONFLICT_LOCAL,
#     CONFLICT_REMOTE, CONFLICT_MAX) = list(range(5))
# CONFLICT_OTHER = CONFLICT_REMOTE
# CONFLICT_THIS = CONFLICT_LOCAL
#     VC_DIR: ClassVar[str]
#     VC_ROOT_WALK: ClassVar[bool] = True
# def partition(pred, iterable):
#     def __init__(self, path, name, state, isdir, options=None):
#     def __str__(self):
#     def __repr__(self):
#     def get_status(self):
#     def is_present(self):
#     def is_modified(entry):
#     def is_normal(entry):
#     def is_nonvc(entry):
#     def is_ignored(entry):
#     def __init__(self, path):
#     def run(self, *args, use_locale_encoding=True):
#     def get_files_to_commit(self, paths):
#     def get_commit_message_prefill(self):
#     def get_commits_to_push_summary(self):
#     def get_valid_actions(self, path_states):
#     def get_path_for_repo_file(self, path, commit=None):
#     def get_path_for_conflict(self, path, conflict):
#     def refresh_vc_state(self, path=None):
#     def get_entries(self, base):
#     def _add_missing_cache_entry(self, path, state):
#     def get_entry(self, path):
#     def is_installed(cls):
#     def is_in_repo(cls, path):
#     def check_repo_root(cls, location):
#     def find_repo_root(cls, location):
#     def valid_repo(cls, path):
#     def __init__(self, vc, path, err):
#     def __str__(self):
#     def __init__(self, vc, rev, err):
#     def __str__(self):
# def popen(cmd, cwd=None, use_locale_encoding=True):
# def call_temp_output(cmd, cwd, file_id='', suffix=None):
# def call(cmd, cwd=None):
# def base_from_diff3(merged):
# class Entry:
# class Vc:
# class InvalidVCPath(ValueError):
# class InvalidVCRevision(ValueError):


import os
from gi.module import get_introspection_module
from gi.repository import Gdk, GLib, GObject, Pango
from meld.style import colour_lookup_with_fallback
from meld.treehelpers import SearchableTreeStore
from meld.vc._vc import (  # noqa: F401
    CONFLICT_BASE,
    CONFLICT_LOCAL,
    CONFLICT_MERGED,
    CONFLICT_OTHER,
    CONFLICT_REMOTE,
    CONFLICT_THIS,
    STATE_CONFLICT,
    STATE_EMPTY,
    STATE_ERROR,
    STATE_IGNORED,
    STATE_MAX,
    STATE_MISSING,
    STATE_MODIFIED,
    STATE_NEW,
    STATE_NOCHANGE,
    STATE_NONE,
    STATE_NONEXIST,
    STATE_NORMAL,
    STATE_REMOVED,
    STATE_SPINNER,
)
    def value_path(self, it, pane):
        return self.get_value(it, self.column_index(COL_PATH, pane))

    def is_folder(self, it, pane, path):
        # A folder may no longer exist, and is only tracked by VC.
        # Therefore, check the icon instead, as the pane already knows.
        icon = self.get_value(it, self.column_index(COL_ICON, pane))
        return icon == "folder" or (bool(path) and os.path.isdir(path))

    def column_index(self, col, pane):
        return self.ntree * col + pane

    def add_entries(self, parent, names):
        it = self.append(parent)
        for pane, path in enumerate(names):
            self.unsafe_set(it, pane, {COL_PATH: path})
        return it

    def add_empty(self, parent, text="empty folder"):
        it = self.append(parent)
        for pane in range(self.ntree):
            self.set_state(it, pane, STATE_EMPTY, text)
        return it

    def add_error(self, parent, msg, pane, defaults={}):
        it = self.append(parent)
        key_values = {COL_STATE: str(STATE_ERROR)}
        key_values.update(defaults)
        for i in range(self.ntree):
            self.unsafe_set(it, i, key_values)

# Path: meld/vc/_vc.py
# (STATE_IGNORED, STATE_NONE, STATE_NORMAL, STATE_NOCHANGE,
#     STATE_ERROR, STATE_EMPTY, STATE_NEW,
#     STATE_MODIFIED, STATE_RENAMED, STATE_CONFLICT, STATE_REMOVED,
#     STATE_MISSING, STATE_NONEXIST, STATE_SPINNER, STATE_MAX) = list(range(15))
# (CONFLICT_MERGED, CONFLICT_BASE, CONFLICT_LOCAL,
#     CONFLICT_REMOTE, CONFLICT_MAX) = list(range(5))
# CONFLICT_OTHER = CONFLICT_REMOTE
# CONFLICT_THIS = CONFLICT_LOCAL
#     VC_DIR: ClassVar[str]
#     VC_ROOT_WALK: ClassVar[bool] = True
# def partition(pred, iterable):
#     def __init__(self, path, name, state, isdir, options=None):
#     def __str__(self):
#     def __repr__(self):
#     def get_status(self):
#     def is_present(self):
#     def is_modified(entry):
#     def is_normal(entry):
#     def is_nonvc(entry):
#     def is_ignored(entry):
#     def __init__(self, path):
#     def run(self, *args, use_locale_encoding=True):
#     def get_files_to_commit(self, paths):
#     def get_commit_message_prefill(self):
#     def get_commits_to_push_summary(self):
#     def get_valid_actions(self, path_states):
#     def get_path_for_repo_file(self, path, commit=None):
#     def get_path_for_conflict(self, path, conflict):
#     def refresh_vc_state(self, path=None):
#     def get_entries(self, base):
#     def _add_missing_cache_entry(self, path, state):
#     def get_entry(self, path):
#     def is_installed(cls):
#     def is_in_repo(cls, path):
#     def check_repo_root(cls, location):
#     def find_repo_root(cls, location):
#     def valid_repo(cls, path):
#     def __init__(self, vc, path, err):
#     def __str__(self):
#     def __init__(self, vc, rev, err):
#     def __str__(self):
# def popen(cmd, cwd=None, use_locale_encoding=True):
# def call_temp_output(cmd, cwd, file_id='', suffix=None):
# def call(cmd, cwd=None):
# def base_from_diff3(merged):
# class Entry:
# class Vc:
# class InvalidVCPath(ValueError):
# class InvalidVCRevision(ValueError):


# Path: meld/tree.py
import os
from gi.module import get_introspection_module
from gi.repository import Gdk, GLib, GObject, Pango
from meld.style import colour_lookup_with_fallback
from meld.treehelpers import SearchableTreeStore
from meld.vc._vc import (  # noqa: F401
    CONFLICT_BASE,
    CONFLICT_LOCAL,
    CONFLICT_MERGED,
    CONFLICT_OTHER,
    CONFLICT_REMOTE,
    CONFLICT_THIS,
    STATE_CONFLICT,
    STATE_EMPTY,
    STATE_ERROR,
    STATE_IGNORED,
    STATE_MAX,
    STATE_MISSING,
    STATE_MODIFIED,
    STATE_NEW,
    STATE_NOCHANGE,
    STATE_NONE,
    STATE_NONEXIST,
    STATE_NORMAL,
    STATE_REMOVED,
    STATE_SPINNER,
)

    def value_path(self, it, pane):
        return self.get_value(it, self.column_index(COL_PATH, pane))

    def is_folder(self, it, pane, path):
        # A folder may no longer exist, and is only tracked by VC.
        # Therefore, check the icon instead, as the pane already knows.
        icon = self.get_value(it, self.column_index(COL_ICON, pane))
        return icon == "folder" or (bool(path) and os.path.isdir(path))

    def column_index(self, col, pane):
        return self.ntree * col + pane

    def add_entries(self, parent, names):
        it = self.append(parent)
        for pane, path in enumerate(names):
            self.unsafe_set(it, pane, {COL_PATH: path})
        return it

    def add_empty(self, parent, text="empty folder"):
        it = self.append(parent)
        for pane in range(self.ntree):
            self.set_state(it, pane, STATE_EMPTY, text)
        return it

    def add_error(self, parent, msg, pane, defaults={}):
        it = self.append(parent)
        key_values = {COL_STATE: str(STATE_ERROR)}
        key_values.update(defaults)
        for i in range(self.ntree):
            self.unsafe_set(it, i, key_values)

        self.set_state(it, pane, STATE_ERROR, msg)