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
87727409
Commit
87727409
authored
Apr 09, 2023
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
blame: support sha256
parent
26b9c056
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
16 deletions
+23
-16
src/libgit2/blame.c
+23
-16
No files found.
src/libgit2/blame.c
View file @
87727409
...
@@ -60,10 +60,11 @@ static bool hunk_starts_at_or_after_line(git_blame_hunk *hunk, size_t line)
...
@@ -60,10 +60,11 @@ static bool hunk_starts_at_or_after_line(git_blame_hunk *hunk, size_t line)
}
}
static
git_blame_hunk
*
new_hunk
(
static
git_blame_hunk
*
new_hunk
(
size_t
start
,
size_t
start
,
size_t
lines
,
size_t
lines
,
size_t
orig_start
,
size_t
orig_start
,
const
char
*
path
)
const
char
*
path
,
git_blame
*
blame
)
{
{
git_blame_hunk
*
hunk
=
git__calloc
(
1
,
sizeof
(
git_blame_hunk
));
git_blame_hunk
*
hunk
=
git__calloc
(
1
,
sizeof
(
git_blame_hunk
));
if
(
!
hunk
)
return
NULL
;
if
(
!
hunk
)
return
NULL
;
...
@@ -72,8 +73,8 @@ static git_blame_hunk *new_hunk(
...
@@ -72,8 +73,8 @@ static git_blame_hunk *new_hunk(
hunk
->
final_start_line_number
=
start
;
hunk
->
final_start_line_number
=
start
;
hunk
->
orig_start_line_number
=
orig_start
;
hunk
->
orig_start_line_number
=
orig_start
;
hunk
->
orig_path
=
path
?
git__strdup
(
path
)
:
NULL
;
hunk
->
orig_path
=
path
?
git__strdup
(
path
)
:
NULL
;
git_oid_clear
(
&
hunk
->
orig_commit_id
,
GIT_OID_SHA1
);
git_oid_clear
(
&
hunk
->
orig_commit_id
,
blame
->
repository
->
oid_type
);
git_oid_clear
(
&
hunk
->
final_commit_id
,
GIT_OID_SHA1
);
git_oid_clear
(
&
hunk
->
final_commit_id
,
blame
->
repository
->
oid_type
);
return
hunk
;
return
hunk
;
}
}
...
@@ -86,13 +87,14 @@ static void free_hunk(git_blame_hunk *hunk)
...
@@ -86,13 +87,14 @@ static void free_hunk(git_blame_hunk *hunk)
git__free
(
hunk
);
git__free
(
hunk
);
}
}
static
git_blame_hunk
*
dup_hunk
(
git_blame_hunk
*
hunk
)
static
git_blame_hunk
*
dup_hunk
(
git_blame_hunk
*
hunk
,
git_blame
*
blame
)
{
{
git_blame_hunk
*
newhunk
=
new_hunk
(
git_blame_hunk
*
newhunk
=
new_hunk
(
hunk
->
final_start_line_number
,
hunk
->
final_start_line_number
,
hunk
->
lines_in_hunk
,
hunk
->
lines_in_hunk
,
hunk
->
orig_start_line_number
,
hunk
->
orig_start_line_number
,
hunk
->
orig_path
);
hunk
->
orig_path
,
blame
);
if
(
!
newhunk
)
if
(
!
newhunk
)
return
NULL
;
return
NULL
;
...
@@ -237,7 +239,8 @@ static git_blame_hunk *split_hunk_in_vector(
...
@@ -237,7 +239,8 @@ static git_blame_hunk *split_hunk_in_vector(
git_vector
*
vec
,
git_vector
*
vec
,
git_blame_hunk
*
hunk
,
git_blame_hunk
*
hunk
,
size_t
rel_line
,
size_t
rel_line
,
bool
return_new
)
bool
return_new
,
git_blame
*
blame
)
{
{
size_t
new_line_count
;
size_t
new_line_count
;
git_blame_hunk
*
nh
;
git_blame_hunk
*
nh
;
...
@@ -250,8 +253,9 @@ static git_blame_hunk *split_hunk_in_vector(
...
@@ -250,8 +253,9 @@ static git_blame_hunk *split_hunk_in_vector(
}
}
new_line_count
=
hunk
->
lines_in_hunk
-
rel_line
;
new_line_count
=
hunk
->
lines_in_hunk
-
rel_line
;
nh
=
new_hunk
(
hunk
->
final_start_line_number
+
rel_line
,
new_line_count
,
nh
=
new_hunk
(
hunk
->
final_start_line_number
+
rel_line
,
hunk
->
orig_start_line_number
+
rel_line
,
hunk
->
orig_path
);
new_line_count
,
hunk
->
orig_start_line_number
+
rel_line
,
hunk
->
orig_path
,
blame
);
if
(
!
nh
)
if
(
!
nh
)
return
NULL
;
return
NULL
;
...
@@ -304,7 +308,8 @@ static int index_blob_lines(git_blame *blame)
...
@@ -304,7 +308,8 @@ static int index_blob_lines(git_blame *blame)
static
git_blame_hunk
*
hunk_from_entry
(
git_blame__entry
*
e
,
git_blame
*
blame
)
static
git_blame_hunk
*
hunk_from_entry
(
git_blame__entry
*
e
,
git_blame
*
blame
)
{
{
git_blame_hunk
*
h
=
new_hunk
(
git_blame_hunk
*
h
=
new_hunk
(
e
->
lno
+
1
,
e
->
num_lines
,
e
->
s_lno
+
1
,
e
->
suspect
->
path
);
e
->
lno
+
1
,
e
->
num_lines
,
e
->
s_lno
+
1
,
e
->
suspect
->
path
,
blame
);
if
(
!
h
)
if
(
!
h
)
return
NULL
;
return
NULL
;
...
@@ -445,14 +450,16 @@ static int buffer_hunk_cb(
...
@@ -445,14 +450,16 @@ static int buffer_hunk_cb(
blame
->
current_hunk
=
(
git_blame_hunk
*
)
git_blame_get_hunk_byline
(
blame
,
wedge_line
);
blame
->
current_hunk
=
(
git_blame_hunk
*
)
git_blame_get_hunk_byline
(
blame
,
wedge_line
);
if
(
!
blame
->
current_hunk
)
{
if
(
!
blame
->
current_hunk
)
{
/* Line added at the end of the file */
/* Line added at the end of the file */
blame
->
current_hunk
=
new_hunk
(
wedge_line
,
0
,
wedge_line
,
blame
->
path
);
blame
->
current_hunk
=
new_hunk
(
wedge_line
,
0
,
wedge_line
,
blame
->
path
,
blame
);
GIT_ERROR_CHECK_ALLOC
(
blame
->
current_hunk
);
GIT_ERROR_CHECK_ALLOC
(
blame
->
current_hunk
);
git_vector_insert
(
&
blame
->
hunks
,
blame
->
current_hunk
);
git_vector_insert
(
&
blame
->
hunks
,
blame
->
current_hunk
);
}
else
if
(
!
hunk_starts_at_or_after_line
(
blame
->
current_hunk
,
wedge_line
)){
}
else
if
(
!
hunk_starts_at_or_after_line
(
blame
->
current_hunk
,
wedge_line
)){
/* If this hunk doesn't start between existing hunks, split a hunk up so it does */
/* If this hunk doesn't start between existing hunks, split a hunk up so it does */
blame
->
current_hunk
=
split_hunk_in_vector
(
&
blame
->
hunks
,
blame
->
current_hunk
,
blame
->
current_hunk
=
split_hunk_in_vector
(
&
blame
->
hunks
,
blame
->
current_hunk
,
wedge_line
-
blame
->
current_hunk
->
orig_start_line_number
,
true
);
wedge_line
-
blame
->
current_hunk
->
orig_start_line_number
,
true
,
blame
);
GIT_ERROR_CHECK_ALLOC
(
blame
->
current_hunk
);
GIT_ERROR_CHECK_ALLOC
(
blame
->
current_hunk
);
}
}
...
@@ -481,7 +488,7 @@ static int buffer_line_cb(
...
@@ -481,7 +488,7 @@ static int buffer_line_cb(
}
else
{
}
else
{
/* Create a new buffer-blame hunk with this line */
/* Create a new buffer-blame hunk with this line */
shift_hunks_by
(
&
blame
->
hunks
,
blame
->
current_diff_line
,
1
);
shift_hunks_by
(
&
blame
->
hunks
,
blame
->
current_diff_line
,
1
);
blame
->
current_hunk
=
new_hunk
(
blame
->
current_diff_line
,
1
,
0
,
blame
->
path
);
blame
->
current_hunk
=
new_hunk
(
blame
->
current_diff_line
,
1
,
0
,
blame
->
path
,
blame
);
GIT_ERROR_CHECK_ALLOC
(
blame
->
current_hunk
);
GIT_ERROR_CHECK_ALLOC
(
blame
->
current_hunk
);
git_vector_insert_sorted
(
&
blame
->
hunks
,
blame
->
current_hunk
,
NULL
);
git_vector_insert_sorted
(
&
blame
->
hunks
,
blame
->
current_hunk
,
NULL
);
...
@@ -529,7 +536,7 @@ int git_blame_buffer(
...
@@ -529,7 +536,7 @@ int git_blame_buffer(
/* Duplicate all of the hunk structures in the reference blame */
/* Duplicate all of the hunk structures in the reference blame */
git_vector_foreach
(
&
reference
->
hunks
,
i
,
hunk
)
{
git_vector_foreach
(
&
reference
->
hunks
,
i
,
hunk
)
{
git_blame_hunk
*
h
=
dup_hunk
(
hunk
);
git_blame_hunk
*
h
=
dup_hunk
(
hunk
,
blame
);
GIT_ERROR_CHECK_ALLOC
(
h
);
GIT_ERROR_CHECK_ALLOC
(
h
);
git_vector_insert
(
&
blame
->
hunks
,
h
);
git_vector_insert
(
&
blame
->
hunks
,
h
);
...
...
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