1
1
import os
2
2
import json
3
3
import logging
4
+
5
+ from pygit2 import Commit
4
6
from ..info import *
5
- from git import Repo
7
+ from pygit2 . repository import Repository
6
8
from pathlib import Path
7
9
from ..graph import Graph
8
10
from .git_graph import GitGraph
@@ -85,9 +87,9 @@ def build_commit_graph(path: str, repo_name: str, ignore_list: Optional[List[str
85
87
86
88
# Initialize with the current commit
87
89
# 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
91
93
92
94
# Add commit to the git graph
93
95
git_graph .add_commit (current_commit )
@@ -106,7 +108,7 @@ def build_commit_graph(path: str, repo_name: str, ignore_list: Optional[List[str
106
108
git_graph .add_commit (parent_commit )
107
109
108
110
# 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 )
110
112
111
113
# Represents the changes going backward!
112
114
# 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
126
128
127
129
# Checkout prev commit
128
130
logging .info (f"Checking out commit: { parent_commit .hexsha } " )
129
- repo .git . checkout (parent_commit .hexsha )
131
+ repo .checkout (parent_commit .hex )
130
132
131
133
#-----------------------------------------------------------------------
132
134
# Apply changes going backwards
@@ -165,15 +167,15 @@ def build_commit_graph(path: str, repo_name: str, ignore_list: Optional[List[str
165
167
166
168
# Log transitions
167
169
logging .debug (f"""Save graph transition from
168
- commit: { child_commit .hexsha }
170
+ commit: { child_commit .hex }
169
171
to
170
- commit: { parent_commit .hexsha }
172
+ commit: { parent_commit .hex }
171
173
Queries: { queries }
172
174
Parameters: { params }
173
175
""" )
174
176
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 )
177
179
# advance to the next commit
178
180
child_commit = parent_commit
179
181
@@ -183,24 +185,24 @@ def build_commit_graph(path: str, repo_name: str, ignore_list: Optional[List[str
183
185
184
186
logging .info ("Computing transition queries moving forward" )
185
187
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__ ( )
189
191
190
192
# Represents the changes going forward
191
193
# e.g. which files need to be deleted when moving forward one commit
192
194
193
195
# Process file changes in this commit
194
196
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 } """ )
197
199
198
- diff = parent_commit .diff (child_commit )
200
+ diff = repo .diff (parent_commit , child_commit )
199
201
added , deleted , modified = classify_changes (diff , ignore_list )
200
202
201
203
# 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 )
204
206
205
207
#-----------------------------------------------------------------------
206
208
# Apply changes going forward
@@ -239,15 +241,15 @@ def build_commit_graph(path: str, repo_name: str, ignore_list: Optional[List[str
239
241
240
242
# Log transitions
241
243
logging .debug (f"""Save graph transition from
242
- commit: { parent_commit .hexsha }
244
+ commit: { parent_commit .hex }
243
245
to
244
- commit: { child_commit .hexsha }
246
+ commit: { child_commit .hex }
245
247
Queries: { queries }
246
248
Parameters: { params }
247
249
""" )
248
250
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 )
251
253
# advance to the child_commit
252
254
parent_commit = child_commit
253
255
0 commit comments