11import os
22import json
33import logging
4+
5+ from pygit2 import Commit
46from ..info import *
5- from git import Repo
7+ from pygit2 . repository import Repository
68from pathlib import Path
79from ..graph import Graph
810from .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