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
2e1e0f10
Commit
2e1e0f10
authored
Nov 21, 2014
by
Vicent Marti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
blame: Do not assume blob contents are NULL-terminated
parent
1ba48b7c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
6 deletions
+8
-6
examples/blame.c
+8
-6
No files found.
examples/blame.c
View file @
2e1e0f10
...
@@ -38,6 +38,7 @@ static void parse_opts(struct opts *o, int argc, char *argv[]);
...
@@ -38,6 +38,7 @@ static void parse_opts(struct opts *o, int argc, char *argv[]);
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
int
i
,
line
,
break_on_null_hunk
;
int
i
,
line
,
break_on_null_hunk
;
size_t
rawsize
;
char
spec
[
1024
]
=
{
0
};
char
spec
[
1024
]
=
{
0
};
struct
opts
o
=
{
0
};
struct
opts
o
=
{
0
};
const
char
*
rawdata
;
const
char
*
rawdata
;
...
@@ -94,23 +95,24 @@ int main(int argc, char *argv[])
...
@@ -94,23 +95,24 @@ int main(int argc, char *argv[])
git_object_free
(
obj
);
git_object_free
(
obj
);
rawdata
=
git_blob_rawcontent
(
blob
);
rawdata
=
git_blob_rawcontent
(
blob
);
rawsize
=
git_blob_rawsize
(
blob
);
/** Produce the output. */
/** Produce the output. */
line
=
1
;
line
=
1
;
i
=
0
;
i
=
0
;
break_on_null_hunk
=
0
;
break_on_null_hunk
=
0
;
while
(
i
<
git_blob_rawsize
(
blob
)
)
{
while
(
i
<
rawsize
)
{
const
char
*
eol
=
strchr
(
rawdata
+
i
,
'\n'
);
const
char
*
eol
=
memchr
(
rawdata
+
i
,
'\n'
,
rawsize
-
i
);
char
oid
[
10
]
=
{
0
};
char
oid
[
10
]
=
{
0
};
const
git_blame_hunk
*
hunk
=
git_blame_get_hunk_byline
(
blame
,
line
);
const
git_blame_hunk
*
hunk
=
git_blame_get_hunk_byline
(
blame
,
line
);
if
(
break_on_null_hunk
&&
!
hunk
)
break
;
if
(
break_on_null_hunk
&&
!
hunk
)
break
;
if
(
hunk
)
{
if
(
hunk
)
{
char
sig
[
128
]
=
{
0
};
char
sig
[
128
]
=
{
0
};
break_on_null_hunk
=
1
;
break_on_null_hunk
=
1
;
git_oid_tostr
(
oid
,
10
,
&
hunk
->
final_commit_id
);
git_oid_tostr
(
oid
,
10
,
&
hunk
->
final_commit_id
);
snprintf
(
sig
,
30
,
"%s <%s>"
,
hunk
->
final_signature
->
name
,
hunk
->
final_signature
->
email
);
snprintf
(
sig
,
30
,
"%s <%s>"
,
hunk
->
final_signature
->
name
,
hunk
->
final_signature
->
email
);
...
@@ -118,8 +120,8 @@ int main(int argc, char *argv[])
...
@@ -118,8 +120,8 @@ int main(int argc, char *argv[])
oid
,
oid
,
sig
,
sig
,
line
,
line
,
(
int
)(
eol
-
rawdata
-
i
),
(
int
)(
eol
-
rawdata
-
i
),
rawdata
+
i
);
rawdata
+
i
);
}
}
i
=
(
int
)(
eol
-
rawdata
+
1
);
i
=
(
int
)(
eol
-
rawdata
+
1
);
...
...
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