Skip to content

Commit dc2b0a1

Browse files
committed
Generate patch/diff for all commits
1 parent 12f4f88 commit dc2b0a1

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

qgitc/aichatwindow.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,8 +553,7 @@ def codeReview(self, commit, args):
553553
repoDir = commitRepoDir(subCommit)
554554
subData = Git.commitRawDiff(subCommit.sha1, gitArgs=args, repoDir=repoDir)
555555
if subData:
556-
data += subData
557-
data += b"\n"
556+
data += b"\n" + subData
558557

559558
diff = data.decode("utf-8", errors="replace")
560559
self._doRequest(diff, AiChatMode.CodeReview)

qgitc/gitutils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,13 @@ def generateDiff(sha1, filePath, repoDir=None):
413413
return True
414414

415415
@staticmethod
416-
def generatePatch(sha1, filePath, repoDir=None):
416+
def commitRawPatch(sha1, repoDir=None):
417417
args = ["format-patch", "-1", "--stdout", sha1]
418+
return Git.checkOutput(args, repoDir=repoDir)
418419

419-
data = Git.checkOutput(args, repoDir=repoDir)
420+
@staticmethod
421+
def generatePatch(sha1, filePath, repoDir=None):
422+
data = Git.commitRawPatch(sha1, repoDir=repoDir)
420423
if not data:
421424
return False
422425

qgitc/logview.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -958,9 +958,20 @@ def __onGeneratePatch(self):
958958
self,
959959
self.tr("Save Patch"))
960960
if f:
961-
# TODO: generate with subCommits?
962-
repoDir = commitRepoDir(commit)
963-
Git.generatePatch(commit.sha1, f, repoDir)
961+
repoDir = commitRepoDir(commit)
962+
patch = Git.commitRawPatch(commit.sha1, repoDir)
963+
if patch is None:
964+
patch = b''
965+
966+
for subCommit in commit.subCommits:
967+
repoDir = commitRepoDir(subCommit)
968+
subPatch = Git.commitRawPatch(subCommit.sha1, repoDir)
969+
if subPatch:
970+
patch += b'\n' + subPatch
971+
972+
if patch:
973+
with open(f, "wb+") as h:
974+
h.write(patch)
964975

965976
def __onGenerateDiff(self):
966977
if self.curIdx == -1:
@@ -973,9 +984,19 @@ def __onGenerateDiff(self):
973984
self,
974985
self.tr("Save Diff"))
975986
if f:
976-
# TODO: generate with subCommits?
977987
repoDir = commitRepoDir(commit)
978-
Git.generateDiff(commit.sha1, f, repoDir)
988+
diff = Git.commitRawDiff(commit.sha1, repoDir=repoDir)
989+
if diff is None:
990+
diff = b''
991+
for subCommit in commit.subCommits:
992+
repoDir = commitRepoDir(subCommit)
993+
subDiff = Git.commitRawDiff(subCommit.sha1, repoDir=repoDir)
994+
if subDiff:
995+
diff += b'\n' + subDiff
996+
997+
if diff:
998+
with open(f, "wb+") as h:
999+
h.write(diff)
9791000

9801001
def __onRevertCommit(self):
9811002
if self.curIdx == -1:

0 commit comments

Comments
 (0)