Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
git
提交
74536958
G
git
项目概览
李少辉-开发者
/
git
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
git
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
74536958
编写于
6月 25, 2005
作者:
L
Linus Torvalds
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
git-unpack-objects: start parsing the actual packed data
So far we just print out the type and size.
上级
d38c3721
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
58 addition
and
5 deletion
+58
-5
unpack-objects.c
unpack-objects.c
+58
-5
未找到文件。
unpack-objects.c
浏览文件 @
74536958
#include "cache.h"
#include "object.h"
static
int
dry_run
;
static
int
nr_entries
;
static
const
char
*
base_name
;
static
const
char
unpack_usage
[]
=
"git-unpack-objects basename"
;
...
...
@@ -9,6 +11,9 @@ struct pack_entry {
unsigned
char
sha1
[
20
];
};
static
void
*
pack_base
;
static
unsigned
long
pack_size
;
static
struct
pack_entry
**
pack_list
;
static
void
*
map_file
(
const
char
*
suffix
,
unsigned
long
*
sizep
)
...
...
@@ -63,7 +68,7 @@ static int check_index(void *index, unsigned long idx_size)
nr
=
n
;
}
if
(
idx_size
!=
4
*
256
+
nr
*
24
)
{
printf
(
"idx_size=%
d, expected %d (%d
)
\n
"
,
idx_size
,
4
*
256
+
nr
*
24
,
nr
);
printf
(
"idx_size=%
lu, expected %u (%u
)
\n
"
,
idx_size
,
4
*
256
+
nr
*
24
,
nr
);
return
error
(
"wrong index file size"
);
}
...
...
@@ -78,17 +83,64 @@ static int check_index(void *index, unsigned long idx_size)
return
0
;
}
static
void
unpack_entry
(
struct
pack_entry
*
entry
)
{
unsigned
long
size
;
unsigned
long
offset
;
unsigned
char
*
pack
;
/* Have we done this one already due to deltas based on it? */
if
(
lookup_object
(
entry
->
sha1
))
return
;
offset
=
ntohl
(
entry
->
offset
);
if
(
offset
>
pack_size
-
5
)
die
(
"object offset outside of pack file"
);
pack
=
pack_base
+
offset
;
offset
=
pack_size
-
offset
;
switch
(
*
pack
)
{
case
'C'
:
case
'T'
:
case
'B'
:
size
=
(
pack
[
1
]
<<
24
)
+
(
pack
[
2
]
<<
16
)
+
(
pack
[
3
]
<<
8
)
+
pack
[
4
];
printf
(
"%s %c %lu
\n
"
,
sha1_to_hex
(
entry
->
sha1
),
*
pack
,
size
);
break
;
case
'D'
:
printf
(
"%s D"
,
sha1_to_hex
(
entry
->
sha1
));
printf
(
" %s
\n
"
,
sha1_to_hex
(
pack
+
1
));
break
;
default:
die
(
"corrupted pack file"
);
}
}
/*
* We unpack from the end, older files first. Now, usually
* there are deltas etc, so we'll not actually write the
* objects in that order, but we might as well try..
*/
static
void
unpack_all
(
void
)
{
int
i
=
nr_entries
;
while
(
--
i
>=
0
)
{
struct
pack_entry
*
entry
=
pack_list
[
i
];
unpack_entry
(
entry
);
}
}
int
main
(
int
argc
,
char
**
argv
)
{
int
i
;
unsigned
long
idx_size
,
pack_size
;
void
*
index
,
*
pack
;
unsigned
long
idx_size
;
void
*
index
;
for
(
i
=
1
;
i
<
argc
;
i
++
)
{
const
char
*
arg
=
argv
[
i
];
if
(
*
arg
==
'-'
)
{
/* Maybe we'll have some flags here some day.. */
if
(
!
strcmp
(
arg
,
"-n"
))
{
dry_run
=
1
;
continue
;
}
usage
(
unpack_usage
);
}
if
(
base_name
)
...
...
@@ -98,8 +150,9 @@ int main(int argc, char **argv)
if
(
!
base_name
)
usage
(
unpack_usage
);
index
=
map_file
(
"idx"
,
&
idx_size
);
pack
=
map_file
(
"pack"
,
&
pack_size
);
pack
_base
=
map_file
(
"pack"
,
&
pack_size
);
if
(
check_index
(
index
,
idx_size
)
<
0
)
die
(
"bad index file"
);
unpack_all
();
return
0
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录