Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
bbfa966c
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
bbfa966c
编写于
11月 19, 2019
作者:
J
Joao Moreno
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'joao/git-fs-provider'
上级
1ba8fc67
b7ead236
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
211 addition
and
3 deletion
+211
-3
extensions/git/src/api/api1.ts
extensions/git/src/api/api1.ts
+5
-0
extensions/git/src/api/git.d.ts
extensions/git/src/api/git.d.ts
+2
-0
extensions/git/src/contentProvider.ts
extensions/git/src/contentProvider.ts
+1
-1
extensions/git/src/fileSystemProvider.ts
extensions/git/src/fileSystemProvider.ts
+199
-0
extensions/git/src/main.ts
extensions/git/src/main.ts
+2
-0
extensions/git/src/uri.ts
extensions/git/src/uri.ts
+2
-2
未找到文件。
extensions/git/src/api/api1.ts
浏览文件 @
bbfa966c
...
...
@@ -8,6 +8,7 @@ import { Repository as BaseRepository, Resource } from '../repository';
import
{
InputBox
,
Git
,
API
,
Repository
,
Remote
,
RepositoryState
,
Branch
,
Ref
,
Submodule
,
Commit
,
Change
,
RepositoryUIState
,
Status
,
LogOptions
,
APIState
}
from
'
./git
'
;
import
{
Event
,
SourceControlInputBox
,
Uri
,
SourceControl
}
from
'
vscode
'
;
import
{
mapEvent
}
from
'
../util
'
;
import
{
toGitUri
}
from
'
../uri
'
;
class
ApiInputBox
implements
InputBox
{
set
value
(
value
:
string
)
{
this
.
_inputBox
.
value
=
value
;
}
...
...
@@ -234,5 +235,9 @@ export class ApiImpl implements API {
return
this
.
_model
.
repositories
.
map
(
r
=>
new
ApiRepository
(
r
));
}
toGitUri
(
uri
:
Uri
,
ref
:
string
):
Uri
{
return
toGitUri
(
uri
,
ref
);
}
constructor
(
private
_model
:
Model
)
{
}
}
extensions/git/src/api/git.d.ts
浏览文件 @
bbfa966c
...
...
@@ -185,6 +185,8 @@ export interface API {
readonly
repositories
:
Repository
[];
readonly
onDidOpenRepository
:
Event
<
Repository
>
;
readonly
onDidCloseRepository
:
Event
<
Repository
>
;
toGitUri
(
uri
:
Uri
,
ref
:
string
):
Uri
;
}
export
interface
GitExtension
{
...
...
extensions/git/src/contentProvider.ts
浏览文件 @
bbfa966c
...
...
@@ -147,4 +147,4 @@ export class GitContentProvider {
dispose
():
void
{
this
.
disposables
.
forEach
(
d
=>
d
.
dispose
());
}
}
\ No newline at end of file
}
extensions/git/src/fileSystemProvider.ts
0 → 100644
浏览文件 @
bbfa966c
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
workspace
,
Uri
,
Disposable
,
Event
,
EventEmitter
,
window
,
FileSystemProvider
,
FileChangeEvent
,
FileStat
,
FileType
,
FileChangeType
,
FileSystemError
}
from
'
vscode
'
;
import
{
debounce
,
throttle
}
from
'
./decorators
'
;
import
{
fromGitUri
,
toGitUri
}
from
'
./uri
'
;
import
{
Model
,
ModelChangeEvent
,
OriginalResourceChangeEvent
}
from
'
./model
'
;
import
{
filterEvent
,
eventToPromise
,
isDescendant
,
pathEquals
,
EmptyDisposable
}
from
'
./util
'
;
interface
CacheRow
{
uri
:
Uri
;
timestamp
:
number
;
}
const
THREE_MINUTES
=
1000
*
60
*
3
;
const
FIVE_MINUTES
=
1000
*
60
*
5
;
export
class
GitFileSystemProvider
implements
FileSystemProvider
{
private
_onDidChangeFile
=
new
EventEmitter
<
FileChangeEvent
[]
>
();
readonly
onDidChangeFile
:
Event
<
FileChangeEvent
[]
>
=
this
.
_onDidChangeFile
.
event
;
private
changedRepositoryRoots
=
new
Set
<
string
>
();
private
cache
=
new
Map
<
string
,
CacheRow
>
();
private
mtime
=
new
Date
().
getTime
();
private
disposables
:
Disposable
[]
=
[];
constructor
(
private
model
:
Model
)
{
this
.
disposables
.
push
(
model
.
onDidChangeRepository
(
this
.
onDidChangeRepository
,
this
),
model
.
onDidChangeOriginalResource
(
this
.
onDidChangeOriginalResource
,
this
),
workspace
.
registerFileSystemProvider
(
'
gitfs
'
,
this
,
{
isReadonly
:
true
,
isCaseSensitive
:
true
}),
workspace
.
registerResourceLabelFormatter
({
scheme
:
'
gitfs
'
,
formatting
:
{
label
:
'
${path} (git)
'
,
separator
:
'
/
'
}
})
);
setInterval
(()
=>
this
.
cleanup
(),
FIVE_MINUTES
);
}
private
onDidChangeRepository
({
repository
}:
ModelChangeEvent
):
void
{
this
.
changedRepositoryRoots
.
add
(
repository
.
root
);
this
.
eventuallyFireChangeEvents
();
}
private
onDidChangeOriginalResource
({
uri
}:
OriginalResourceChangeEvent
):
void
{
if
(
uri
.
scheme
!==
'
file
'
)
{
return
;
}
const
gitUri
=
toGitUri
(
uri
,
''
,
{
replaceFileExtension
:
true
});
this
.
mtime
=
new
Date
().
getTime
();
this
.
_onDidChangeFile
.
fire
([{
type
:
FileChangeType
.
Changed
,
uri
:
gitUri
}]);
}
@
debounce
(
1100
)
private
eventuallyFireChangeEvents
():
void
{
this
.
fireChangeEvents
();
}
@
throttle
private
async
fireChangeEvents
():
Promise
<
void
>
{
if
(
!
window
.
state
.
focused
)
{
const
onDidFocusWindow
=
filterEvent
(
window
.
onDidChangeWindowState
,
e
=>
e
.
focused
);
await
eventToPromise
(
onDidFocusWindow
);
}
const
events
:
FileChangeEvent
[]
=
[];
for
(
const
{
uri
}
of
this
.
cache
.
values
())
{
const
fsPath
=
uri
.
fsPath
;
for
(
const
root
of
this
.
changedRepositoryRoots
)
{
if
(
isDescendant
(
root
,
fsPath
))
{
events
.
push
({
type
:
FileChangeType
.
Changed
,
uri
});
break
;
}
}
}
if
(
events
.
length
>
0
)
{
this
.
mtime
=
new
Date
().
getTime
();
this
.
_onDidChangeFile
.
fire
(
events
);
}
this
.
changedRepositoryRoots
.
clear
();
}
private
cleanup
():
void
{
const
now
=
new
Date
().
getTime
();
const
cache
=
new
Map
<
string
,
CacheRow
>
();
for
(
const
row
of
this
.
cache
.
values
())
{
const
{
path
}
=
fromGitUri
(
row
.
uri
);
const
isOpen
=
workspace
.
textDocuments
.
filter
(
d
=>
d
.
uri
.
scheme
===
'
file
'
)
.
some
(
d
=>
pathEquals
(
d
.
uri
.
fsPath
,
path
));
if
(
isOpen
||
now
-
row
.
timestamp
<
THREE_MINUTES
)
{
cache
.
set
(
row
.
uri
.
toString
(),
row
);
}
else
{
// TODO: should fire delete events?
}
}
this
.
cache
=
cache
;
}
watch
():
Disposable
{
return
EmptyDisposable
;
}
stat
(
uri
:
Uri
):
FileStat
{
const
{
submoduleOf
}
=
fromGitUri
(
uri
);
const
repository
=
submoduleOf
?
this
.
model
.
getRepository
(
submoduleOf
)
:
this
.
model
.
getRepository
(
uri
);
if
(
!
repository
)
{
throw
FileSystemError
.
FileNotFound
();
}
return
{
type
:
FileType
.
File
,
size
:
0
,
mtime
:
this
.
mtime
,
ctime
:
0
};
}
readDirectory
():
Thenable
<
[
string
,
FileType
][]
>
{
throw
new
Error
(
'
Method not implemented.
'
);
}
createDirectory
():
void
{
throw
new
Error
(
'
Method not implemented.
'
);
}
async
readFile
(
uri
:
Uri
):
Promise
<
Uint8Array
>
{
let
{
path
,
ref
,
submoduleOf
}
=
fromGitUri
(
uri
);
if
(
submoduleOf
)
{
const
repository
=
this
.
model
.
getRepository
(
submoduleOf
);
if
(
!
repository
)
{
throw
FileSystemError
.
FileNotFound
();
}
const
encoder
=
new
TextEncoder
();
if
(
ref
===
'
index
'
)
{
return
encoder
.
encode
(
await
repository
.
diffIndexWithHEAD
(
path
));
}
else
{
return
encoder
.
encode
(
await
repository
.
diffWithHEAD
(
path
));
}
}
const
repository
=
this
.
model
.
getRepository
(
uri
);
if
(
!
repository
)
{
throw
FileSystemError
.
FileNotFound
();
}
const
timestamp
=
new
Date
().
getTime
();
const
cacheValue
:
CacheRow
=
{
uri
,
timestamp
};
this
.
cache
.
set
(
uri
.
toString
(),
cacheValue
);
if
(
ref
===
'
~
'
)
{
const
fileUri
=
Uri
.
file
(
path
);
const
uriString
=
fileUri
.
toString
();
const
[
indexStatus
]
=
repository
.
indexGroup
.
resourceStates
.
filter
(
r
=>
r
.
resourceUri
.
toString
()
===
uriString
);
ref
=
indexStatus
?
''
:
'
HEAD
'
;
}
else
if
(
/^~
\d
$/
.
test
(
ref
))
{
ref
=
`:
${
ref
[
1
]}
`
;
}
try
{
return
await
repository
.
buffer
(
ref
,
path
);
}
catch
(
err
)
{
return
new
Uint8Array
(
0
);
}
}
writeFile
():
void
{
throw
new
Error
(
'
Method not implemented.
'
);
}
delete
():
void
{
throw
new
Error
(
'
Method not implemented.
'
);
}
rename
():
void
{
throw
new
Error
(
'
Method not implemented.
'
);
}
dispose
():
void
{
this
.
disposables
.
forEach
(
d
=>
d
.
dispose
());
}
}
extensions/git/src/main.ts
浏览文件 @
bbfa966c
...
...
@@ -11,6 +11,7 @@ import { findGit, Git, IGit } from './git';
import
{
Model
}
from
'
./model
'
;
import
{
CommandCenter
}
from
'
./commands
'
;
import
{
GitContentProvider
}
from
'
./contentProvider
'
;
import
{
GitFileSystemProvider
}
from
'
./fileSystemProvider
'
;
import
{
GitDecorations
}
from
'
./decorationProvider
'
;
import
{
Askpass
}
from
'
./askpass
'
;
import
{
toDisposable
,
filterEvent
,
eventToPromise
}
from
'
./util
'
;
...
...
@@ -62,6 +63,7 @@ async function createModel(context: ExtensionContext, outputChannel: OutputChann
disposables
.
push
(
new
CommandCenter
(
git
,
model
,
outputChannel
,
telemetryReporter
),
new
GitContentProvider
(
model
),
new
GitFileSystemProvider
(
model
),
new
GitDecorations
(
model
),
new
GitProtocolHandler
()
);
...
...
extensions/git/src/uri.ts
浏览文件 @
bbfa966c
...
...
@@ -42,8 +42,8 @@ export function toGitUri(uri: Uri, ref: string, options: GitUriOptions = {}): Ur
}
return
uri
.
with
({
scheme
:
'
git
'
,
scheme
:
'
git
fs
'
,
path
,
query
:
JSON
.
stringify
(
params
)
});
}
\ No newline at end of file
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录