Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions api/git_utils/git_graph.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import os
import logging
from git import Commit
from falkordb import FalkorDB, Node
from typing import List, Optional

from pygit2 import Commit

# Configure logging
logging.basicConfig(level=logging.DEBUG, format='%(filename)s - %(asctime)s - %(levelname)s - %(message)s')

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


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


def set_child_transition(self, child: str, parent: str, queries: [str], params: [str]) -> None:
def set_child_transition(self, child: str, parent: str, queries: list[str], params: list[str]) -> None:
"""
Sets the queries and parameters needed to transition the code-graph
from the parent commit to the child commit
Expand Down
46 changes: 24 additions & 22 deletions api/git_utils/git_utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import os
import json
import logging

from pygit2 import Commit
from ..info import *
from git import Repo
from pygit2.repository import Repository
from pathlib import Path
from ..graph import Graph
from .git_graph import GitGraph
Expand Down Expand Up @@ -85,9 +87,9 @@ def build_commit_graph(path: str, repo_name: str, ignore_list: Optional[List[str

# Initialize with the current commit
# Save current git for later restoration
repo = Repo('.')
current_commit = repo.head.commit
current_commit_hexsha = current_commit.hexsha
repo = Repository('.')
current_commit = repo.walk(repo.head.target).__next__()
current_commit_hexsha = current_commit.hex

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

# connect child parent commits relation
git_graph.connect_commits(child_commit.hexsha, parent_commit.hexsha)
git_graph.connect_commits(child_commit.hex, parent_commit.hex)

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

# Checkout prev commit
logging.info(f"Checking out commit: {parent_commit.hexsha}")
repo.git.checkout(parent_commit.hexsha)
repo.checkout(parent_commit.hex)

#-----------------------------------------------------------------------
# Apply changes going backwards
Expand Down Expand Up @@ -165,15 +167,15 @@ def build_commit_graph(path: str, repo_name: str, ignore_list: Optional[List[str

# Log transitions
logging.debug(f"""Save graph transition from
commit: {child_commit.hexsha}
commit: {child_commit.hex}
to
commit: {parent_commit.hexsha}
commit: {parent_commit.hex}
Queries: {queries}
Parameters: {params}
""")

git_graph.set_parent_transition(child_commit.hexsha,
parent_commit.hexsha, queries, params)
git_graph.set_parent_transition(child_commit.hex,
parent_commit.hex, queries, params)
# advance to the next commit
child_commit = parent_commit

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

logging.info("Computing transition queries moving forward")
parent_commit = child_commit
while parent_commit.hexsha != current_commit_hexsha:
child_commit = git_graph.get_child_commit(parent_commit.hexsha)
child_commit = repo.commit(child_commit['hash'])
while parent_commit.hex != current_commit_hexsha:
child_commit = git_graph.get_child_commit(parent_commit.hex)
child_commit = repo.walk(child_commit['hash']).__next__()

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

# Process file changes in this commit
logging.info(f"""Computing diff between
child {parent_commit.hexsha}: {parent_commit.message}
and {child_commit.hexsha}: {child_commit.message}""")
child {parent_commit.hex}: {parent_commit.message}
and {child_commit.hex}: {child_commit.message}""")

diff = parent_commit.diff(child_commit)
diff = repo.diff(parent_commit, child_commit)
added, deleted, modified = classify_changes(diff, ignore_list)

# Checkout child commit
logging.info(f"Checking out commit: {child_commit.hexsha}")
repo.git.checkout(child_commit.hexsha)
logging.info(f"Checking out commit: {child_commit.hex}")
repo.checkout(child_commit.hex)

#-----------------------------------------------------------------------
# Apply changes going forward
Expand Down Expand Up @@ -239,15 +241,15 @@ def build_commit_graph(path: str, repo_name: str, ignore_list: Optional[List[str

# Log transitions
logging.debug(f"""Save graph transition from
commit: {parent_commit.hexsha}
commit: {parent_commit.hex}
to
commit: {child_commit.hexsha}
commit: {child_commit.hex}
Queries: {queries}
Parameters: {params}
""")

git_graph.set_child_transition(child_commit.hexsha,
parent_commit.hexsha, queries, params)
git_graph.set_child_transition(child_commit.hex,
parent_commit.hex, queries, params)
# advance to the child_commit
parent_commit = child_commit

Expand Down
10 changes: 5 additions & 5 deletions api/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
import validators
import subprocess
from git import Repo
from pygit2.repository import Repository
from .info import *
from shlex import quote
from pathlib import Path
Expand Down Expand Up @@ -70,7 +70,7 @@ def from_local_repository(cls, path: Path|str):

# adjust url
# '[email protected]:FalkorDB/code_graph.git'
url = Repo(path).remotes[0].url
url = Repository(path).remotes[0].url
url = url.replace("git@", "https://").replace(":", "/").replace(".git", "")

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

try:
# Save processed commit hash to the DB
repo = Repo(self.path)
current_commit = repo.head.commit
set_repo_commit(self.name, current_commit.hexsha)
repo = Repository(self.path)
current_commit = repo.walk(repo.head.target).__next__()
set_repo_commit(self.name, current_commit.hex)
except Exception:
# Probably not .git folder is missing
pass
Expand Down
94 changes: 45 additions & 49 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ python = "^3.10"
graphrag-sdk = { version = "^0.5.0", extras = ["litellm"] }
tree-sitter = "^0.24.0"
validators = "^0.34.0"
GitPython = "^3.1.44"
falkordb = "^1.0.10"
tree-sitter-c = "^0.23.4"
tree-sitter-python = "^0.23.6"
Expand All @@ -19,6 +18,7 @@ flask = "^3.1.0"
python-dotenv = "^1.0.1"
multilspy = {git = "https://github.com/AviAvni/multilspy.git", rev = "update-pydantic"}
javatools = "^1.6.0"
pygit2 = "^1.17.0"

[tool.poetry.group.test.dependencies]
pytest = "^8.2.0"
Expand Down
8 changes: 3 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ blinker==1.9.0 ; python_version >= "3.10" and python_version < "4.0"
bs4==0.0.2 ; python_version >= "3.10" and python_version < "4.0"
cattrs==24.1.2 ; python_version >= "3.10" and python_version < "4.0"
certifi==2024.12.14 ; python_version >= "3.10" and python_version < "4.0"
cffi==1.17.1 ; python_version >= "3.10" and python_version < "4.0" and implementation_name == "pypy"
cffi==1.17.1 ; python_version >= "3.10" and python_version < "4.0"
charset-normalizer==3.4.1 ; python_version >= "3.10" and python_version < "4.0"
click==8.1.8 ; python_version >= "3.10" and python_version < "4.0"
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"
Expand All @@ -31,8 +31,6 @@ fix-busted-json==0.0.18 ; python_version >= "3.10" and python_version < "4.0"
flask==3.1.0 ; python_version >= "3.10" and python_version < "4.0"
frozenlist==1.5.0 ; python_version >= "3.10" and python_version < "4.0"
fsspec==2024.12.0 ; python_version >= "3.10" and python_version < "4.0"
gitdb==4.0.12 ; python_version >= "3.10" and python_version < "4.0"
gitpython==3.1.44 ; python_version >= "3.10" and python_version < "4.0"
graphrag-sdk==0.5.0 ; python_version >= "3.10" and python_version < "4.0"
h11==0.14.0 ; python_version >= "3.10" and python_version < "4.0"
httpcore==1.0.7 ; python_version >= "3.10" and python_version < "4.0"
Expand Down Expand Up @@ -70,9 +68,10 @@ propcache==0.2.1 ; python_version >= "3.10" and python_version < "4.0"
psutil==6.1.1 ; python_version >= "3.10" and python_version < "4.0"
ptyprocess==0.7.0 ; python_version >= "3.10" and python_version < "4.0" and (sys_platform != "win32" and sys_platform != "emscripten")
pure-eval==0.2.3 ; python_version >= "3.10" and python_version < "4.0"
pycparser==2.22 ; python_version >= "3.10" and python_version < "4.0" and implementation_name == "pypy"
pycparser==2.22 ; python_version >= "3.10" and python_version < "4.0"
pydantic-core==2.27.2 ; python_version >= "3.10" and python_version < "4.0"
pydantic==2.10.6 ; python_version >= "3.10" and python_version < "4.0"
pygit2==1.17.0 ; python_version >= "3.10" and python_version < "4.0"
pygls==1.3.1 ; python_version >= "3.10" and python_version < "4.0"
pygments==2.19.1 ; python_version >= "3.10" and python_version < "4.0"
pypdf==4.3.1 ; python_version >= "3.10" and python_version < "4.0"
Expand All @@ -89,7 +88,6 @@ regex==2024.11.6 ; python_version >= "3.10" and python_version < "4.0"
requests==2.32.3 ; python_version >= "3.10" and python_version < "4.0"
rpds-py==0.22.3 ; python_version >= "3.10" and python_version < "4.0"
six==1.17.0 ; python_version >= "3.10" and python_version < "4.0"
smmap==5.0.2 ; python_version >= "3.10" and python_version < "4.0"
sniffio==1.3.1 ; python_version >= "3.10" and python_version < "4.0"
soupsieve==2.6 ; python_version >= "3.10" and python_version < "4.0"
stack-data==0.6.3 ; python_version >= "3.10" and python_version < "4.0"
Expand Down