Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
ab87cb18
Commit
ab87cb18
authored
Feb 09, 2016
by
Carlos Martín Nieto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3602 from libgit2/cmn/header-field-2
commit: also match the first header field when searching
parents
e0bbe781
f55eca16
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
17 deletions
+26
-17
src/commit.c
+22
-17
tests/commit/parse.c
+4
-0
No files found.
src/commit.c
View file @
ab87cb18
...
@@ -564,41 +564,45 @@ int git_commit_nth_gen_ancestor(
...
@@ -564,41 +564,45 @@ int git_commit_nth_gen_ancestor(
int
git_commit_header_field
(
git_buf
*
out
,
const
git_commit
*
commit
,
const
char
*
field
)
int
git_commit_header_field
(
git_buf
*
out
,
const
git_commit
*
commit
,
const
char
*
field
)
{
{
const
char
*
buf
=
commit
->
raw_header
;
const
char
*
eol
,
*
buf
=
commit
->
raw_header
;
const
char
*
h
,
*
eol
;
git_buf_sanitize
(
out
);
git_buf_sanitize
(
out
);
while
((
h
=
strchr
(
buf
,
'\n'
))
&&
h
[
1
]
!=
'\0'
&&
h
[
1
]
!=
'\n'
)
{
h
++
;
while
((
eol
=
strchr
(
buf
,
'\n'
))
&&
eol
[
1
]
!=
'\0'
)
{
if
(
git__prefixcmp
(
h
,
field
))
{
/* We can skip continuations here */
buf
=
h
;
if
(
buf
[
0
]
==
' '
)
{
buf
=
eol
+
1
;
continue
;
continue
;
}
}
h
+=
strlen
(
field
);
/* Skip until we find the field we're after */
eol
=
strchr
(
h
,
'\n'
);
if
(
git__prefixcmp
(
buf
,
field
))
{
if
(
h
[
0
]
!=
' '
)
{
buf
=
eol
+
1
;
buf
=
h
;
continue
;
}
buf
+=
strlen
(
field
);
/* Check that we're not matching a prefix but the field itself */
if
(
buf
[
0
]
!=
' '
)
{
buf
=
eol
+
1
;
continue
;
continue
;
}
}
if
(
!
eol
)
goto
malformed
;
h
++
;
/* skip the SP */
buf
++
;
/* skip the SP */
git_buf_put
(
out
,
h
,
eol
-
h
);
git_buf_put
(
out
,
buf
,
eol
-
buf
);
if
(
git_buf_oom
(
out
))
if
(
git_buf_oom
(
out
))
goto
oom
;
goto
oom
;
/* If the next line starts with SP, it's multi-line, we must continue */
/* If the next line starts with SP, it's multi-line, we must continue */
while
(
eol
[
1
]
==
' '
)
{
while
(
eol
[
1
]
==
' '
)
{
git_buf_putc
(
out
,
'\n'
);
git_buf_putc
(
out
,
'\n'
);
h
=
eol
+
2
;
buf
=
eol
+
2
;
eol
=
strchr
(
h
,
'\n'
);
eol
=
strchr
(
buf
,
'\n'
);
if
(
!
eol
)
if
(
!
eol
)
goto
malformed
;
goto
malformed
;
git_buf_put
(
out
,
h
,
eol
-
h
);
git_buf_put
(
out
,
buf
,
eol
-
buf
);
}
}
if
(
git_buf_oom
(
out
))
if
(
git_buf_oom
(
out
))
...
@@ -607,6 +611,7 @@ int git_commit_header_field(git_buf *out, const git_commit *commit, const char *
...
@@ -607,6 +611,7 @@ int git_commit_header_field(git_buf *out, const git_commit *commit, const char *
return
0
;
return
0
;
}
}
giterr_set
(
GITERR_OBJECT
,
"no such field '%s'"
,
field
);
return
GIT_ENOTFOUND
;
return
GIT_ENOTFOUND
;
malformed
:
malformed
:
...
...
tests/commit/parse.c
View file @
ab87cb18
...
@@ -443,6 +443,10 @@ cpxtDQQMGYFpXK/71stq\n\
...
@@ -443,6 +443,10 @@ cpxtDQQMGYFpXK/71stq\n\
cl_git_pass
(
parse_commit
(
&
commit
,
passing_commit_cases
[
4
]));
cl_git_pass
(
parse_commit
(
&
commit
,
passing_commit_cases
[
4
]));
cl_git_pass
(
git_commit_header_field
(
&
buf
,
commit
,
"tree"
));
cl_assert_equal_s
(
"6b79e22d69bf46e289df0345a14ca059dfc9bdf6"
,
buf
.
ptr
);
git_buf_clear
(
&
buf
);
cl_git_pass
(
git_commit_header_field
(
&
buf
,
commit
,
"parent"
));
cl_git_pass
(
git_commit_header_field
(
&
buf
,
commit
,
"parent"
));
cl_assert_equal_s
(
"34734e478d6cf50c27c9d69026d93974d052c454"
,
buf
.
ptr
);
cl_assert_equal_s
(
"34734e478d6cf50c27c9d69026d93974d052c454"
,
buf
.
ptr
);
git_buf_clear
(
&
buf
);
git_buf_clear
(
&
buf
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment