Skip to content

Commit ab6d861

Browse files
committed
feat: update commit data
1 parent febc257 commit ab6d861

File tree

11 files changed

+136
-350
lines changed

11 files changed

+136
-350
lines changed

demo.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
<!-- <circle cx="30" cy="210" r="10" fill="red" /> -->
117117
</svg>
118118
</div>
119+
<div style='width: 150px;height: 28px;background: url("data:image/svg+xml;charset=UTF-8,<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"100%\" height=\"100%\"><g><line fill=\"none\" shape-rendering=\"auto\" stroke-linejoin=\"round\" stroke-width=\"2\" stroke=\"rgba(21, 160, 191, 1)\" x1=\"39\" x2=\"39\" y2=\"28\" /><line fill=\"none\" shape-rendering=\"auto\" stroke-linejoin=\"round\" stroke-width=\"2\" stroke=\"rgba(6, 105, 247, 1)\" x1=\"61\" x2=\"61\" y2=\"28\" /><line fill=\"none\" shape-rendering=\"auto\" stroke-linejoin=\"round\" stroke-width=\"2\" stroke=\"rgba(142, 0, 194, 1)\" x1=\"83\" x2=\"83\" y2=\"28\" /><g><path d=\"M 116 14 H 113 A 8 8 0 0 0 105 22 V 25\" fill=\"none\" shape-rendering=\"auto\" stroke-linejoin=\"round\" stroke-width=\"2\" stroke=\"rgba(197, 23, 182, 1)\" /><line fill=\"none\" shape-rendering=\"auto\" stroke-linejoin=\"round\" stroke-width=\"2\" stroke=\"rgba(197, 23, 182, 1)\" x1=\"105\" x2=\"105\" y1=\"25\" y2=\"28\" /><line fill=\"none\" shape-rendering=\"auto\" stroke-linejoin=\"round\" stroke-width=\"2\" stroke=\"rgba(197, 23, 182, 1)\" x1=\"116\" x2=\"127\" y1=\"14\" y2=\"14\" /></g><line fill=\"none\" shape-rendering=\"auto\" stroke-linejoin=\"round\" stroke-width=\"2\" stroke=\"rgba(197, 23, 182, 1)\" x1=\"105\" x2=\"105\" y2=\"28\" /><line fill=\"none\" shape-rendering=\"auto\" stroke-linejoin=\"round\" stroke-width=\"2\" stroke=\"rgba(217, 1, 113, 1)\" x1=\"127\" x2=\"127\" y1=\"14\" y2=\"28\" /></g></svg>")'></div>
119120
</div>
120121
<script>
121122
const commits = [

src/git/index.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,12 @@ export const useGitService = createSingletonComposable(() => {
2424
const logResult = await git.log([
2525
'--all',
2626
'--stat',
27-
'--max-count=50',
2827
]) as ExtendedLogResult
2928

3029
const rawParentsOutput = await git.raw([
3130
'log',
3231
'--all',
3332
'--pretty=format:%H %P',
34-
'--max-count=50',
3533
])
3634

3735
const parentMap: { [hash: string]: string[] } = {}
@@ -102,16 +100,9 @@ export const useGitService = createSingletonComposable(() => {
102100
const branches = refs
103101
.filter(ref => ref.includes('refs/heads/') || ref.includes('refs/remotes/') || (!ref.includes('refs/') && !ref.includes('tag:')))
104102
.map((ref) => {
105-
let branch = ref
106-
if (ref.includes('refs/heads/')) {
107-
branch = ref.replace('refs/heads/', '')
108-
}
109-
else if (ref.includes('refs/remotes/')) {
110-
branch = ref.replace('refs/remotes/', '').split('/').slice(1).join('/')
111-
}
112-
else if (ref.includes('HEAD ->')) {
113-
branch = ref.replace('HEAD -> ', '')
114-
}
103+
const branch = ref.replace('refs/heads/', '')
104+
.replace('refs/remotes/', '').split('/').slice(1).join('/')
105+
.replace('HEAD -> ', '')
115106
return branch
116107
})
117108
.filter(Boolean)
@@ -123,7 +114,6 @@ export const useGitService = createSingletonComposable(() => {
123114
}
124115
})
125116

126-
// 如果没有找到分支信息,使用默认分支名称
127117
if (branchSet.size === 0) {
128118
branchSet.add('master')
129119
}

src/storage.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,38 @@
11
import { createSingletonComposable, extensionContext } from 'reactive-vscode'
2-
import type { Commit } from '@/git/types'
2+
import type { Commit, CommitGraph } from '@/git/types'
33

44
const COMMITS_KEY = 'git-panel.commits'
55

66
export const useStorage = createSingletonComposable(() => {
7-
function saveCommits(commits: Commit[]) {
7+
function saveCommits(commits: CommitGraph) {
88
extensionContext.value?.globalState.update(COMMITS_KEY, commits)
99
}
1010

1111
function updateCommitFiles(commitHash: string, files: Array<{ status: string, path: string }>) {
12-
const commits = getCommits()
13-
const commit = commits.find(c => c.hash === commitHash)
12+
const { operations, branches, logResult } = getCommits()
13+
const commit = logResult.all.find(c => c.hash === commitHash)
1414

1515
if (commit) {
1616
commit.files = files
17-
saveCommits(commits)
17+
saveCommits({ operations, branches, logResult })
1818
}
1919
}
2020

21-
function getCommits(): Commit[] {
22-
return extensionContext.value?.globalState.get<Commit[]>(COMMITS_KEY) || []
21+
function getCommits(): CommitGraph {
22+
return extensionContext.value?.globalState.get<CommitGraph>(COMMITS_KEY) || ({
23+
operations: [],
24+
branches: [],
25+
logResult: {
26+
all: [],
27+
total: 0,
28+
},
29+
}) as unknown as CommitGraph
2330
}
2431

2532
function getCommit(hash: string): Commit | undefined {
26-
const commits = getCommits()
33+
const { logResult: { all: commits } } = getCommits()
34+
if (!commits)
35+
return
2736
return commits.find(commit => commit.hash === hash)
2837
}
2938

src/views/diff/DiffTreeView.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const useDiffTreeView = createSingletonComposable(() => {
2222
let commit = storage.getCommit(hash)
2323

2424
if (!commit) {
25-
const { logResult } = await git.getHistory()
25+
const { logResult, operations, branches } = await git.getHistory()
2626
const historyCommit = logResult.all.find(c => c.hash === hash)
2727
if (!historyCommit)
2828
return
@@ -31,7 +31,7 @@ export const useDiffTreeView = createSingletonComposable(() => {
3131
...historyCommit,
3232
}
3333

34-
storage.saveCommits(Array.from(logResult.all))
34+
storage.saveCommits({ operations, branches, logResult })
3535
}
3636

3737
commitDetails.value = commit

src/views/history/App.vue

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<script setup lang="ts">
2-
import { computed, onMounted, ref, watch } from 'vue'
2+
import { computed, onMounted, ref } from 'vue'
33
44
import CommitTable from './components/CommitTable/index.vue'
55
66
import { CHANNEL, WEBVIEW_CHANNEL } from '@/constant'
77
8-
import type { Commit } from '@/git'
8+
import type { CommitGraph } from '@/git'
99
1010
declare global {
1111
interface Window {
@@ -14,15 +14,15 @@ declare global {
1414
}
1515
1616
interface State {
17-
commits: Commit[]
17+
commits: CommitGraph
1818
selectedHash?: string
1919
filter?: string
2020
}
2121
22-
const commits = ref<Commit[]>([])
22+
const commits = ref<CommitGraph>()
2323
const error = ref<string>('')
24-
const selectedHash = ref<string>('')
25-
const filter = ref<string>('')
24+
// const selectedHash = ref<string>('')
25+
// const filter = ref<string>('')
2626
2727
// VSCode webview API
2828
const vscode = acquireVsCodeApi<State>()
@@ -34,7 +34,7 @@ window.addEventListener('message', (event: { data: any }) => {
3434
3535
switch (message.command) {
3636
case CHANNEL.HISTORY:
37-
commits.value = message.commits as Commit[]
37+
commits.value = message.commits as CommitGraph
3838
break
3939
case 'error':
4040
error.value = message.message
@@ -47,7 +47,7 @@ onMounted(() => {
4747
})
4848
4949
const transformedCommits = computed(() => {
50-
return commits.value
50+
return Array.from(commits.value?.logResult.all || []) || []
5151
})
5252
</script>
5353

@@ -57,7 +57,7 @@ const transformedCommits = computed(() => {
5757
<input v-model="filter" type="text" placeholder="Search commits..." class="search-input">
5858
</div> -->
5959

60-
<CommitTable :commits="transformedCommits" class="git-graph-container" />
60+
<CommitTable :commits="transformedCommits" :graph-data="commits?.operations || []" class="git-graph-container" />
6161

6262
<div v-if="error" class="error">
6363
{{ error }}

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<script setup lang="ts">
22
import { defineModel, ref } from 'vue'
3-
import ResizeHandle from './ResizeHandle.vue'
3+
import ResizeHandle from '../ResizeHandle/index.vue'
44
55
interface ColumnWidths {
6+
branch: number
67
hash: number
78
message: number
89
stats: number
@@ -12,18 +13,18 @@ interface ColumnWidths {
1213
1314
const modelValue = defineModel<ColumnWidths>()
1415
const isDragging = ref(false)
15-
const currentColumn = ref('')
16+
const currentColumn = ref<keyof ColumnWidths>()
1617
const startX = ref(0)
1718
const startWidth = ref(0)
1819
19-
function handleDragStart(e: MouseEvent, column: string) {
20+
function handleDragStart(e: MouseEvent, column: keyof ColumnWidths) {
2021
e.preventDefault()
2122
e.stopPropagation()
2223
2324
isDragging.value = true
2425
currentColumn.value = column
2526
startX.value = e.clientX
26-
startWidth.value = modelValue.value[column]
27+
startWidth.value = modelValue.value?.[column] || 0
2728
2829
document.addEventListener('mousemove', handleDragging, { passive: false })
2930
document.addEventListener('mouseup', handleDragEnd, { once: true })
@@ -45,15 +46,15 @@ function handleDragging(e: MouseEvent) {
4546
const diff = e.clientX - startX.value
4647
const newWidth = Math.max(100, startWidth.value + diff)
4748
48-
modelValue.value[currentColumn.value] = newWidth
49+
modelValue.value![currentColumn.value!] = newWidth
4950
}
5051
5152
function handleDragEnd() {
5253
if (!isDragging.value)
5354
return
5455
5556
isDragging.value = false
56-
currentColumn.value = ''
57+
currentColumn.value = undefined
5758
5859
document.removeEventListener('mousemove', handleDragging)
5960
document.removeEventListener('mouseup', handleDragEnd)
@@ -66,19 +67,23 @@ function handleDragEnd() {
6667

6768
<template>
6869
<li class="commit-header">
69-
<span class="hash-col column-header" :style="{ width: `${modelValue.hash}px` }">
70+
<!-- <span class="column-header" :style="{ width: `${modelValue?.branch}px` }">
71+
Branch
72+
<ResizeHandle :is-active="currentColumn === 'branch'" @mousedown="handleDragStart($event, 'branch')" />
73+
</span> -->
74+
<span class="hash-col column-header" :style="{ width: `${modelValue?.hash}px` }">
7075
CommitId
7176
<ResizeHandle :is-active="currentColumn === 'hash'" @mousedown="handleDragStart($event, 'hash')" />
7277
</span>
73-
<span class="column-header" :style="{ width: `${modelValue.message}px` }">
78+
<span class="column-header" :style="{ width: `${modelValue?.message}px` }">
7479
Message
7580
<ResizeHandle :is-active="currentColumn === 'message'" @mousedown="handleDragStart($event, 'message')" />
7681
</span>
77-
<span class="column-header" :style="{ width: `${modelValue.stats}px` }">
82+
<span class="column-header" :style="{ width: `${modelValue?.stats}px` }">
7883
Changes
7984
<ResizeHandle :is-active="currentColumn === 'stats'" @mousedown="handleDragStart($event, 'stats')" />
8085
</span>
81-
<span class="column-header" :style="{ width: `${modelValue.author}px` }">
86+
<span class="column-header" :style="{ width: `${modelValue?.author}px` }">
8287
Author
8388
<ResizeHandle :is-active="currentColumn === 'author'" @mousedown="handleDragStart($event, 'author')" />
8489
</span>

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

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
<script setup lang="ts">
2+
import { ref } from 'vue'
3+
// import GitGraph from './GitGraph.vue'
4+
import CopyButton from '../CopyButton/index.vue'
5+
26
import { WEBVIEW_CHANNEL } from '@/constant'
3-
import type { Commit } from '@/git'
7+
8+
import type { Commit, GitOperation } from '@/git'
49
510
const props = defineProps<{
611
commit: Commit
12+
graphData: GitOperation
13+
prevGraphData?: GitOperation
14+
nextGraphData?: GitOperation
715
columnWidths: Record<string, number>
816
}>()
917
18+
const hoveredCell = ref<string | null>(null)
19+
1020
function handleCommitClick() {
1121
try {
1222
if (window.vscode) {
@@ -37,17 +47,45 @@ function handleDoubleClick() {
3747

3848
<template>
3949
<li class="commit-row" @click="handleCommitClick" @dblclick="handleDoubleClick">
40-
<span class="hash-col commit-cell" :style="{ width: `${columnWidths.hash}px` }">{{ commit.hash.substring(0, 7)
41-
}}</span>
42-
<span class="commit-cell" :style="{ width: `${columnWidths.message}px` }">{{ commit.message }}</span>
50+
<!-- <div class="branch-col commit-cell" :style="{ width: `${columnWidths.branch}px` }">
51+
<GitGraph
52+
:graph-data="graphData"
53+
:prev-graph-data="prevGraphData"
54+
:next-graph-data="nextGraphData"
55+
/>
56+
</div> -->
57+
<span
58+
class="hash-col commit-cell" :style="{ width: `${columnWidths.hash}px` }" @mouseenter="hoveredCell = 'hash'"
59+
@mouseleave="hoveredCell = null"
60+
>
61+
{{ commit.hash.substring(0, 7) }}
62+
<CopyButton v-show="hoveredCell === 'hash'" :copy-text="commit.hash" />
63+
</span>
64+
65+
<span
66+
class="commit-cell" :style="{ width: `${columnWidths.message}px` }" @mouseenter="hoveredCell = 'message'"
67+
@mouseleave="hoveredCell = null"
68+
>
69+
{{ commit.message }}
70+
<CopyButton v-show="hoveredCell === 'message'" :copy-text="commit.message" />
71+
</span>
72+
4373
<span class="commit-cell" :style="{ width: `${columnWidths.stats}px` }">
4474
<span v-if="commit.diff" class="commit-stats">
4575
<span class="files">{{ commit.diff.changed }} files</span>
4676
<span v-if="commit.diff.insertions" class="additions">+{{ commit.diff.insertions }}</span>
4777
<span v-if="commit.diff.deletions" class="deletions">-{{ commit.diff.deletions }}</span>
4878
</span>
4979
</span>
50-
<span class="commit-cell" :style="{ width: `${columnWidths.author}px` }">{{ commit.authorName }}</span>
80+
81+
<span
82+
class="commit-cell" :style="{ width: `${columnWidths.author}px` }" @mouseenter="hoveredCell = 'authorName'"
83+
@mouseleave="hoveredCell = null"
84+
>
85+
{{ commit.authorName }}
86+
<CopyButton v-show="hoveredCell === 'authorName'" :copy-text="`${commit.authorName} <${commit.authorEmail}>`" />
87+
</span>
88+
5189
<span class="commit-cell date" :style="{ width: `${columnWidths.date}px` }">{{ commit.date }}</span>
5290
</li>
5391
</template>
@@ -60,7 +98,7 @@ function handleDoubleClick() {
6098
cursor: pointer;
6199
width: 100%;
62100
box-sizing: border-box;
63-
padding: 8px;
101+
position: relative;
64102
}
65103
66104
.commit-row:hover {
@@ -71,22 +109,24 @@ function handleDoubleClick() {
71109
white-space: nowrap;
72110
overflow: hidden;
73111
text-overflow: ellipsis;
112+
padding: 8px;
113+
position: relative;
74114
}
75115
76-
.hash-col {
77-
color: var(--vscode-gitDecoration-addedResourceForeground);
116+
.branch-col {
117+
position: relative;
118+
padding: 0px;
119+
z-index: 1;
78120
}
79121
80-
.date {
81-
padding-right: 16px;
82-
color: var(--vscode-descriptionForeground);
122+
.hash-col {
123+
color: var(--vscode-gitDecoration-addedResourceForeground);
83124
}
84125
85126
.commit-stats {
86-
display: inline-flex;
127+
font-size: 0.85em;
128+
display: flex;
87129
gap: 8px;
88-
font-size: 12px;
89-
white-space: nowrap;
90130
}
91131
92132
.additions {
@@ -96,4 +136,9 @@ function handleDoubleClick() {
96136
.deletions {
97137
color: var(--vscode-gitDecoration-deletedResourceForeground);
98138
}
139+
140+
.date {
141+
color: var(--vscode-descriptionForeground);
142+
font-size: 0.9em;
143+
}
99144
</style>

0 commit comments

Comments
 (0)