Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jobily
Libgit2sharp
提交
98157253
L
Libgit2sharp
项目概览
jobily
/
Libgit2sharp
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
Libgit2sharp
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
98157253
编写于
12月 09, 2010
作者:
N
nulltoken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added string to byte[] conversion method to ObjectId.
上级
06315111
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
77 addition
and
10 deletion
+77
-10
libgit2sharp.Tests/ObjectIdFixture.cs
libgit2sharp.Tests/ObjectIdFixture.cs
+31
-0
libgit2sharp.Tests/libgit2sharp.Tests.csproj
libgit2sharp.Tests/libgit2sharp.Tests.csproj
+1
-0
libgit2sharp/ObjectId.cs
libgit2sharp/ObjectId.cs
+44
-10
libgit2sharp/Wrapper/Constants.cs
libgit2sharp/Wrapper/Constants.cs
+1
-0
未找到文件。
libgit2sharp.Tests/ObjectIdFixture.cs
0 → 100644
浏览文件 @
98157253
using
System
;
using
NUnit.Framework
;
namespace
libgit2sharp.Tests
{
[
TestFixture
]
public
class
ObjectIdFixture
{
[
TestCase
(
"DDelORu/9Dw38NA3GCOlUJ7tWx0="
,
"0c37a5391bbff43c37f0d0371823a5509eed5b1d"
)]
[
TestCase
(
"FqASNFZ4mrze9Ld1ITwjqL109eA="
,
"16a0123456789abcdef4b775213c23a8bd74f5e0"
)]
public
void
ToString
(
string
encoded
,
string
expected
)
{
byte
[]
id
=
Convert
.
FromBase64String
(
encoded
);
string
objectId
=
ObjectId
.
ToString
(
id
);
Assert
.
AreEqual
(
expected
,
objectId
);
}
[
TestCase
(
"0c37a5391bbff43c37f0d0371823a5509eed5b1d"
,
"DDelORu/9Dw38NA3GCOlUJ7tWx0="
)]
[
TestCase
(
"16a0123456789abcdef4b775213c23a8bd74f5e0"
,
"FqASNFZ4mrze9Ld1ITwjqL109eA="
)]
public
void
ToByteArray
(
string
objectId
,
string
expected
)
{
byte
[]
id
=
Convert
.
FromBase64String
(
expected
);
byte
[]
rawId
=
ObjectId
.
ToByteArray
(
objectId
);
CollectionAssert
.
AreEqual
(
id
,
rawId
);
}
}
}
\ No newline at end of file
libgit2sharp.Tests/libgit2sharp.Tests.csproj
浏览文件 @
98157253
...
...
@@ -44,6 +44,7 @@
</ItemGroup>
<ItemGroup>
<Compile
Include=
"EpochHelperFixture.cs"
/>
<Compile
Include=
"ObjectIdFixture.cs"
/>
<Compile
Include=
"RepositoryFixtures.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
</ItemGroup>
...
...
libgit2sharp/ObjectId.cs
浏览文件 @
98157253
using
System.Diagnostics
;
using
System
;
using
System.Diagnostics
;
using
libgit2sharp.Wrapper
;
namespace
libgit2sharp
{
public
static
class
ObjectId
{
private
static
readonly
char
[]
hexDigits
=
new
[]
{
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
};
private
static
readonly
char
[]
HexDigits
=
"0123456789abcdef"
.
ToCharArray
();
private
static
readonly
byte
[]
ReverseHexDigits
=
BuildReverseHexDigits
();
private
static
byte
[]
BuildReverseHexDigits
()
{
var
bytes
=
new
byte
[
'f'
-
'0'
+
1
];
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
bytes
[
i
]
=
(
byte
)
i
;
}
for
(
int
i
=
10
;
i
<
16
;
i
++)
{
bytes
[
i
+
'a'
-
'0'
-
0x0a
]
=
(
byte
)(
i
);
}
return
bytes
;
}
public
static
string
ToString
(
byte
[]
id
)
{
...
...
@@ -17,19 +32,38 @@ public static string ToString(byte[] id)
// Inspired from http://stackoverflow.com/questions/623104/c-byte-to-hex-string/3974535#3974535
var
c
=
new
char
[
Constants
.
GIT_OID_
RAWSZ
*
2
];
var
c
=
new
char
[
Constants
.
GIT_OID_
HEXSZ
];
for
(
int
i
=
0
;
i
<
Constants
.
GIT_OID_
RAWSZ
*
2
;
i
++)
for
(
int
i
=
0
;
i
<
Constants
.
GIT_OID_
HEXSZ
;
i
++)
{
int
index0
=
i
>>
1
;
var
b
=
((
byte
)(
id
[
index0
]
>>
4
));
c
[
i
++]
=
h
exDigits
[
b
];
c
[
i
++]
=
H
exDigits
[
b
];
b
=
((
byte
)(
id
[
index0
]
&
0x0F
));
c
[
i
]
=
h
exDigits
[
b
];
c
[
i
]
=
H
exDigits
[
b
];
}
return
new
string
(
c
);
}
public
static
byte
[]
ToByteArray
(
string
id
)
{
Debug
.
Assert
(
id
!=
null
&&
id
.
Length
==
Constants
.
GIT_OID_HEXSZ
);
var
bytes
=
new
byte
[
Constants
.
GIT_OID_RAWSZ
];
for
(
int
i
=
0
;
i
<
Constants
.
GIT_OID_HEXSZ
;
i
++)
{
int
c1
=
ByteConverter
(
id
[
i
++])
<<
4
;
int
c2
=
ByteConverter
(
id
[
i
]);
bytes
[
i
>>
1
]
=
(
byte
)(
c1
+
c2
);
}
return
bytes
;
}
private
static
readonly
Func
<
int
,
byte
>
ByteConverter
=
i
=>
ReverseHexDigits
[
i
-
'0'
];
}
}
\ No newline at end of file
libgit2sharp/Wrapper/Constants.cs
浏览文件 @
98157253
...
...
@@ -5,5 +5,6 @@ public static class Constants
//public const int GIT_PATH_MAX = 4096;
public
const
int
GIT_ERROR
=
-
1
;
public
const
int
GIT_OID_RAWSZ
=
20
;
public
const
int
GIT_OID_HEXSZ
=
GIT_OID_RAWSZ
*
2
;
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录