Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
git
提交
94537c78
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,发现更多精彩内容 >>
提交
94537c78
编写于
4月 22, 2005
作者:
L
Linus Torvalds
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move "read_tree()" to "tree.c" to be used as a generic helper function.
Next step: make "diff-cache" use it.
上级
aba06682
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
71 addition
and
63 deletion
+71
-63
cache.h
cache.h
+3
-0
read-tree.c
read-tree.c
+3
-63
tree.c
tree.c
+65
-0
未找到文件。
cache.h
浏览文件 @
94537c78
...
...
@@ -122,6 +122,9 @@ extern void * read_sha1_file(const unsigned char *sha1, char *type, unsigned lon
extern
int
write_sha1_file
(
char
*
buf
,
unsigned
len
,
unsigned
char
*
return_sha1
);
extern
int
check_sha1_signature
(
unsigned
char
*
sha1
,
void
*
buf
,
unsigned
long
size
,
const
char
*
type
);
/* Read a tree into the cache */
extern
int
read_tree
(
void
*
buffer
,
unsigned
long
size
,
int
stage
);
/* Convert to/from hex/sha1 representation */
extern
int
get_sha1_hex
(
const
char
*
hex
,
unsigned
char
*
sha1
);
extern
char
*
sha1_to_hex
(
const
unsigned
char
*
sha1
);
/* static buffer result! */
...
...
read-tree.c
浏览文件 @
94537c78
...
...
@@ -7,67 +7,7 @@
static
int
stage
=
0
;
static
int
read_one_entry
(
unsigned
char
*
sha1
,
const
char
*
base
,
int
baselen
,
const
char
*
pathname
,
unsigned
mode
)
{
int
len
=
strlen
(
pathname
);
unsigned
int
size
=
cache_entry_size
(
baselen
+
len
);
struct
cache_entry
*
ce
=
malloc
(
size
);
memset
(
ce
,
0
,
size
);
ce
->
ce_mode
=
create_ce_mode
(
mode
);
ce
->
ce_flags
=
create_ce_flags
(
baselen
+
len
,
stage
);
memcpy
(
ce
->
name
,
base
,
baselen
);
memcpy
(
ce
->
name
+
baselen
,
pathname
,
len
+
1
);
memcpy
(
ce
->
sha1
,
sha1
,
20
);
return
add_cache_entry
(
ce
,
1
);
}
static
int
read_tree_recursive
(
void
*
buffer
,
unsigned
long
size
,
const
char
*
base
,
int
baselen
)
{
while
(
size
)
{
int
len
=
strlen
(
buffer
)
+
1
;
unsigned
char
*
sha1
=
buffer
+
len
;
char
*
path
=
strchr
(
buffer
,
' '
)
+
1
;
unsigned
int
mode
;
if
(
size
<
len
+
20
||
sscanf
(
buffer
,
"%o"
,
&
mode
)
!=
1
)
return
-
1
;
buffer
=
sha1
+
20
;
size
-=
len
+
20
;
if
(
S_ISDIR
(
mode
))
{
int
retval
;
int
pathlen
=
strlen
(
path
);
char
*
newbase
=
malloc
(
baselen
+
1
+
pathlen
);
void
*
eltbuf
;
char
elttype
[
20
];
unsigned
long
eltsize
;
eltbuf
=
read_sha1_file
(
sha1
,
elttype
,
&
eltsize
);
if
(
!
eltbuf
||
strcmp
(
elttype
,
"tree"
))
return
-
1
;
memcpy
(
newbase
,
base
,
baselen
);
memcpy
(
newbase
+
baselen
,
path
,
pathlen
);
newbase
[
baselen
+
pathlen
]
=
'/'
;
retval
=
read_tree_recursive
(
eltbuf
,
eltsize
,
newbase
,
baselen
+
pathlen
+
1
);
free
(
eltbuf
);
free
(
newbase
);
if
(
retval
)
return
-
1
;
continue
;
}
if
(
read_one_entry
(
sha1
,
base
,
baselen
,
path
,
mode
)
<
0
)
return
-
1
;
}
return
0
;
}
static
int
read_tree
(
unsigned
char
*
sha1
,
const
char
*
base
,
int
baselen
)
static
int
unpack_tree
(
unsigned
char
*
sha1
)
{
void
*
buffer
;
unsigned
long
size
;
...
...
@@ -75,7 +15,7 @@ static int read_tree(unsigned char *sha1, const char *base, int baselen)
buffer
=
read_tree_with_tree_or_commit_sha1
(
sha1
,
&
size
,
0
);
if
(
!
buffer
)
return
-
1
;
return
read_tree
_recursive
(
buffer
,
size
,
base
,
baselen
);
return
read_tree
(
buffer
,
size
,
stage
);
}
static
char
*
lockfile_name
;
...
...
@@ -255,7 +195,7 @@ int main(int argc, char **argv)
usage
(
read_tree_usage
);
if
(
stage
>
3
)
usage
(
read_tree_usage
);
if
(
read_tree
(
sha1
,
""
,
0
)
<
0
)
if
(
unpack_tree
(
sha1
)
<
0
)
die
(
"failed to unpack tree object %s"
,
arg
);
stage
++
;
}
...
...
tree.c
浏览文件 @
94537c78
...
...
@@ -5,6 +5,71 @@
const
char
*
tree_type
=
"tree"
;
static
int
read_one_entry
(
unsigned
char
*
sha1
,
const
char
*
base
,
int
baselen
,
const
char
*
pathname
,
unsigned
mode
,
int
stage
)
{
int
len
=
strlen
(
pathname
);
unsigned
int
size
=
cache_entry_size
(
baselen
+
len
);
struct
cache_entry
*
ce
=
malloc
(
size
);
memset
(
ce
,
0
,
size
);
ce
->
ce_mode
=
create_ce_mode
(
mode
);
ce
->
ce_flags
=
create_ce_flags
(
baselen
+
len
,
stage
);
memcpy
(
ce
->
name
,
base
,
baselen
);
memcpy
(
ce
->
name
+
baselen
,
pathname
,
len
+
1
);
memcpy
(
ce
->
sha1
,
sha1
,
20
);
return
add_cache_entry
(
ce
,
1
);
}
static
int
read_tree_recursive
(
void
*
buffer
,
unsigned
long
size
,
const
char
*
base
,
int
baselen
,
int
stage
)
{
while
(
size
)
{
int
len
=
strlen
(
buffer
)
+
1
;
unsigned
char
*
sha1
=
buffer
+
len
;
char
*
path
=
strchr
(
buffer
,
' '
)
+
1
;
unsigned
int
mode
;
if
(
size
<
len
+
20
||
sscanf
(
buffer
,
"%o"
,
&
mode
)
!=
1
)
return
-
1
;
buffer
=
sha1
+
20
;
size
-=
len
+
20
;
if
(
S_ISDIR
(
mode
))
{
int
retval
;
int
pathlen
=
strlen
(
path
);
char
*
newbase
=
malloc
(
baselen
+
1
+
pathlen
);
void
*
eltbuf
;
char
elttype
[
20
];
unsigned
long
eltsize
;
eltbuf
=
read_sha1_file
(
sha1
,
elttype
,
&
eltsize
);
if
(
!
eltbuf
||
strcmp
(
elttype
,
"tree"
))
return
-
1
;
memcpy
(
newbase
,
base
,
baselen
);
memcpy
(
newbase
+
baselen
,
path
,
pathlen
);
newbase
[
baselen
+
pathlen
]
=
'/'
;
retval
=
read_tree_recursive
(
eltbuf
,
eltsize
,
newbase
,
baselen
+
pathlen
+
1
,
stage
);
free
(
eltbuf
);
free
(
newbase
);
if
(
retval
)
return
-
1
;
continue
;
}
if
(
read_one_entry
(
sha1
,
base
,
baselen
,
path
,
mode
,
stage
)
<
0
)
return
-
1
;
}
return
0
;
}
int
read_tree
(
void
*
buffer
,
unsigned
long
size
,
int
stage
)
{
return
read_tree_recursive
(
buffer
,
size
,
""
,
0
,
stage
);
}
struct
tree
*
lookup_tree
(
unsigned
char
*
sha1
)
{
struct
object
*
obj
=
lookup_object
(
sha1
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录