Mercurial > public > mercurial-scm > hg
annotate 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 |
rev | line source |
---|---|
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1 """utilities to assist in working with pygit2""" |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
2 |
51859
f4733654f144
typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents:
49849
diff
changeset
|
3 from __future__ import annotations |
f4733654f144
typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents:
49849
diff
changeset
|
4 |
49300
227124098e14
py3: use `x.hex()` instead of `pycompat.sysstr(node.hex(x))`
Manuel Jacob <me@manueljacob.de>
parents:
49290
diff
changeset
|
5 from mercurial.node import bin, sha1nodeconstants |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
6 |
44484
ec54b3d2af0b
git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents:
44477
diff
changeset
|
7 pygit2_module = None |
ec54b3d2af0b
git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents:
44477
diff
changeset
|
8 |
ec54b3d2af0b
git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents:
44477
diff
changeset
|
9 |
ec54b3d2af0b
git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents:
44477
diff
changeset
|
10 def get_pygit2(): |
ec54b3d2af0b
git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents:
44477
diff
changeset
|
11 global pygit2_module |
ec54b3d2af0b
git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents:
44477
diff
changeset
|
12 if pygit2_module is None: |
ec54b3d2af0b
git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents:
44477
diff
changeset
|
13 try: |
49849
de9ffb82ef4d
typing: suppress a bunch of potential import-error cases in extensions
Matt Harbison <matt_harbison@yahoo.com>
parents:
49300
diff
changeset
|
14 import pygit2 as pygit2_module # pytype: disable=import-error |
44484
ec54b3d2af0b
git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents:
44477
diff
changeset
|
15 |
ec54b3d2af0b
git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents:
44477
diff
changeset
|
16 pygit2_module.InvalidSpecError |
ec54b3d2af0b
git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents:
44477
diff
changeset
|
17 except (ImportError, AttributeError): |
ec54b3d2af0b
git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents:
44477
diff
changeset
|
18 pass |
ec54b3d2af0b
git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents:
44477
diff
changeset
|
19 return pygit2_module |
ec54b3d2af0b
git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents:
44477
diff
changeset
|
20 |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
21 |
45950
c7c1efdfd4de
git: show the version of `pygit2` with verbose version output
Matt Harbison <matt_harbison@yahoo.com>
parents:
44484
diff
changeset
|
22 def pygit2_version(): |
c7c1efdfd4de
git: show the version of `pygit2` with verbose version output
Matt Harbison <matt_harbison@yahoo.com>
parents:
44484
diff
changeset
|
23 mod = get_pygit2() |
c7c1efdfd4de
git: show the version of `pygit2` with verbose version output
Matt Harbison <matt_harbison@yahoo.com>
parents:
44484
diff
changeset
|
24 v = "N/A" |
c7c1efdfd4de
git: show the version of `pygit2` with verbose version output
Matt Harbison <matt_harbison@yahoo.com>
parents:
44484
diff
changeset
|
25 |
c7c1efdfd4de
git: show the version of `pygit2` with verbose version output
Matt Harbison <matt_harbison@yahoo.com>
parents:
44484
diff
changeset
|
26 if mod: |
c7c1efdfd4de
git: show the version of `pygit2` with verbose version output
Matt Harbison <matt_harbison@yahoo.com>
parents:
44484
diff
changeset
|
27 try: |
c7c1efdfd4de
git: show the version of `pygit2` with verbose version output
Matt Harbison <matt_harbison@yahoo.com>
parents:
44484
diff
changeset
|
28 v = mod.__version__ |
c7c1efdfd4de
git: show the version of `pygit2` with verbose version output
Matt Harbison <matt_harbison@yahoo.com>
parents:
44484
diff
changeset
|
29 except AttributeError: |
c7c1efdfd4de
git: show the version of `pygit2` with verbose version output
Matt Harbison <matt_harbison@yahoo.com>
parents:
44484
diff
changeset
|
30 pass |
c7c1efdfd4de
git: show the version of `pygit2` with verbose version output
Matt Harbison <matt_harbison@yahoo.com>
parents:
44484
diff
changeset
|
31 |
c7c1efdfd4de
git: show the version of `pygit2` with verbose version output
Matt Harbison <matt_harbison@yahoo.com>
parents:
44484
diff
changeset
|
32 return b"(pygit2 %s)" % v.encode("utf-8") |
c7c1efdfd4de
git: show the version of `pygit2` with verbose version output
Matt Harbison <matt_harbison@yahoo.com>
parents:
44484
diff
changeset
|
33 |
c7c1efdfd4de
git: show the version of `pygit2` with verbose version output
Matt Harbison <matt_harbison@yahoo.com>
parents:
44484
diff
changeset
|
34 |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
35 def togitnode(n): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
36 """Wrapper to convert a Mercurial binary node to a unicode hexlified node. |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
37 |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
38 pygit2 and sqlite both need nodes as strings, not bytes. |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
39 """ |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
40 assert len(n) == 20 |
49300
227124098e14
py3: use `x.hex()` instead of `pycompat.sysstr(node.hex(x))`
Manuel Jacob <me@manueljacob.de>
parents:
49290
diff
changeset
|
41 return n.hex() |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
42 |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
43 |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
44 def fromgitnode(n): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
45 """Opposite of togitnode.""" |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
46 assert len(n) == 40 |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
47 return bin(n) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
48 |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
49 |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
45950
diff
changeset
|
50 nullgit = togitnode(sha1nodeconstants.nullid) |