Skip to content

Commit a1e085d

Browse files
authored
Merge pull request #68 from FalkorDB/fix-staging
move to pygit2
2 parents 250ddea + 561ebcb commit a1e085d

File tree

6 files changed

+82
-85
lines changed

6 files changed

+82
-85
lines changed

api/git_utils/git_graph.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import os
22
import logging
3-
from git import Commit
43
from falkordb import FalkorDB, Node
54
from typing import List, Optional
65

6+
from pygit2 import Commit
7+
78
# Configure logging
89
logging.basicConfig(level=logging.DEBUG, format='%(filename)s - %(asctime)s - %(levelname)s - %(message)s')
910

@@ -112,7 +113,7 @@ def connect_commits(self, child: str, parent: str) -> None:
112113
self.g.query(q, params)
113114

114115

115-
def set_parent_transition(self, child: str, parent: str, queries: [str], params: [str]) -> None:
116+
def set_parent_transition(self, child: str, parent: str, queries: list[str], params: list[str]) -> None:
116117
"""
117118
Sets the queries and parameters needed to transition the code-graph
118119
from the child commit to the parent commit
@@ -126,7 +127,7 @@ def set_parent_transition(self, child: str, parent: str, queries: [str], params:
126127
self.g.query(q, _params)
127128

128129

129-
def set_child_transition(self, child: str, parent: str, queries: [str], params: [str]) -> None:
130+
def set_child_transition(self, child: str, parent: str, queries: list[str], params: list[str]) -> None:
130131
"""
131132
Sets the queries and parameters needed to transition the code-graph
132133
from the parent commit to the child commit

api/git_utils/git_utils.py

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import os
22
import json
33
import logging
4+
5+
from pygit2 import Commit
46
from ..info import *
5-
from git import Repo
7+
from pygit2.repository import Repository
68
from pathlib import Path
79
from ..graph import Graph
810
from .git_graph import GitGraph
@@ -85,9 +87,9 @@ def build_commit_graph(path: str, repo_name: str, ignore_list: Optional[List[str
8587

8688
# Initialize with the current commit
8789
# Save current git for later restoration
88-
repo = Repo('.')
89-
current_commit = repo.head.commit
90-
current_commit_hexsha = current_commit.hexsha
90+
repo = Repository('.')
91+
current_commit = repo.walk(repo.head.target).__next__()
92+
current_commit_hexsha = current_commit.hex
9193

9294
# Add commit to the git graph
9395
git_graph.add_commit(current_commit)
@@ -106,7 +108,7 @@ def build_commit_graph(path: str, repo_name: str, ignore_list: Optional[List[str
106108
git_graph.add_commit(parent_commit)
107109

108110
# connect child parent commits relation
109-
git_graph.connect_commits(child_commit.hexsha, parent_commit.hexsha)
111+
git_graph.connect_commits(child_commit.hex, parent_commit.hex)
110112

111113
# Represents the changes going backward!
112114
# e.g. which files need to be deleted when moving back one commit
@@ -126,7 +128,7 @@ def build_commit_graph(path: str, repo_name: str, ignore_list: Optional[List[str
126128

127129
# Checkout prev commit
128130
logging.info(f"Checking out commit: {parent_commit.hexsha}")
129-
repo.git.checkout(parent_commit.hexsha)
131+
repo.checkout(parent_commit.hex)
130132

131133
#-----------------------------------------------------------------------
132134
# Apply changes going backwards
@@ -165,15 +167,15 @@ def build_commit_graph(path: str, repo_name: str, ignore_list: Optional[List[str
165167

166168
# Log transitions
167169
logging.debug(f"""Save graph transition from
168-
commit: {child_commit.hexsha}
170+
commit: {child_commit.hex}
169171
to
170-
commit: {parent_commit.hexsha}
172+
commit: {parent_commit.hex}
171173
Queries: {queries}
172174
Parameters: {params}
173175
""")
174176

175-
git_graph.set_parent_transition(child_commit.hexsha,
176-
parent_commit.hexsha, queries, params)
177+
git_graph.set_parent_transition(child_commit.hex,
178+
parent_commit.hex, queries, params)
177179
# advance to the next commit
178180
child_commit = parent_commit
179181

@@ -183,24 +185,24 @@ def build_commit_graph(path: str, repo_name: str, ignore_list: Optional[List[str
183185

184186
logging.info("Computing transition queries moving forward")
185187
parent_commit = child_commit
186-
while parent_commit.hexsha != current_commit_hexsha:
187-
child_commit = git_graph.get_child_commit(parent_commit.hexsha)
188-
child_commit = repo.commit(child_commit['hash'])
188+
while parent_commit.hex != current_commit_hexsha:
189+
child_commit = git_graph.get_child_commit(parent_commit.hex)
190+
child_commit = repo.walk(child_commit['hash']).__next__()
189191

190192
# Represents the changes going forward
191193
# e.g. which files need to be deleted when moving forward one commit
192194

193195
# Process file changes in this commit
194196
logging.info(f"""Computing diff between
195-
child {parent_commit.hexsha}: {parent_commit.message}
196-
and {child_commit.hexsha}: {child_commit.message}""")
197+
child {parent_commit.hex}: {parent_commit.message}
198+
and {child_commit.hex}: {child_commit.message}""")
197199

198-
diff = parent_commit.diff(child_commit)
200+
diff = repo.diff(parent_commit, child_commit)
199201
added, deleted, modified = classify_changes(diff, ignore_list)
200202

201203
# Checkout child commit
202-
logging.info(f"Checking out commit: {child_commit.hexsha}")
203-
repo.git.checkout(child_commit.hexsha)
204+
logging.info(f"Checking out commit: {child_commit.hex}")
205+
repo.checkout(child_commit.hex)
204206

205207
#-----------------------------------------------------------------------
206208
# Apply changes going forward
@@ -239,15 +241,15 @@ def build_commit_graph(path: str, repo_name: str, ignore_list: Optional[List[str
239241

240242
# Log transitions
241243
logging.debug(f"""Save graph transition from
242-
commit: {parent_commit.hexsha}
244+
commit: {parent_commit.hex}
243245
to
244-
commit: {child_commit.hexsha}
246+
commit: {child_commit.hex}
245247
Queries: {queries}
246248
Parameters: {params}
247249
""")
248250

249-
git_graph.set_child_transition(child_commit.hexsha,
250-
parent_commit.hexsha, queries, params)
251+
git_graph.set_child_transition(child_commit.hex,
252+
parent_commit.hex, queries, params)
251253
# advance to the child_commit
252254
parent_commit = child_commit
253255

api/project.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import logging
44
import validators
55
import subprocess
6-
from git import Repo
6+
from pygit2.repository import Repository
77
from .info import *
88
from shlex import quote
99
from pathlib import Path
@@ -70,7 +70,7 @@ def from_local_repository(cls, path: Path|str):
7070

7171
# adjust url
7272
# '[email protected]:FalkorDB/code_graph.git'
73-
url = Repo(path).remotes[0].url
73+
url = Repository(path).remotes[0].url
7474
url = url.replace("git@", "https://").replace(":", "/").replace(".git", "")
7575

7676
name = path.name
@@ -85,9 +85,9 @@ def analyze_sources(self, ignore: Optional[List[str]] = None) -> Graph:
8585

8686
try:
8787
# Save processed commit hash to the DB
88-
repo = Repo(self.path)
89-
current_commit = repo.head.commit
90-
set_repo_commit(self.name, current_commit.hexsha)
88+
repo = Repository(self.path)
89+
current_commit = repo.walk(repo.head.target).__next__()
90+
set_repo_commit(self.name, current_commit.hex)
9191
except Exception:
9292
# Probably not .git folder is missing
9393
pass

poetry.lock

Lines changed: 45 additions & 49 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ python = "^3.10"
1010
graphrag-sdk = { version = "^0.5.0", extras = ["litellm"] }
1111
tree-sitter = "^0.24.0"
1212
validators = "^0.34.0"
13-
GitPython = "^3.1.44"
1413
falkordb = "^1.0.10"
1514
tree-sitter-c = "^0.23.4"
1615
tree-sitter-python = "^0.23.6"
@@ -19,6 +18,7 @@ flask = "^3.1.0"
1918
python-dotenv = "^1.0.1"
2019
multilspy = {git = "https://github.com/AviAvni/multilspy.git", rev = "update-pydantic"}
2120
javatools = "^1.6.0"
21+
pygit2 = "^1.17.0"
2222

2323
[tool.poetry.group.test.dependencies]
2424
pytest = "^8.2.0"

requirements.txt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ blinker==1.9.0 ; python_version >= "3.10" and python_version < "4.0"
1313
bs4==0.0.2 ; python_version >= "3.10" and python_version < "4.0"
1414
cattrs==24.1.2 ; python_version >= "3.10" and python_version < "4.0"
1515
certifi==2024.12.14 ; python_version >= "3.10" and python_version < "4.0"
16-
cffi==1.17.1 ; python_version >= "3.10" and python_version < "4.0" and implementation_name == "pypy"
16+
cffi==1.17.1 ; python_version >= "3.10" and python_version < "4.0"
1717
charset-normalizer==3.4.1 ; python_version >= "3.10" and python_version < "4.0"
1818
click==8.1.8 ; python_version >= "3.10" and python_version < "4.0"
1919
colorama==0.4.6 ; python_version >= "3.10" and python_version < "4.0" and sys_platform == "win32" or python_version >= "3.10" and python_version < "4.0" and platform_system == "Windows"
@@ -31,8 +31,6 @@ fix-busted-json==0.0.18 ; python_version >= "3.10" and python_version < "4.0"
3131
flask==3.1.0 ; python_version >= "3.10" and python_version < "4.0"
3232
frozenlist==1.5.0 ; python_version >= "3.10" and python_version < "4.0"
3333
fsspec==2024.12.0 ; python_version >= "3.10" and python_version < "4.0"
34-
gitdb==4.0.12 ; python_version >= "3.10" and python_version < "4.0"
35-
gitpython==3.1.44 ; python_version >= "3.10" and python_version < "4.0"
3634
graphrag-sdk==0.5.0 ; python_version >= "3.10" and python_version < "4.0"
3735
h11==0.14.0 ; python_version >= "3.10" and python_version < "4.0"
3836
httpcore==1.0.7 ; python_version >= "3.10" and python_version < "4.0"
@@ -70,9 +68,10 @@ propcache==0.2.1 ; python_version >= "3.10" and python_version < "4.0"
7068
psutil==6.1.1 ; python_version >= "3.10" and python_version < "4.0"
7169
ptyprocess==0.7.0 ; python_version >= "3.10" and python_version < "4.0" and (sys_platform != "win32" and sys_platform != "emscripten")
7270
pure-eval==0.2.3 ; python_version >= "3.10" and python_version < "4.0"
73-
pycparser==2.22 ; python_version >= "3.10" and python_version < "4.0" and implementation_name == "pypy"
71+
pycparser==2.22 ; python_version >= "3.10" and python_version < "4.0"
7472
pydantic-core==2.27.2 ; python_version >= "3.10" and python_version < "4.0"
7573
pydantic==2.10.6 ; python_version >= "3.10" and python_version < "4.0"
74+
pygit2==1.17.0 ; python_version >= "3.10" and python_version < "4.0"
7675
pygls==1.3.1 ; python_version >= "3.10" and python_version < "4.0"
7776
pygments==2.19.1 ; python_version >= "3.10" and python_version < "4.0"
7877
pypdf==4.3.1 ; python_version >= "3.10" and python_version < "4.0"
@@ -89,7 +88,6 @@ regex==2024.11.6 ; python_version >= "3.10" and python_version < "4.0"
8988
requests==2.32.3 ; python_version >= "3.10" and python_version < "4.0"
9089
rpds-py==0.22.3 ; python_version >= "3.10" and python_version < "4.0"
9190
six==1.17.0 ; python_version >= "3.10" and python_version < "4.0"
92-
smmap==5.0.2 ; python_version >= "3.10" and python_version < "4.0"
9391
sniffio==1.3.1 ; python_version >= "3.10" and python_version < "4.0"
9492
soupsieve==2.6 ; python_version >= "3.10" and python_version < "4.0"
9593
stack-data==0.6.3 ; python_version >= "3.10" and python_version < "4.0"

0 commit comments

Comments
 (0)