Skip to content

Commit 49e205a

Browse files
Kosinkadinkampcode-comltdrdata
authored
feat: add pygit2 compatibility wrapper for standalone Desktop 2.0 installs (#2719)
* feat: add pygit2 compatibility wrapper for standalone Desktop 2.0 installs Add git_compat.py abstraction layer that wraps both GitPython and pygit2 behind a unified GitRepo interface. When CM_USE_PYGIT2=1 is set (by the Desktop 2.0 Launcher for standalone installs), or when system git is not available, the pygit2 backend is used automatically. Key changes: - New comfyui_manager/common/git_compat.py with abstract GitRepo base class, _GitPythonRepo (1:1 pass-throughs) and _Pygit2Repo implementations - All 6 non-legacy files updated to use the wrapper: - comfyui_manager/glob/manager_core.py (14 git.Repo usages) - comfyui_manager/common/git_helper.py (7 git.Repo usages) - comfyui_manager/common/context.py (1 usage) - comfyui_manager/glob/utils/environment_utils.py (2 usages) - cm_cli/__main__.py (1 usage) - comfyui_manager/common/timestamp_utils.py (repo.heads usage) - get_script_env() propagates CM_USE_PYGIT2 to subprocesses - git_helper.py uses sys.path.insert to find git_compat as standalone script - All repo handles wrapped in context managers to prevent resource leaks - get_head_by_name returns _HeadProxy for interface consistency - Submodule fallback logs clear message when system git is absent - 47 tests comparing both backends via subprocess isolation Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-019d0ec5-cb9f-74df-a1a2-0c8154a330b3 * fix(pygit2): address review findings + bump version to 4.2b1 - C1: add submodule_update() after pygit2 clone for recursive parity - C2: check subprocess returncode in submodule_update fallback - C3: move GIT_OPT_SET_OWNER_VALIDATION to module-level (once at import) - H1: use context manager in git_pull() to prevent resource leaks - Bump version to 4.2b1, version_code to [4, 2] - Add pygit2 to dev dependencies and requirements.txt * style: fix ruff F841 unused variable and F541 unnecessary f-string --------- Co-authored-by: Amp <amp@ampcode.com> Co-authored-by: Dr.Lt.Data <dr.lt.data@gmail.com>
1 parent 92e05fc commit 49e205a

11 files changed

Lines changed: 2061 additions & 400 deletions

File tree

cm_cli/__main__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from rich import print
1212
from typing_extensions import List, Annotated
1313
import re
14-
import git
1514
import importlib
1615

1716

@@ -62,9 +61,10 @@
6261

6362
def check_comfyui_hash():
6463
try:
65-
repo = git.Repo(comfy_path)
66-
core.comfy_ui_revision = len(list(repo.iter_commits('HEAD')))
67-
core.comfy_ui_commit_datetime = repo.head.commit.committed_datetime
64+
from comfyui_manager.common.git_compat import open_repo
65+
with open_repo(comfy_path) as repo:
66+
core.comfy_ui_revision = repo.iter_commits_count()
67+
core.comfy_ui_commit_datetime = repo.head_commit_datetime
6868
except Exception:
6969
print('[bold yellow]INFO: Frozen ComfyUI mode.[/bold yellow]')
7070
core.comfy_ui_revision = 0

comfyui_manager/common/context.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import logging
44
from . import manager_util
55
import toml
6-
import git
6+
from .git_compat import open_repo
77

88

99
# read env vars
@@ -98,8 +98,8 @@ def get_current_comfyui_ver():
9898

9999
def get_comfyui_tag():
100100
try:
101-
with git.Repo(comfy_path) as repo:
102-
return repo.git.describe('--tags')
101+
with open_repo(comfy_path) as repo:
102+
return repo.describe_tags()
103103
except Exception:
104104
return None
105105

0 commit comments

Comments
 (0)