Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
git
提交
356eff53
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,发现更多精彩内容 >>
提交
356eff53
编写于
2月 20, 2008
作者:
J
Junio C Hamano
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'mc/prefix'
* mc/prefix: Avoid a useless prefix lookup in strbuf_expand()
上级
c0284cea
c3a670de
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
83 addition
and
108 deletion
+83
-108
pretty.c
pretty.c
+73
-95
strbuf.c
strbuf.c
+8
-11
strbuf.h
strbuf.h
+2
-2
未找到文件。
pretty.c
浏览文件 @
356eff53
...
...
@@ -282,59 +282,59 @@ static char *logmsg_reencode(const struct commit *commit,
return
out
;
}
static
void
format_person_part
(
struct
strbuf
*
sb
,
char
part
,
static
size_t
format_person_part
(
struct
strbuf
*
sb
,
char
part
,
const
char
*
msg
,
int
len
)
{
/* currently all placeholders have same length */
const
int
placeholder_len
=
2
;
int
start
,
end
,
tz
=
0
;
unsigned
long
date
;
unsigned
long
date
=
0
;
char
*
ep
;
/*
parse name
*/
/*
advance 'end' to point to email start delimiter
*/
for
(
end
=
0
;
end
<
len
&&
msg
[
end
]
!=
'<'
;
end
++
)
;
/* do nothing */
/*
* If it does not even have a '<' and '>', that is
* quite a bogus commit author and we discard it;
* this is in line with add_user_info() that is used
* in the normal codepath. When end points at the '<'
* that we found, it should have matching '>' later,
* which means start (beginning of email address) must
* be strictly below len.
* When end points at the '<' that we found, it should have
* matching '>' later, which means 'end' must be strictly
* below len - 1.
*/
start
=
end
+
1
;
if
(
start
>=
len
-
1
)
return
;
while
(
end
>
0
&&
isspace
(
msg
[
end
-
1
]))
end
--
;
if
(
end
>=
len
-
2
)
goto
skip
;
if
(
part
==
'n'
)
{
/* name */
while
(
end
>
0
&&
isspace
(
msg
[
end
-
1
]))
end
--
;
strbuf_add
(
sb
,
msg
,
end
);
return
;
return
placeholder_len
;
}
start
=
++
end
;
/* save email start position */
/*
parse email
*/
for
(
end
=
start
;
end
<
len
&&
msg
[
end
]
!=
'>'
;
end
++
)
/*
advance 'end' to point to email end delimiter
*/
for
(
;
end
<
len
&&
msg
[
end
]
!=
'>'
;
end
++
)
;
/* do nothing */
if
(
end
>=
len
)
return
;
goto
skip
;
if
(
part
==
'e'
)
{
/* email */
strbuf_add
(
sb
,
msg
+
start
,
end
-
start
);
return
;
return
placeholder_len
;
}
/*
parse date
*/
/*
advance 'start' to point to date start delimiter
*/
for
(
start
=
end
+
1
;
start
<
len
&&
isspace
(
msg
[
start
]);
start
++
)
;
/* do nothing */
if
(
start
>=
len
)
return
;
goto
skip
;
date
=
strtoul
(
msg
+
start
,
&
ep
,
10
);
if
(
msg
+
start
==
ep
)
return
;
goto
skip
;
if
(
part
==
't'
)
{
/* date, UNIX timestamp */
strbuf_add
(
sb
,
msg
+
start
,
ep
-
(
msg
+
start
));
return
;
return
placeholder_len
;
}
/* parse tz */
...
...
@@ -349,17 +349,28 @@ static void format_person_part(struct strbuf *sb, char part,
switch
(
part
)
{
case
'd'
:
/* date */
strbuf_addstr
(
sb
,
show_date
(
date
,
tz
,
DATE_NORMAL
));
return
;
return
placeholder_len
;
case
'D'
:
/* date, RFC2822 style */
strbuf_addstr
(
sb
,
show_date
(
date
,
tz
,
DATE_RFC2822
));
return
;
return
placeholder_len
;
case
'r'
:
/* date, relative */
strbuf_addstr
(
sb
,
show_date
(
date
,
tz
,
DATE_RELATIVE
));
return
;
return
placeholder_len
;
case
'i'
:
/* date, ISO 8601 */
strbuf_addstr
(
sb
,
show_date
(
date
,
tz
,
DATE_ISO8601
));
return
;
return
placeholder_len
;
}
skip:
/*
* bogus commit, 'sb' cannot be updated, but we still need to
* compute a valid return value.
*/
if
(
part
==
'n'
||
part
==
'e'
||
part
==
't'
||
part
==
'd'
||
part
==
'D'
||
part
==
'r'
||
part
==
'i'
)
return
placeholder_len
;
return
0
;
/* unknown placeholder */
}
struct
chunk
{
...
...
@@ -440,7 +451,7 @@ static void parse_commit_header(struct format_commit_context *context)
context
->
commit_header_parsed
=
1
;
}
static
void
format_commit_item
(
struct
strbuf
*
sb
,
const
char
*
placeholder
,
static
size_t
format_commit_item
(
struct
strbuf
*
sb
,
const
char
*
placeholder
,
void
*
context
)
{
struct
format_commit_context
*
c
=
context
;
...
...
@@ -451,23 +462,23 @@ static void format_commit_item(struct strbuf *sb, const char *placeholder,
/* these are independent of the commit */
switch
(
placeholder
[
0
])
{
case
'C'
:
switch
(
placeholder
[
3
])
{
case
'd'
:
/* red */
if
(
!
prefixcmp
(
placeholder
+
1
,
"red"
))
{
strbuf_addstr
(
sb
,
"
\033
[31m"
);
return
;
case
'e'
:
/* green */
return
4
;
}
else
if
(
!
prefixcmp
(
placeholder
+
1
,
"green"
))
{
strbuf_addstr
(
sb
,
"
\033
[32m"
);
return
;
case
'u'
:
/* blue */
return
6
;
}
else
if
(
!
prefixcmp
(
placeholder
+
1
,
"blue"
))
{
strbuf_addstr
(
sb
,
"
\033
[34m"
);
return
;
case
's'
:
/* reset color */
return
5
;
}
else
if
(
!
prefixcmp
(
placeholder
+
1
,
"reset"
))
{
strbuf_addstr
(
sb
,
"
\033
[m"
);
return
;
}
return
6
;
}
else
return
0
;
case
'n'
:
/* newline */
strbuf_addch
(
sb
,
'\n'
);
return
;
return
1
;
}
/* these depend on the commit */
...
...
@@ -477,34 +488,34 @@ static void format_commit_item(struct strbuf *sb, const char *placeholder,
switch
(
placeholder
[
0
])
{
case
'H'
:
/* commit hash */
strbuf_addstr
(
sb
,
sha1_to_hex
(
commit
->
object
.
sha1
));
return
;
return
1
;
case
'h'
:
/* abbreviated commit hash */
if
(
add_again
(
sb
,
&
c
->
abbrev_commit_hash
))
return
;
return
1
;
strbuf_addstr
(
sb
,
find_unique_abbrev
(
commit
->
object
.
sha1
,
DEFAULT_ABBREV
));
c
->
abbrev_commit_hash
.
len
=
sb
->
len
-
c
->
abbrev_commit_hash
.
off
;
return
;
return
1
;
case
'T'
:
/* tree hash */
strbuf_addstr
(
sb
,
sha1_to_hex
(
commit
->
tree
->
object
.
sha1
));
return
;
return
1
;
case
't'
:
/* abbreviated tree hash */
if
(
add_again
(
sb
,
&
c
->
abbrev_tree_hash
))
return
;
return
1
;
strbuf_addstr
(
sb
,
find_unique_abbrev
(
commit
->
tree
->
object
.
sha1
,
DEFAULT_ABBREV
));
c
->
abbrev_tree_hash
.
len
=
sb
->
len
-
c
->
abbrev_tree_hash
.
off
;
return
;
return
1
;
case
'P'
:
/* parent hashes */
for
(
p
=
commit
->
parents
;
p
;
p
=
p
->
next
)
{
if
(
p
!=
commit
->
parents
)
strbuf_addch
(
sb
,
' '
);
strbuf_addstr
(
sb
,
sha1_to_hex
(
p
->
item
->
object
.
sha1
));
}
return
;
return
1
;
case
'p'
:
/* abbreviated parent hashes */
if
(
add_again
(
sb
,
&
c
->
abbrev_parent_hashes
))
return
;
return
1
;
for
(
p
=
commit
->
parents
;
p
;
p
=
p
->
next
)
{
if
(
p
!=
commit
->
parents
)
strbuf_addch
(
sb
,
' '
);
...
...
@@ -513,14 +524,14 @@ static void format_commit_item(struct strbuf *sb, const char *placeholder,
}
c
->
abbrev_parent_hashes
.
len
=
sb
->
len
-
c
->
abbrev_parent_hashes
.
off
;
return
;
return
1
;
case
'm'
:
/* left/right/bottom */
strbuf_addch
(
sb
,
(
commit
->
object
.
flags
&
BOUNDARY
)
?
'-'
:
(
commit
->
object
.
flags
&
SYMMETRIC_LEFT
)
?
'<'
:
'>'
);
return
;
return
1
;
}
/* For the rest we have to parse the commit header. */
...
...
@@ -528,66 +539,33 @@ static void format_commit_item(struct strbuf *sb, const char *placeholder,
parse_commit_header
(
c
);
switch
(
placeholder
[
0
])
{
case
's'
:
case
's'
:
/* subject */
strbuf_add
(
sb
,
msg
+
c
->
subject
.
off
,
c
->
subject
.
len
);
return
;
case
'a'
:
format_person_part
(
sb
,
placeholder
[
1
],
return
1
;
case
'a'
:
/* author ... */
return
format_person_part
(
sb
,
placeholder
[
1
],
msg
+
c
->
author
.
off
,
c
->
author
.
len
);
return
;
case
'c'
:
format_person_part
(
sb
,
placeholder
[
1
],
case
'c'
:
/* committer ... */
return
format_person_part
(
sb
,
placeholder
[
1
],
msg
+
c
->
committer
.
off
,
c
->
committer
.
len
);
return
;
case
'e'
:
case
'e'
:
/* encoding */
strbuf_add
(
sb
,
msg
+
c
->
encoding
.
off
,
c
->
encoding
.
len
);
return
;
case
'b'
:
return
1
;
case
'b'
:
/* body */
strbuf_addstr
(
sb
,
msg
+
c
->
body_off
);
return
;
return
1
;
}
return
0
;
/* unknown placeholder */
}
void
format_commit_message
(
const
struct
commit
*
commit
,
const
void
*
format
,
struct
strbuf
*
sb
)
{
const
char
*
placeholders
[]
=
{
"H"
,
/* commit hash */
"h"
,
/* abbreviated commit hash */
"T"
,
/* tree hash */
"t"
,
/* abbreviated tree hash */
"P"
,
/* parent hashes */
"p"
,
/* abbreviated parent hashes */
"an"
,
/* author name */
"ae"
,
/* author email */
"ad"
,
/* author date */
"aD"
,
/* author date, RFC2822 style */
"ar"
,
/* author date, relative */
"at"
,
/* author date, UNIX timestamp */
"ai"
,
/* author date, ISO 8601 */
"cn"
,
/* committer name */
"ce"
,
/* committer email */
"cd"
,
/* committer date */
"cD"
,
/* committer date, RFC2822 style */
"cr"
,
/* committer date, relative */
"ct"
,
/* committer date, UNIX timestamp */
"ci"
,
/* committer date, ISO 8601 */
"e"
,
/* encoding */
"s"
,
/* subject */
"b"
,
/* body */
"Cred"
,
/* red */
"Cgreen"
,
/* green */
"Cblue"
,
/* blue */
"Creset"
,
/* reset color */
"n"
,
/* newline */
"m"
,
/* left/right/bottom */
NULL
};
struct
format_commit_context
context
;
memset
(
&
context
,
0
,
sizeof
(
context
));
context
.
commit
=
commit
;
strbuf_expand
(
sb
,
format
,
placeholders
,
format_commit_item
,
&
context
);
strbuf_expand
(
sb
,
format
,
format_commit_item
,
&
context
);
}
static
void
pp_header
(
enum
cmit_fmt
fmt
,
...
...
strbuf.c
浏览文件 @
356eff53
...
...
@@ -146,11 +146,12 @@ void strbuf_addf(struct strbuf *sb, const char *fmt, ...)
strbuf_setlen
(
sb
,
sb
->
len
+
len
);
}
void
strbuf_expand
(
struct
strbuf
*
sb
,
const
char
*
format
,
const
char
**
placeholders
,
expand_fn_t
fn
,
void
*
context
)
void
strbuf_expand
(
struct
strbuf
*
sb
,
const
char
*
format
,
expand_fn_t
fn
,
void
*
context
)
{
for
(;;)
{
const
char
*
percent
,
**
p
;
const
char
*
percent
;
size_t
consumed
;
percent
=
strchrnul
(
format
,
'%'
);
strbuf_add
(
sb
,
format
,
percent
-
format
);
...
...
@@ -158,14 +159,10 @@ void strbuf_expand(struct strbuf *sb, const char *format,
break
;
format
=
percent
+
1
;
for
(
p
=
placeholders
;
*
p
;
p
++
)
{
if
(
!
prefixcmp
(
format
,
*
p
))
break
;
}
if
(
*
p
)
{
fn
(
sb
,
*
p
,
context
);
format
+=
strlen
(
*
p
);
}
else
consumed
=
fn
(
sb
,
format
,
context
);
if
(
consumed
)
format
+=
consumed
;
else
strbuf_addch
(
sb
,
'%'
);
}
}
...
...
strbuf.h
浏览文件 @
356eff53
...
...
@@ -103,8 +103,8 @@ static inline void strbuf_addbuf(struct strbuf *sb, struct strbuf *sb2) {
}
extern
void
strbuf_adddup
(
struct
strbuf
*
sb
,
size_t
pos
,
size_t
len
);
typedef
void
(
*
expand_fn_t
)
(
struct
strbuf
*
sb
,
const
char
*
placeholder
,
void
*
context
);
extern
void
strbuf_expand
(
struct
strbuf
*
sb
,
const
char
*
format
,
const
char
**
placeholders
,
expand_fn_t
fn
,
void
*
context
);
typedef
size_t
(
*
expand_fn_t
)
(
struct
strbuf
*
sb
,
const
char
*
placeholder
,
void
*
context
);
extern
void
strbuf_expand
(
struct
strbuf
*
sb
,
const
char
*
format
,
expand_fn_t
fn
,
void
*
context
);
__attribute__
((
format
(
printf
,
2
,
3
)))
extern
void
strbuf_addf
(
struct
strbuf
*
sb
,
const
char
*
fmt
,
...);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录