Skip to content

Commit 739c739

Browse files
authored
Merge pull request #72 from FalkorDB/staging
Staging
2 parents 250ddea + f235c88 commit 739c739

17 files changed

+914
-468
lines changed

api/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@
55
from .entities import *
66
from .git_utils import *
77
from .code_coverage import *
8-
from .index import create_app
98
from .analyzers.source_analyzer import *
109
from .auto_complete import prefix_search

api/entities/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
from .file import File
44
from .entity import Entity
5-
from .entity_encoder import *
5+
from .entity_encoder import encode_node, encode_edge, encode_path, encode_graph_entity

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

0 commit comments

Comments
 (0)