-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTauriGitService.ts
More file actions
122 lines (102 loc) · 3.01 KB
/
TauriGitService.ts
File metadata and controls
122 lines (102 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import { invoke } from '@tauri-apps/api/core'
import type {
GitService,
LoadRepoResult,
DiffResult,
FileContent,
} from '@gitcontext/core'
/**
* TauriGitService - Desktop implementation using Rust git2 crate
*
* This service implements the GitService interface using Tauri's invoke
* to call Rust functions that use native git2 for high performance.
*/
export class TauriGitService implements GitService {
private repoPath: string | null = null
async loadRepo(
repoKey: string,
_opts: {
dirHandle?: FileSystemDirectoryHandle
gitFiles?: Array<{ path: string; data: Uint8Array }>
workFiles?: Array<{ path: string; data: Uint8Array }>
}
): Promise<LoadRepoResult> {
// For desktop, we use the repo path directly (no browser FileSystemDirectoryHandle)
// The repoKey should be the actual file system path
this.repoPath = repoKey
return invoke<LoadRepoResult>('open_repo', { path: repoKey })
}
async listBranches(): Promise<LoadRepoResult> {
if (!this.repoPath) {
throw new Error('No repository loaded')
}
return invoke<LoadRepoResult>('get_branches', { path: this.repoPath })
}
async getDiff(base: string, compare: string): Promise<DiffResult> {
if (!this.repoPath) {
throw new Error('No repository loaded')
}
return invoke<DiffResult>('git_diff', {
path: this.repoPath,
base,
compare,
})
}
async listFiles(ref: string): Promise<{ files: string[] }> {
if (!this.repoPath) {
throw new Error('No repository loaded')
}
const result = await invoke<{ files: string[] }>('list_files', {
path: this.repoPath,
refName: ref,
})
return result
}
async listFilesWithOids(ref: string): Promise<{ files: Array<{ path: string; oid: string }> }> {
if (!this.repoPath) {
throw new Error('No repository loaded')
}
const result = await invoke<{ files: Array<{ path: string; oid: string }> }>('list_files_with_oids', {
path: this.repoPath,
refName: ref,
})
return result
}
async readFile(ref: string, path: string): Promise<FileContent> {
if (!this.repoPath) {
throw new Error('No repository loaded')
}
const result = await invoke<{
binary: boolean
text: string | null
not_found?: boolean
}>('read_file_blob', {
path: this.repoPath,
refName: ref,
filePath: path,
})
return {
binary: result.binary,
text: result.text,
notFound: result.not_found,
}
}
async resolveRef(ref: string): Promise<{ oid: string }> {
if (!this.repoPath) {
throw new Error('No repository loaded')
}
const result = await invoke<{ oid: string }>('resolve_ref', {
path: this.repoPath,
refName: ref,
})
return result
}
/**
* Dispose of resources by clearing the repo path.
* Note: This service instance remains valid and can be reused after dispose().
* Call loadRepo() again to load a new repository.
*/
dispose(): void {
this.repoPath = null
}
}