Skip to content

Commit 21a0a8f

Browse files
committed
refactor: refactor stats info
1 parent fd7620f commit 21a0a8f

File tree

5 files changed

+11
-54
lines changed

5 files changed

+11
-54
lines changed

src/git/index.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,9 @@ export const useGitService = createSingletonComposable(() => {
2929
]) as ExtendedLogResult
3030

3131
for (const commit of logResult.all) {
32-
try {
33-
const { diff, author_email, author_name } = commit
34-
commit.authorEmail = author_email
35-
commit.authorName = author_name
36-
37-
commit.stats = {
38-
files: diff?.changed || 0,
39-
additions: diff?.insertions || 0,
40-
deletions: diff?.deletions || 0,
41-
}
42-
}
43-
catch (error) {
44-
logger.warn(`Failed to get stats for commit ${commit.hash}:`, error)
45-
commit.stats = { files: 0, additions: 0, deletions: 0 }
46-
}
32+
const { author_email, author_name } = commit
33+
commit.authorEmail = author_email
34+
commit.authorName = author_name
4735
}
4836

4937
return logResult

src/git/types.ts

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,12 @@ export interface CommitFile {
66
oldPath?: string
77
}
88

9-
export interface Commit extends ListLogLine {
10-
hash: string
11-
authorName: string
12-
authorEmail: string
13-
message: string
14-
body: string
15-
date: string
16-
stats?: {
17-
files: number
18-
additions: number
19-
deletions: number
20-
}
21-
files?: Array<CommitFile>
22-
}
9+
export type Commit = CommitFields & ListLogLine
2310

2411
export interface CommitFields extends DefaultLogFields {
25-
stats?: CommitStats
2612
authorName: string
2713
authorEmail: string
28-
}
29-
30-
export interface CommitStats {
31-
files: number
32-
additions: number
33-
deletions: number
14+
files?: Array<CommitFile>
3415
}
3516

3617
export interface ExtendedLogResult extends LogResult<CommitFields> {

src/views/diff/DiffTreeView.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,7 @@ export class DiffTreeView implements TreeDataProvider<CommitNode> {
5656
}
5757

5858
commit = {
59-
hash: historyCommit.hash,
60-
authorName: historyCommit.author_name,
61-
authorEmail: historyCommit.author_email,
62-
date: historyCommit.date,
63-
message: historyCommit.message,
64-
body: historyCommit.body,
65-
stats: historyCommit.stats,
59+
...historyCommit,
6660
}
6761
}
6862

src/views/history/components/CommitTable/ListItem.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ function handleDoubleClick() {
4141
}}</span>
4242
<span class="commit-cell" :style="{ width: `${columnWidths.message}px` }">{{ commit.message }}</span>
4343
<span class="commit-cell" :style="{ width: `${columnWidths.stats}px` }">
44-
<span v-if="commit.stats" class="commit-stats">
45-
<span class="files">{{ commit.stats.files }} files</span>
46-
<span v-if="commit.stats.additions" class="additions">+{{ commit.stats.additions }}</span>
47-
<span v-if="commit.stats.deletions" class="deletions">-{{ commit.stats.deletions }}</span>
44+
<span v-if="commit.diff" class="commit-stats">
45+
<span class="files">{{ commit.diff.changed }} files</span>
46+
<span v-if="commit.diff.insertions" class="additions">+{{ commit.diff.insertions }}</span>
47+
<span v-if="commit.diff.deletions" class="deletions">-{{ commit.diff.deletions }}</span>
4848
</span>
4949
</span>
5050
<span class="commit-cell" :style="{ width: `${columnWidths.author}px` }">{{ commit.authorName }}</span>

src/views/webview.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,7 @@ export class GitPanelViewProvider implements WebviewViewProvider {
3232
try {
3333
if (this._commits.length === 0 || forceRefresh) {
3434
const history = await this.git.getHistory()
35-
36-
this._commits = history.all.map(commit => ({
37-
...commit,
38-
authorName: commit.author_name,
39-
authorEmail: commit.author_email,
40-
body: commit.body || '',
41-
}))
35+
this._commits = Array.from(history.all)
4236

4337
this.storage.saveCommits(this._commits)
4438
}

0 commit comments

Comments
 (0)