Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
git
提交
6aa33f40
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,发现更多精彩内容 >>
提交
6aa33f40
编写于
7月 12, 2005
作者:
L
Linus Torvalds
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Abstract out the "name <email> date" handling of commit-tree.c
We'll want to use it for the tagging too.
上级
26a2d8ae
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
156 addition
and
71 deletion
+156
-71
Makefile
Makefile
+1
-1
cache.h
cache.h
+3
-0
commit-tree.c
commit-tree.c
+14
-70
ident.c
ident.c
+138
-0
未找到文件。
Makefile
浏览文件 @
6aa33f40
...
...
@@ -58,7 +58,7 @@ install: $(PROG) $(SCRIPTS)
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 path.o
\
epoch.o refs.o csum-file.o pack-check.o pkt-line.o connect.o
epoch.o refs.o csum-file.o pack-check.o pkt-line.o connect.o
ident.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
\
pack.h pkt-line.h refs.h
...
...
cache.h
浏览文件 @
6aa33f40
...
...
@@ -211,6 +211,9 @@ const char *show_date(unsigned long time, int timezone);
void
parse_date
(
const
char
*
date
,
char
*
buf
,
int
bufsize
);
void
datestamp
(
char
*
buf
,
int
bufsize
);
extern
int
setup_ident
(
void
);
extern
char
*
get_ident
(
const
char
*
name
,
const
char
*
email
,
const
char
*
date_str
);
static
inline
void
*
xmalloc
(
size_t
size
)
{
void
*
ret
=
malloc
(
size
);
...
...
commit-tree.c
浏览文件 @
6aa33f40
...
...
@@ -45,39 +45,6 @@ static void add_buffer(char **bufp, unsigned int *sizep, const char *fmt, ...)
memcpy
(
buf
+
size
,
one_line
,
len
);
}
static
void
remove_special
(
char
*
p
)
{
char
c
;
char
*
dst
=
p
,
*
src
=
p
;
for
(;;)
{
c
=
*
src
;
src
++
;
switch
(
c
)
{
case
'\n'
:
case
'<'
:
case
'>'
:
continue
;
}
*
dst
++
=
c
;
if
(
!
c
)
break
;
}
/*
* Go back, and remove crud from the end: some people
* have commas etc in their gecos field
*/
dst
--
;
while
(
--
dst
>=
p
)
{
unsigned
char
c
=
*
dst
;
switch
(
c
)
{
case
','
:
case
';'
:
case
'.'
:
*
dst
=
0
;
continue
;
}
break
;
}
}
static
void
check_valid
(
unsigned
char
*
sha1
,
const
char
*
expect
)
{
void
*
buf
;
...
...
@@ -112,18 +79,23 @@ static int new_parent(int idx)
return
1
;
}
static
char
*
git_author_info
(
void
)
{
return
get_ident
(
gitenv
(
"GIT_AUTHOR_NAME"
),
gitenv
(
"GIT_AUTHOR_EMAIL"
),
gitenv
(
"GIT_AUTHOR_DATE"
));
}
static
char
*
git_committer_info
(
void
)
{
return
get_ident
(
gitenv
(
"GIT_COMMITTER_NAME"
),
gitenv
(
"GIT_COMMITTER_EMAIL"
),
gitenv
(
"GIT_COMMITTER_DATE"
));
}
int
main
(
int
argc
,
char
**
argv
)
{
int
i
,
len
;
int
i
;
int
parents
=
0
;
unsigned
char
tree_sha1
[
20
];
unsigned
char
commit_sha1
[
20
];
char
*
gecos
,
*
realgecos
,
*
commitgecos
;
char
*
email
,
*
commitemail
,
realemail
[
1000
];
char
date
[
50
],
realdate
[
50
];
char
*
audate
,
*
cmdate
;
char
comment
[
1000
];
struct
passwd
*
pw
;
char
*
buffer
;
unsigned
int
size
;
...
...
@@ -142,35 +114,7 @@ int main(int argc, char **argv)
}
if
(
!
parents
)
fprintf
(
stderr
,
"Committing initial tree %s
\n
"
,
argv
[
1
]);
pw
=
getpwuid
(
getuid
());
if
(
!
pw
)
die
(
"You don't exist. Go away!"
);
realgecos
=
pw
->
pw_gecos
;
len
=
strlen
(
pw
->
pw_name
);
memcpy
(
realemail
,
pw
->
pw_name
,
len
);
realemail
[
len
]
=
'@'
;
gethostname
(
realemail
+
len
+
1
,
sizeof
(
realemail
)
-
len
-
1
);
if
(
!
strchr
(
realemail
+
len
+
1
,
'.'
))
{
strcat
(
realemail
,
"."
);
getdomainname
(
realemail
+
strlen
(
realemail
),
sizeof
(
realemail
)
-
strlen
(
realemail
)
-
1
);
}
datestamp
(
realdate
,
sizeof
(
realdate
));
strcpy
(
date
,
realdate
);
commitgecos
=
gitenv
(
"GIT_COMMITTER_NAME"
)
?
:
realgecos
;
commitemail
=
gitenv
(
"GIT_COMMITTER_EMAIL"
)
?
:
realemail
;
gecos
=
gitenv
(
"GIT_AUTHOR_NAME"
)
?
:
realgecos
;
email
=
gitenv
(
"GIT_AUTHOR_EMAIL"
)
?
:
realemail
;
audate
=
gitenv
(
"GIT_AUTHOR_DATE"
);
if
(
audate
)
parse_date
(
audate
,
date
,
sizeof
(
date
));
cmdate
=
gitenv
(
"GIT_COMMITTER_DATE"
);
if
(
cmdate
)
parse_date
(
cmdate
,
realdate
,
sizeof
(
realdate
));
remove_special
(
gecos
);
remove_special
(
realgecos
);
remove_special
(
commitgecos
);
remove_special
(
email
);
remove_special
(
realemail
);
remove_special
(
commitemail
);
setup_ident
();
init_buffer
(
&
buffer
,
&
size
);
add_buffer
(
&
buffer
,
&
size
,
"tree %s
\n
"
,
sha1_to_hex
(
tree_sha1
));
...
...
@@ -184,8 +128,8 @@ int main(int argc, char **argv)
add_buffer
(
&
buffer
,
&
size
,
"parent %s
\n
"
,
sha1_to_hex
(
parent_sha1
[
i
]));
/* Person/date information */
add_buffer
(
&
buffer
,
&
size
,
"author %s
<%s> %s
\n
"
,
gecos
,
email
,
date
);
add_buffer
(
&
buffer
,
&
size
,
"committer %s
<%s> %s
\n\n
"
,
commitgecos
,
commitemail
,
realdate
);
add_buffer
(
&
buffer
,
&
size
,
"author %s
\n
"
,
git_author_info
()
);
add_buffer
(
&
buffer
,
&
size
,
"committer %s
\n\n
"
,
git_committer_info
()
);
/* And add the comment */
while
(
fgets
(
comment
,
sizeof
(
comment
),
stdin
)
!=
NULL
)
...
...
ident.c
0 → 100644
浏览文件 @
6aa33f40
/*
* ident.c
*
* create git identifier lines of the form "name <email> date"
*
* Copyright (C) 2005 Linus Torvalds
*/
#include "cache.h"
#include <pwd.h>
#include <time.h>
#include <ctype.h>
static
char
real_email
[
1000
];
static
char
real_name
[
1000
];
static
char
real_date
[
50
];
int
setup_ident
(
void
)
{
int
len
;
struct
passwd
*
pw
=
getpwuid
(
getuid
());
if
(
!
pw
)
die
(
"You don't exist. Go away!"
);
/* Get the name ("gecos") */
len
=
strlen
(
pw
->
pw_gecos
);
if
(
len
>=
sizeof
(
real_name
))
die
(
"Your parents must have hated you"
);
memcpy
(
real_name
,
pw
->
pw_gecos
,
len
+
1
);
/* Make up a fake email address (name + '@' + hostname [+ '.' + domainname]) */
len
=
strlen
(
pw
->
pw_name
);
if
(
len
>
sizeof
(
real_email
)
/
2
)
die
(
"Your parents must have hated you"
);
memcpy
(
real_email
,
pw
->
pw_name
,
len
);
real_email
[
len
++
]
=
'@'
;
gethostname
(
real_email
+
len
,
sizeof
(
real_email
)
-
len
);
if
(
!
strchr
(
real_email
+
len
,
'.'
))
{
len
=
strlen
(
real_email
);
real_email
[
len
++
]
=
'.'
;
getdomainname
(
real_email
+
len
,
sizeof
(
real_email
)
-
len
);
}
/* And set the default date */
datestamp
(
real_date
,
sizeof
(
real_date
));
return
0
;
}
static
int
add_raw
(
char
*
buf
,
int
size
,
int
offset
,
const
char
*
str
)
{
int
len
=
strlen
(
str
);
if
(
offset
+
len
>
size
)
return
size
;
memcpy
(
buf
+
offset
,
str
,
len
);
return
offset
+
len
;
}
static
int
crud
(
unsigned
char
c
)
{
static
const
char
crud_array
[
256
]
=
{
[
0
...
31
]
=
1
,
[
' '
]
=
1
,
[
'.'
]
=
1
,
[
','
]
=
1
,
[
':'
]
=
1
,
[
';'
]
=
1
,
[
'<'
]
=
1
,
[
'>'
]
=
1
,
[
'"'
]
=
1
,
[
'\''
]
=
1
,
};
return
crud_array
[
c
];
}
/*
* Copy over a string to the destination, but avoid special
* characters ('\n', '<' and '>') and remove crud at the end
*/
static
int
copy
(
char
*
buf
,
int
size
,
int
offset
,
const
char
*
src
)
{
int
i
,
len
;
unsigned
char
c
;
/* Remove crud from the beginning.. */
while
((
c
=
*
src
)
!=
0
)
{
if
(
!
crud
(
c
))
break
;
src
++
;
}
/* Remove crud from the end.. */
len
=
strlen
(
src
);
while
(
len
>
0
)
{
c
=
src
[
len
-
1
];
if
(
!
crud
(
c
))
break
;
--
len
;
}
/*
* Copy the rest to the buffer, but avoid the special
* characters '\n' '<' and '>' that act as delimeters on
* a identification line
*/
for
(
i
=
0
;
i
<
len
;
i
++
)
{
c
=
*
src
++
;
switch
(
c
)
{
case
'\n'
:
case
'<'
:
case
'>'
:
continue
;
}
if
(
offset
>=
size
)
return
size
;
buf
[
offset
++
]
=
c
;
}
return
offset
;
}
char
*
get_ident
(
const
char
*
name
,
const
char
*
email
,
const
char
*
date_str
)
{
static
char
buffer
[
1000
];
char
date
[
50
];
int
i
;
if
(
!
name
)
name
=
real_name
;
if
(
!
email
)
email
=
real_email
;
strcpy
(
date
,
real_date
);
if
(
date_str
)
parse_date
(
date_str
,
date
,
sizeof
(
date
));
i
=
copy
(
buffer
,
sizeof
(
buffer
),
0
,
name
);
i
=
add_raw
(
buffer
,
sizeof
(
buffer
),
i
,
" <"
);
i
=
copy
(
buffer
,
sizeof
(
buffer
),
i
,
email
);
i
=
add_raw
(
buffer
,
sizeof
(
buffer
),
i
,
"> "
);
i
=
copy
(
buffer
,
sizeof
(
buffer
),
i
,
date
);
if
(
i
>=
sizeof
(
buffer
))
die
(
"Impossibly long personal identifier"
);
buffer
[
i
]
=
0
;
return
buffer
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录