view hgext/git/gitutil.py @ 52616:b798ad65ced8

git: add stubs for dirstate methods $ hg log ** unknown exception encountered, please report by visiting ** https://mercurial-scm.org/wiki/BugTracker ** Python 3.11.10 (main, Oct 31 2024, 01:10:40) [Clang 18.1.5 (https://github.com/llvm/llvm-project.git llvmorg-18.1.5-0-g617a15 ** Mercurial Distributed SCM (version 6.9.post1.dev337+hg.72af9fa34832) ** Extensions loaded: absorb, churn, git (pygit2 1.14.1), githelp, gpg, hgk, histedit, patchbomb, rebase Traceback (most recent call last): File "/home/jeffpc/src/oss/hg-gitext-test/../hg-gitext/hg", line 61, in <module> dispatch.run() ... File "/usr/home/jeffpc/src/oss/hg-gitext/mercurial/localrepo.py", line 1789, in changelog repo.dirstate.prefetch_parents() ^^^^^^^^^^^^^ File "/usr/home/jeffpc/src/oss/hg-gitext/mercurial/localrepo.py", line 225, in __get__ return super(unfilteredpropertycache, self).__get__(unfi) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/home/jeffpc/src/oss/hg-gitext/mercurial/util.py", line 1822, in __get__ result = self.func(obj) ^^^^^^^^^^^^^^ File "/usr/home/jeffpc/src/oss/hg-gitext/mercurial/localrepo.py", line 1802, in dirstate self._dirstate = self._makedirstate() ^^^^^^^^^^^^^^^^^^^^ File "/usr/home/jeffpc/src/oss/hg-gitext/hgext/git/__init__.py", line 311, in _makedirstate return dirstate.gitdirstate( ^^^^^^^^^^^^^^^^^^^^^ TypeError: Can't instantiate abstract class gitdirstate with abstract methods _checkexec, _ignorefileandline, changing_files, clear, copy, hasdir, invalidate, is_changing_files, rebuild, verify
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Thu, 02 Jan 2025 10:46:37 -0500
parents f4733654f144
children
line wrap: on
line source

"""utilities to assist in working with pygit2"""

from __future__ import annotations

from mercurial.node import bin, sha1nodeconstants

pygit2_module = None


def get_pygit2():
    global pygit2_module
    if pygit2_module is None:
        try:
            import pygit2 as pygit2_module  # pytype: disable=import-error

            pygit2_module.InvalidSpecError
        except (ImportError, AttributeError):
            pass
    return pygit2_module


def pygit2_version():
    mod = get_pygit2()
    v = "N/A"

    if mod:
        try:
            v = mod.__version__
        except AttributeError:
            pass

    return b"(pygit2 %s)" % v.encode("utf-8")


def togitnode(n):
    """Wrapper to convert a Mercurial binary node to a unicode hexlified node.

    pygit2 and sqlite both need nodes as strings, not bytes.
    """
    assert len(n) == 20
    return n.hex()


def fromgitnode(n):
    """Opposite of togitnode."""
    assert len(n) == 40
    return bin(n)


nullgit = togitnode(sha1nodeconstants.nullid)