Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
git
提交
26c8a533
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,发现更多精彩内容 >>
提交
26c8a533
编写于
7月 08, 2005
作者:
L
Linus Torvalds
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add "mkpath()" helper function
I'm bored with doing it by hand all the time.
上级
5c5dc2fb
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
62 addition
and
29 deletion
+62
-29
Makefile
Makefile
+1
-1
cache.h
cache.h
+1
-0
path.c
path.c
+60
-0
sha1_file.c
sha1_file.c
+0
-28
未找到文件。
Makefile
浏览文件 @
26c8a533
...
...
@@ -56,7 +56,7 @@ install: $(PROG) $(SCRIPTS)
$(INSTALL)
$(PROG)
$(SCRIPTS)
$(dest)$(bin)
LIB_OBJS
=
read-cache.o sha1_file.o usage.o object.o commit.o tree.o blob.o
\
tag.o date.o index.o diff-delta.o patch-delta.o entry.o
\
tag.o date.o index.o diff-delta.o patch-delta.o entry.o
path.o
\
epoch.o refs.o csum-file.o pack-check.o pkt-line.o connect.o
LIB_FILE
=
libgit.a
LIB_H
=
cache.h object.h blob.h tree.h commit.h tag.h delta.h epoch.h csum-file.h
\
...
...
cache.h
浏览文件 @
26c8a533
...
...
@@ -158,6 +158,7 @@ extern void rollback_index_file(struct cache_file *);
#define TYPE_CHANGED 0x0040
/* Return a statically allocated filename matching the sha1 signature */
extern
char
*
mkpath
(
const
char
*
fmt
,
...);
extern
char
*
git_path
(
const
char
*
fmt
,
...);
extern
char
*
sha1_file_name
(
const
unsigned
char
*
sha1
);
...
...
path.c
0 → 100644
浏览文件 @
26c8a533
/*
* I'm tired of doing "vsnprintf()" etc just to open a
* file, so here's a "return static buffer with printf"
* interface for paths.
*
* It's obviously not thread-safe. Sue me. But it's quite
* useful for doing things like
*
* f = open(mkpath("%s/%s.git", base, name), O_RDONLY);
*
* which is what it's designed for.
*/
#include "cache.h"
static
char
pathname
[
PATH_MAX
];
static
char
bad_path
[]
=
"/bad-path/"
;
static
char
*
cleanup_path
(
char
*
path
)
{
/* Clean it up */
if
(
!
memcmp
(
path
,
"./"
,
2
))
{
path
+=
2
;
while
(
*
path
==
'/'
)
path
++
;
}
return
path
;
}
char
*
mkpath
(
const
char
*
fmt
,
...)
{
va_list
args
;
unsigned
len
;
va_start
(
args
,
fmt
);
len
=
vsnprintf
(
pathname
,
PATH_MAX
,
fmt
,
args
);
va_end
(
args
);
if
(
len
>=
PATH_MAX
)
return
bad_path
;
return
cleanup_path
(
pathname
);
}
char
*
git_path
(
const
char
*
fmt
,
...)
{
const
char
*
git_dir
=
gitenv
(
GIT_DIR_ENVIRONMENT
)
?
:
DEFAULT_GIT_DIR_ENVIRONMENT
;
va_list
args
;
unsigned
len
;
len
=
strlen
(
git_dir
);
if
(
len
>
PATH_MAX
-
100
)
return
bad_path
;
memcpy
(
pathname
,
git_dir
,
len
);
if
(
len
&&
git_dir
[
len
-
1
]
!=
'/'
)
pathname
[
len
++
]
=
'/'
;
va_start
(
args
,
fmt
);
len
+=
vsnprintf
(
pathname
+
len
,
PATH_MAX
-
len
,
fmt
,
args
);
va_end
(
args
);
if
(
len
>=
PATH_MAX
)
return
bad_path
;
return
cleanup_path
(
pathname
);
}
sha1_file.c
浏览文件 @
26c8a533
...
...
@@ -102,34 +102,6 @@ char *get_index_file(void)
return
git_index_file
;
}
char
*
git_path
(
const
char
*
fmt
,
...)
{
static
char
pathname
[
PATH_MAX
],
*
ret
;
va_list
args
;
int
len
;
if
(
!
git_dir
)
setup_git_env
();
len
=
strlen
(
git_dir
);
if
(
len
>
PATH_MAX
-
100
)
return
"pad-path"
;
memcpy
(
pathname
,
git_dir
,
len
);
if
(
len
&&
git_dir
[
len
-
1
]
!=
'/'
)
pathname
[
len
++
]
=
'/'
;
va_start
(
args
,
fmt
);
vsnprintf
(
pathname
+
len
,
sizeof
(
pathname
)
-
len
,
fmt
,
args
);
va_end
(
args
);
ret
=
pathname
;
/* Clean it up */
if
(
!
memcmp
(
pathname
,
"./"
,
2
))
{
ret
+=
2
;
while
(
*
ret
==
'/'
)
ret
++
;
}
return
ret
;
}
int
safe_create_leading_directories
(
char
*
path
)
{
char
*
pos
=
path
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录