Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
git
提交
86193807
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,发现更多精彩内容 >>
提交
86193807
编写于
10月 09, 2008
作者:
S
Shawn O. Pearce
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'rz/grepz'
* rz/grepz: git grep: Add "-z/--null" option as in GNU's grep.
上级
e4fff5ce
83caecca
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
26 addition
and
3 deletion
+26
-3
Documentation/git-grep.txt
Documentation/git-grep.txt
+6
-0
builtin-grep.c
builtin-grep.c
+8
-0
grep.c
grep.c
+11
-3
grep.h
grep.h
+1
-0
未找到文件。
Documentation/git-grep.txt
浏览文件 @
86193807
...
@@ -15,6 +15,7 @@ SYNOPSIS
...
@@ -15,6 +15,7 @@ SYNOPSIS
[-E | --extended-regexp] [-G | --basic-regexp]
[-E | --extended-regexp] [-G | --basic-regexp]
[-F | --fixed-strings] [-n]
[-F | --fixed-strings] [-n]
[-l | --files-with-matches] [-L | --files-without-match]
[-l | --files-with-matches] [-L | --files-without-match]
[-z | --null]
[-c | --count] [--all-match]
[-c | --count] [--all-match]
[-A <post-context>] [-B <pre-context>] [-C <context>]
[-A <post-context>] [-B <pre-context>] [-C <context>]
[-f <file>] [-e] <pattern>
[-f <file>] [-e] <pattern>
...
@@ -94,6 +95,11 @@ OPTIONS
...
@@ -94,6 +95,11 @@ OPTIONS
For better compatibility with 'git-diff', --name-only is a
For better compatibility with 'git-diff', --name-only is a
synonym for --files-with-matches.
synonym for --files-with-matches.
-z::
--null::
Output \0 instead of the character that normally follows a
file name.
-c::
-c::
--count::
--count::
Instead of showing every matched line, show the number of
Instead of showing every matched line, show the number of
...
...
builtin-grep.c
浏览文件 @
86193807
...
@@ -295,6 +295,9 @@ static int external_grep(struct grep_opt *opt, const char **paths, int cached)
...
@@ -295,6 +295,9 @@ static int external_grep(struct grep_opt *opt, const char **paths, int cached)
push_arg
(
"-l"
);
push_arg
(
"-l"
);
if
(
opt
->
unmatch_name_only
)
if
(
opt
->
unmatch_name_only
)
push_arg
(
"-L"
);
push_arg
(
"-L"
);
if
(
opt
->
null_following_name
)
/* in GNU grep git's "-z" translates to "-Z" */
push_arg
(
"-Z"
);
if
(
opt
->
count
)
if
(
opt
->
count
)
push_arg
(
"-c"
);
push_arg
(
"-c"
);
if
(
opt
->
post_context
||
opt
->
pre_context
)
{
if
(
opt
->
post_context
||
opt
->
pre_context
)
{
...
@@ -599,6 +602,11 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
...
@@ -599,6 +602,11 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
opt
.
unmatch_name_only
=
1
;
opt
.
unmatch_name_only
=
1
;
continue
;
continue
;
}
}
if
(
!
strcmp
(
"-z"
,
arg
)
||
!
strcmp
(
"--null"
,
arg
))
{
opt
.
null_following_name
=
1
;
continue
;
}
if
(
!
strcmp
(
"-c"
,
arg
)
||
if
(
!
strcmp
(
"-c"
,
arg
)
||
!
strcmp
(
"--count"
,
arg
))
{
!
strcmp
(
"--count"
,
arg
))
{
opt
.
count
=
1
;
opt
.
count
=
1
;
...
...
grep.c
浏览文件 @
86193807
...
@@ -239,6 +239,8 @@ static int word_char(char ch)
...
@@ -239,6 +239,8 @@ static int word_char(char ch)
static
void
show_line
(
struct
grep_opt
*
opt
,
const
char
*
bol
,
const
char
*
eol
,
static
void
show_line
(
struct
grep_opt
*
opt
,
const
char
*
bol
,
const
char
*
eol
,
const
char
*
name
,
unsigned
lno
,
char
sign
)
const
char
*
name
,
unsigned
lno
,
char
sign
)
{
{
if
(
opt
->
null_following_name
)
sign
=
'\0'
;
if
(
opt
->
pathname
)
if
(
opt
->
pathname
)
printf
(
"%s%c"
,
name
,
sign
);
printf
(
"%s%c"
,
name
,
sign
);
if
(
opt
->
linenum
)
if
(
opt
->
linenum
)
...
@@ -246,6 +248,11 @@ static void show_line(struct grep_opt *opt, const char *bol, const char *eol,
...
@@ -246,6 +248,11 @@ static void show_line(struct grep_opt *opt, const char *bol, const char *eol,
printf
(
"%.*s
\n
"
,
(
int
)(
eol
-
bol
),
bol
);
printf
(
"%.*s
\n
"
,
(
int
)(
eol
-
bol
),
bol
);
}
}
static
void
show_name
(
struct
grep_opt
*
opt
,
const
char
*
name
)
{
printf
(
"%s%c"
,
name
,
opt
->
null_following_name
?
'\0'
:
'\n'
);
}
static
int
fixmatch
(
const
char
*
pattern
,
char
*
line
,
regmatch_t
*
match
)
static
int
fixmatch
(
const
char
*
pattern
,
char
*
line
,
regmatch_t
*
match
)
{
{
char
*
hit
=
strstr
(
line
,
pattern
);
char
*
hit
=
strstr
(
line
,
pattern
);
...
@@ -489,7 +496,7 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,
...
@@ -489,7 +496,7 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,
return
1
;
return
1
;
}
}
if
(
opt
->
name_only
)
{
if
(
opt
->
name_only
)
{
printf
(
"%s
\n
"
,
name
);
show_name
(
opt
,
name
);
return
1
;
return
1
;
}
}
/* Hit at this line. If we haven't shown the
/* Hit at this line. If we haven't shown the
...
@@ -555,7 +562,7 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,
...
@@ -555,7 +562,7 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,
return
0
;
return
0
;
if
(
opt
->
unmatch_name_only
)
{
if
(
opt
->
unmatch_name_only
)
{
/* We did not see any hit, so we want to show this */
/* We did not see any hit, so we want to show this */
printf
(
"%s
\n
"
,
name
);
show_name
(
opt
,
name
);
return
1
;
return
1
;
}
}
...
@@ -565,7 +572,8 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,
...
@@ -565,7 +572,8 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,
* make it another option? For now suppress them.
* make it another option? For now suppress them.
*/
*/
if
(
opt
->
count
&&
count
)
if
(
opt
->
count
&&
count
)
printf
(
"%s:%u
\n
"
,
name
,
count
);
printf
(
"%s%c%u
\n
"
,
name
,
opt
->
null_following_name
?
'\0'
:
':'
,
count
);
return
!!
last_hit
;
return
!!
last_hit
;
}
}
...
...
grep.h
浏览文件 @
86193807
...
@@ -74,6 +74,7 @@ struct grep_opt {
...
@@ -74,6 +74,7 @@ struct grep_opt {
unsigned
extended
:
1
;
unsigned
extended
:
1
;
unsigned
relative
:
1
;
unsigned
relative
:
1
;
unsigned
pathname
:
1
;
unsigned
pathname
:
1
;
unsigned
null_following_name
:
1
;
int
regflags
;
int
regflags
;
unsigned
pre_context
;
unsigned
pre_context
;
unsigned
post_context
;
unsigned
post_context
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录