Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
b6781b00
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b6781b00
编写于
7月 06, 2018
作者:
J
Joao Moreno
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
align lstree implementations
上级
00a1abe9
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
43 addition
and
46 deletion
+43
-46
extensions/git/src/commands.ts
extensions/git/src/commands.ts
+1
-1
extensions/git/src/git.ts
extensions/git/src/git.ts
+15
-18
extensions/git/src/repository.ts
extensions/git/src/repository.ts
+5
-5
extensions/git/src/test/git.test.ts
extensions/git/src/test/git.test.ts
+22
-22
未找到文件。
extensions/git/src/commands.ts
浏览文件 @
b6781b00
...
@@ -252,7 +252,7 @@ export class CommandCenter {
...
@@ -252,7 +252,7 @@ export class CommandCenter {
gitRef
=
indexStatus
?
''
:
'
HEAD
'
;
gitRef
=
indexStatus
?
''
:
'
HEAD
'
;
}
}
const
{
size
,
object
}
=
await
repository
.
lstree
(
gitRef
,
uri
.
fsPath
);
const
{
size
,
object
}
=
await
repository
.
getObjectDetails
(
gitRef
,
uri
.
fsPath
);
const
{
mimetype
}
=
await
repository
.
detectObjectType
(
object
);
const
{
mimetype
}
=
await
repository
.
detectObjectType
(
object
);
if
(
mimetype
===
'
text/plain
'
)
{
if
(
mimetype
===
'
text/plain
'
)
{
...
...
extensions/git/src/git.ts
浏览文件 @
b6781b00
...
@@ -647,15 +647,16 @@ interface LsTreeElement {
...
@@ -647,15 +647,16 @@ interface LsTreeElement {
mode
:
string
;
mode
:
string
;
type
:
string
;
type
:
string
;
object
:
string
;
object
:
string
;
size
:
string
;
file
:
string
;
file
:
string
;
}
}
export
function
parseLsTree
(
raw
:
string
):
LsTreeElement
[]
{
export
function
parseLsTree
(
raw
:
string
):
LsTreeElement
[]
{
return
raw
.
split
(
'
\n
'
)
return
raw
.
split
(
'
\n
'
)
.
filter
(
l
=>
!!
l
)
.
filter
(
l
=>
!!
l
)
.
map
(
line
=>
/^
(\S
+
)\s
+
(\S
+
)\s
+
(\S
+
)\s
+
(
.*
)
$/
.
exec
(
line
)
!
)
.
map
(
line
=>
/^
(\S
+
)\s
+
(\S
+
)\s
+
(\S
+
)\s
+
(
\S
+
)\s
+
(
.*
)
$/
.
exec
(
line
)
!
)
.
filter
(
m
=>
!!
m
)
.
filter
(
m
=>
!!
m
)
.
map
(([,
mode
,
type
,
object
,
file
])
=>
({
mode
,
type
,
object
,
file
}));
.
map
(([,
mode
,
type
,
object
,
size
,
file
])
=>
({
mode
,
type
,
object
,
size
,
file
}));
}
}
interface
LsFilesElement
{
interface
LsFilesElement
{
...
@@ -759,37 +760,33 @@ export class Repository {
...
@@ -759,37 +760,33 @@ export class Repository {
return
stdout
;
return
stdout
;
}
}
async
lstree
(
treeish
:
string
,
path
:
string
):
Promise
<
{
mode
:
string
,
object
:
string
,
size
:
number
}
>
{
async
getObjectDetails
(
treeish
:
string
,
path
:
string
):
Promise
<
{
mode
:
string
,
object
:
string
,
size
:
number
}
>
{
if
(
!
treeish
)
{
// index
if
(
!
treeish
)
{
// index
const
{
stdout
}
=
await
this
.
run
([
'
ls-files
'
,
'
--stage
'
,
'
--
'
,
path
]);
const
elements
=
await
this
.
lsfiles
(
path
);
const
match
=
/^
(\d
+
)\s
+
([
0-9a-f
]{40})\s
+
(\d
+
)
/
.
exec
(
stdout
);
if
(
!
match
)
{
if
(
elements
.
length
===
0
)
{
throw
new
GitError
({
message
:
'
Error running ls-files
'
});
throw
new
GitError
({
message
:
'
Error running ls-files
'
});
}
}
const
[,
mode
,
object
]
=
match
;
const
{
mode
,
object
}
=
elements
[
0
]
;
const
catFile
=
await
this
.
run
([
'
cat-file
'
,
'
-s
'
,
object
]);
const
catFile
=
await
this
.
run
([
'
cat-file
'
,
'
-s
'
,
object
]);
const
size
=
parseInt
(
catFile
.
stdout
);
const
size
=
parseInt
(
catFile
.
stdout
);
return
{
mode
,
object
,
size
};
return
{
mode
,
object
,
size
};
}
}
const
{
stdout
}
=
await
this
.
run
([
'
ls-tree
'
,
'
-l
'
,
treeish
,
'
--
'
,
path
]);
const
elements
=
await
this
.
lstree
(
treeish
,
path
);
const
match
=
/^
(\d
+
)\s
+
(\w
+
)\s
+
([
0-9a-f
]{40})\s
+
(\d
+
)
/
.
exec
(
stdout
);
if
(
!
match
)
{
if
(
elements
.
length
===
0
)
{
throw
new
GitError
({
message
:
'
Error running ls-
tree
'
});
throw
new
GitError
({
message
:
'
Error running ls-
files
'
});
}
}
const
[,
mode
,
,
object
,
size
]
=
match
;
const
{
mode
,
object
,
size
}
=
elements
[
0
]
;
return
{
mode
,
object
,
size
:
parseInt
(
size
)
};
return
{
mode
,
object
,
size
:
parseInt
(
size
)
};
}
}
async
lstree
2
(
treeish
:
string
,
path
:
string
):
Promise
<
LsTreeElement
[]
>
{
async
lstree
(
treeish
:
string
,
path
:
string
):
Promise
<
LsTreeElement
[]
>
{
const
{
stdout
}
=
await
this
.
run
([
'
ls-tree
'
,
treeish
,
'
--
'
,
path
]);
const
{
stdout
}
=
await
this
.
run
([
'
ls-tree
'
,
'
-l
'
,
treeish
,
'
--
'
,
path
]);
return
parseLsTree
(
stdout
);
return
parseLsTree
(
stdout
);
}
}
...
@@ -801,7 +798,7 @@ export class Repository {
...
@@ -801,7 +798,7 @@ export class Repository {
async
getGitRelativePath
(
treeish
:
string
,
relativePath
:
string
):
Promise
<
string
>
{
async
getGitRelativePath
(
treeish
:
string
,
relativePath
:
string
):
Promise
<
string
>
{
const
relativePathLowercase
=
relativePath
.
toLowerCase
();
const
relativePathLowercase
=
relativePath
.
toLowerCase
();
const
dirname
=
path
.
posix
.
dirname
(
relativePath
)
+
'
/
'
;
const
dirname
=
path
.
posix
.
dirname
(
relativePath
)
+
'
/
'
;
const
elements
:
{
file
:
string
;
}[]
=
treeish
?
await
this
.
lstree
2
(
treeish
,
dirname
)
:
await
this
.
lsfiles
(
dirname
);
const
elements
:
{
file
:
string
;
}[]
=
treeish
?
await
this
.
lstree
(
treeish
,
dirname
)
:
await
this
.
lsfiles
(
dirname
);
const
element
=
elements
.
filter
(
file
=>
file
.
file
.
toLowerCase
()
===
relativePathLowercase
)[
0
];
const
element
=
elements
.
filter
(
file
=>
file
.
file
.
toLowerCase
()
===
relativePathLowercase
)[
0
];
if
(
!
element
)
{
if
(
!
element
)
{
...
@@ -893,7 +890,7 @@ export class Repository {
...
@@ -893,7 +890,7 @@ export class Repository {
let
mode
:
string
;
let
mode
:
string
;
try
{
try
{
const
details
=
await
this
.
lstree
(
'
HEAD
'
,
path
);
const
details
=
await
this
.
getObjectDetails
(
'
HEAD
'
,
path
);
mode
=
details
.
mode
;
mode
=
details
.
mode
;
}
catch
(
err
)
{
}
catch
(
err
)
{
mode
=
'
100644
'
;
mode
=
'
100644
'
;
...
...
extensions/git/src/repository.ts
浏览文件 @
b6781b00
...
@@ -299,7 +299,7 @@ export enum Operation {
...
@@ -299,7 +299,7 @@ export enum Operation {
Tag
=
'
Tag
'
,
Tag
=
'
Tag
'
,
Stash
=
'
Stash
'
,
Stash
=
'
Stash
'
,
CheckIgnore
=
'
CheckIgnore
'
,
CheckIgnore
=
'
CheckIgnore
'
,
LSTree
=
'
LSTree
'
,
GetObjectDetails
=
'
GetObjectDetails
'
,
SubmoduleUpdate
=
'
SubmoduleUpdate
'
,
SubmoduleUpdate
=
'
SubmoduleUpdate
'
,
RebaseContinue
=
'
RebaseContinue
'
,
RebaseContinue
=
'
RebaseContinue
'
,
}
}
...
@@ -309,7 +309,7 @@ function isReadOnly(operation: Operation): boolean {
...
@@ -309,7 +309,7 @@ function isReadOnly(operation: Operation): boolean {
case
Operation
.
Show
:
case
Operation
.
Show
:
case
Operation
.
GetCommitTemplate
:
case
Operation
.
GetCommitTemplate
:
case
Operation
.
CheckIgnore
:
case
Operation
.
CheckIgnore
:
case
Operation
.
LSTree
:
case
Operation
.
GetObjectDetails
:
return
true
;
return
true
;
default
:
default
:
return
false
;
return
false
;
...
@@ -320,7 +320,7 @@ function shouldShowProgress(operation: Operation): boolean {
...
@@ -320,7 +320,7 @@ function shouldShowProgress(operation: Operation): boolean {
switch
(
operation
)
{
switch
(
operation
)
{
case
Operation
.
Fetch
:
case
Operation
.
Fetch
:
case
Operation
.
CheckIgnore
:
case
Operation
.
CheckIgnore
:
case
Operation
.
LSTree
:
case
Operation
.
GetObjectDetails
:
case
Operation
.
Show
:
case
Operation
.
Show
:
return
false
;
return
false
;
default
:
default
:
...
@@ -906,8 +906,8 @@ export class Repository implements Disposable {
...
@@ -906,8 +906,8 @@ export class Repository implements Disposable {
});
});
}
}
lstree
(
ref
:
string
,
filePath
:
string
):
Promise
<
{
mode
:
string
,
object
:
string
,
size
:
number
}
>
{
getObjectDetails
(
ref
:
string
,
filePath
:
string
):
Promise
<
{
mode
:
string
,
object
:
string
,
size
:
number
}
>
{
return
this
.
run
(
Operation
.
LSTree
,
()
=>
this
.
repository
.
lstree
(
ref
,
filePath
));
return
this
.
run
(
Operation
.
GetObjectDetails
,
()
=>
this
.
repository
.
getObjectDetails
(
ref
,
filePath
));
}
}
detectObjectType
(
object
:
string
):
Promise
<
{
mimetype
:
string
,
encoding
?:
string
}
>
{
detectObjectType
(
object
:
string
):
Promise
<
{
mimetype
:
string
,
encoding
?:
string
}
>
{
...
...
extensions/git/src/test/git.test.ts
浏览文件 @
b6781b00
...
@@ -216,32 +216,32 @@ This is a commit message.`;
...
@@ -216,32 +216,32 @@ This is a commit message.`;
suite
(
'
parseLsTree
'
,
function
()
{
suite
(
'
parseLsTree
'
,
function
()
{
test
(
'
sample
'
,
function
()
{
test
(
'
sample
'
,
function
()
{
const
input
=
`040000 tree 0274a81f8ee9ca3669295dc40f510bd2021d0043 .vscode
const
input
=
`040000 tree 0274a81f8ee9ca3669295dc40f510bd2021d0043
-
.vscode
100644 blob 1d487c1817262e4f20efbfa1d04c18f51b0046f6 Screen Shot 2018-06-01 at 14.48.05.png
100644 blob 1d487c1817262e4f20efbfa1d04c18f51b0046f6
491570
Screen Shot 2018-06-01 at 14.48.05.png
100644 blob 686c16e4f019b734655a2576ce8b98749a9ffdb9 Screen Shot 2018-06-07 at 20.04.59.png
100644 blob 686c16e4f019b734655a2576ce8b98749a9ffdb9
764420
Screen Shot 2018-06-07 at 20.04.59.png
100644 blob 257cc5642cb1a054f08cc83f2d943e56fd3ebe99 boom.txt
100644 blob 257cc5642cb1a054f08cc83f2d943e56fd3ebe99
4
boom.txt
100644 blob 86dc360dd25f13fa50ffdc8259e9653921f4f2b7 boomcaboom.txt
100644 blob 86dc360dd25f13fa50ffdc8259e9653921f4f2b7
11
boomcaboom.txt
100644 blob a68b14060589b16d7ac75f67b905c918c03c06eb file.js
100644 blob a68b14060589b16d7ac75f67b905c918c03c06eb
24
file.js
100644 blob f7bcfb05af46850d780f88c069edcd57481d822d file.md
100644 blob f7bcfb05af46850d780f88c069edcd57481d822d
201
file.md
100644 blob ab8b86114a051f6490f1ec5e3141b9a632fb46b5 hello.js
100644 blob ab8b86114a051f6490f1ec5e3141b9a632fb46b5
8
hello.js
100644 blob 257cc5642cb1a054f08cc83f2d943e56fd3ebe99 what.js
100644 blob 257cc5642cb1a054f08cc83f2d943e56fd3ebe99
4
what.js
100644 blob be859e3f412fa86513cd8bebe8189d1ea1a3e46d what.txt
100644 blob be859e3f412fa86513cd8bebe8189d1ea1a3e46d
24
what.txt
100644 blob 56ec42c9dc6fcf4534788f0fe34b36e09f37d085 what.txt2`
;
100644 blob 56ec42c9dc6fcf4534788f0fe34b36e09f37d085
261186
what.txt2`
;
const
output
=
parseLsTree
(
input
);
const
output
=
parseLsTree
(
input
);
assert
.
deepEqual
(
output
,
[
assert
.
deepEqual
(
output
,
[
{
mode
:
'
040000
'
,
type
:
'
tree
'
,
object
:
'
0274a81f8ee9ca3669295dc40f510bd2021d0043
'
,
file
:
'
.vscode
'
},
{
mode
:
'
040000
'
,
type
:
'
tree
'
,
object
:
'
0274a81f8ee9ca3669295dc40f510bd2021d0043
'
,
size
:
'
-
'
,
file
:
'
.vscode
'
},
{
mode
:
'
100644
'
,
type
:
'
blob
'
,
object
:
'
1d487c1817262e4f20efbfa1d04c18f51b0046f6
'
,
file
:
'
Screen Shot 2018-06-01 at 14.48.05.png
'
},
{
mode
:
'
100644
'
,
type
:
'
blob
'
,
object
:
'
1d487c1817262e4f20efbfa1d04c18f51b0046f6
'
,
size
:
'
491570
'
,
file
:
'
Screen Shot 2018-06-01 at 14.48.05.png
'
},
{
mode
:
'
100644
'
,
type
:
'
blob
'
,
object
:
'
686c16e4f019b734655a2576ce8b98749a9ffdb9
'
,
file
:
'
Screen Shot 2018-06-07 at 20.04.59.png
'
},
{
mode
:
'
100644
'
,
type
:
'
blob
'
,
object
:
'
686c16e4f019b734655a2576ce8b98749a9ffdb9
'
,
size
:
'
764420
'
,
file
:
'
Screen Shot 2018-06-07 at 20.04.59.png
'
},
{
mode
:
'
100644
'
,
type
:
'
blob
'
,
object
:
'
257cc5642cb1a054f08cc83f2d943e56fd3ebe99
'
,
file
:
'
boom.txt
'
},
{
mode
:
'
100644
'
,
type
:
'
blob
'
,
object
:
'
257cc5642cb1a054f08cc83f2d943e56fd3ebe99
'
,
size
:
'
4
'
,
file
:
'
boom.txt
'
},
{
mode
:
'
100644
'
,
type
:
'
blob
'
,
object
:
'
86dc360dd25f13fa50ffdc8259e9653921f4f2b7
'
,
file
:
'
boomcaboom.txt
'
},
{
mode
:
'
100644
'
,
type
:
'
blob
'
,
object
:
'
86dc360dd25f13fa50ffdc8259e9653921f4f2b7
'
,
size
:
'
11
'
,
file
:
'
boomcaboom.txt
'
},
{
mode
:
'
100644
'
,
type
:
'
blob
'
,
object
:
'
a68b14060589b16d7ac75f67b905c918c03c06eb
'
,
file
:
'
file.js
'
},
{
mode
:
'
100644
'
,
type
:
'
blob
'
,
object
:
'
a68b14060589b16d7ac75f67b905c918c03c06eb
'
,
size
:
'
24
'
,
file
:
'
file.js
'
},
{
mode
:
'
100644
'
,
type
:
'
blob
'
,
object
:
'
f7bcfb05af46850d780f88c069edcd57481d822d
'
,
file
:
'
file.md
'
},
{
mode
:
'
100644
'
,
type
:
'
blob
'
,
object
:
'
f7bcfb05af46850d780f88c069edcd57481d822d
'
,
size
:
'
201
'
,
file
:
'
file.md
'
},
{
mode
:
'
100644
'
,
type
:
'
blob
'
,
object
:
'
ab8b86114a051f6490f1ec5e3141b9a632fb46b5
'
,
file
:
'
hello.js
'
},
{
mode
:
'
100644
'
,
type
:
'
blob
'
,
object
:
'
ab8b86114a051f6490f1ec5e3141b9a632fb46b5
'
,
size
:
'
8
'
,
file
:
'
hello.js
'
},
{
mode
:
'
100644
'
,
type
:
'
blob
'
,
object
:
'
257cc5642cb1a054f08cc83f2d943e56fd3ebe99
'
,
file
:
'
what.js
'
},
{
mode
:
'
100644
'
,
type
:
'
blob
'
,
object
:
'
257cc5642cb1a054f08cc83f2d943e56fd3ebe99
'
,
size
:
'
4
'
,
file
:
'
what.js
'
},
{
mode
:
'
100644
'
,
type
:
'
blob
'
,
object
:
'
be859e3f412fa86513cd8bebe8189d1ea1a3e46d
'
,
file
:
'
what.txt
'
},
{
mode
:
'
100644
'
,
type
:
'
blob
'
,
object
:
'
be859e3f412fa86513cd8bebe8189d1ea1a3e46d
'
,
size
:
'
24
'
,
file
:
'
what.txt
'
},
{
mode
:
'
100644
'
,
type
:
'
blob
'
,
object
:
'
56ec42c9dc6fcf4534788f0fe34b36e09f37d085
'
,
file
:
'
what.txt2
'
}
{
mode
:
'
100644
'
,
type
:
'
blob
'
,
object
:
'
56ec42c9dc6fcf4534788f0fe34b36e09f37d085
'
,
size
:
'
261186
'
,
file
:
'
what.txt2
'
}
]);
]);
});
});
});
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录