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
25c47aae
Commit
25c47aae
authored
Sep 20, 2013
by
Ben Straub
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Detect boundaries, support limiting commit range
parent
9d42fcbe
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
41 additions
and
16 deletions
+41
-16
include/git2/blame.h
+4
-0
src/blame.c
+1
-0
src/blame_git.c
+12
-3
src/blame_git.h
+4
-0
tests-clar/blame/blame_helpers.c
+7
-1
tests-clar/blame/blame_helpers.h
+1
-0
tests-clar/blame/buffer.c
+12
-12
tests-clar/blame/simple.c
+0
-0
No files found.
include/git2/blame.h
View file @
25c47aae
...
...
@@ -93,6 +93,8 @@ typedef struct git_blame_options {
* - `orig_start_line_number` is the 1-based line number where this hunk begins
* in the file named by `orig_path` in the commit specified by
* `orig_commit_id`.
* - `boundary` is 1 iff the hunk has been tracked to a boundary commit (the
* root, or the commit specified in git_blame_options.oldest_commit)
*/
typedef
struct
git_blame_hunk
{
uint16_t
lines_in_hunk
;
...
...
@@ -103,6 +105,8 @@ typedef struct git_blame_hunk {
git_oid
orig_commit_id
;
const
char
*
orig_path
;
uint16_t
orig_start_line_number
;
char
boundary
;
}
git_blame_hunk
;
...
...
src/blame.c
View file @
25c47aae
...
...
@@ -247,6 +247,7 @@ static git_blame_hunk* hunk_from_entry(struct blame_entry *e)
git_blame_hunk
*
h
=
new_hunk
(
e
->
lno
+
1
,
e
->
num_lines
,
e
->
s_lno
+
1
,
e
->
suspect
->
path
);
git_oid_cpy
(
&
h
->
final_commit_id
,
git_commit_id
(
e
->
suspect
->
commit
));
h
->
boundary
=
e
->
is_boundary
?
1
:
0
;
return
h
;
}
...
...
src/blame_git.c
View file @
25c47aae
...
...
@@ -456,8 +456,12 @@ static void pass_blame(struct scoreboard *sb, struct origin *origin, uint32_t op
GIT_UNUSED
(
opt
);
num_sg
=
git_commit_parentcount
(
commit
);
if
(
!
num_sg
)
if
(
!
git_oid_cmp
(
git_commit_id
(
commit
),
&
sb
->
blame
->
options
.
oldest_commit
))
num_sg
=
0
;
if
(
!
num_sg
)
{
git_oid_cpy
(
&
sb
->
blame
->
options
.
oldest_commit
,
git_commit_id
(
commit
));
goto
finish
;
}
else
if
(
num_sg
<
(
int
)
ARRAY_SIZE
(
sg_buf
))
memset
(
sg_buf
,
0
,
sizeof
(
sg_buf
));
else
...
...
@@ -558,9 +562,14 @@ void assign_blame(struct scoreboard *sb, uint32_t opt)
pass_blame
(
sb
,
suspect
,
opt
);
/* Take responsibility for the remaining entries */
for
(
ent
=
sb
->
ent
;
ent
;
ent
=
ent
->
next
)
if
(
same_suspect
(
ent
->
suspect
,
suspect
))
for
(
ent
=
sb
->
ent
;
ent
;
ent
=
ent
->
next
)
{
if
(
same_suspect
(
ent
->
suspect
,
suspect
))
{
ent
->
guilty
=
1
;
ent
->
is_boundary
=
!
git_oid_cmp
(
git_commit_id
(
suspect
->
commit
),
&
sb
->
blame
->
options
.
oldest_commit
);
}
}
origin_decref
(
suspect
);
}
}
...
...
src/blame_git.h
View file @
25c47aae
...
...
@@ -55,6 +55,10 @@ struct blame_entry {
* scanning the lines over and over.
*/
unsigned
score
;
/* Whether this entry has been tracked to a boundary commit.
*/
bool
is_boundary
;
};
/*
...
...
tests-clar/blame/blame_helpers.c
View file @
25c47aae
...
...
@@ -15,7 +15,7 @@ void hunk_message(size_t idx, const git_blame_hunk *hunk, const char *fmt, ...)
}
void
check_blame_hunk_index
(
git_repository
*
repo
,
git_blame
*
blame
,
int
idx
,
int
start_line
,
int
len
,
const
char
*
commit_id
,
const
char
*
orig_path
)
int
start_line
,
int
len
,
c
har
boundary
,
c
onst
char
*
commit_id
,
const
char
*
orig_path
)
{
char
expected
[
41
]
=
{
0
},
actual
[
41
]
=
{
0
};
const
git_blame_hunk
*
hunk
=
git_blame_get_hunk_byindex
(
blame
,
idx
);
...
...
@@ -53,6 +53,12 @@ void check_blame_hunk_index(git_repository *repo, git_blame *blame, int idx,
hunk
->
orig_path
,
orig_path
);
}
cl_assert_equal_s
(
hunk
->
orig_path
,
orig_path
);
if
(
hunk
->
boundary
!=
boundary
)
{
hunk_message
(
idx
,
hunk
,
"doesn't match boundary flag (got %d, expected %d)
\n
"
,
hunk
->
boundary
,
boundary
);
}
cl_assert_equal_i
(
boundary
,
hunk
->
boundary
);
}
tests-clar/blame/blame_helpers.h
View file @
25c47aae
...
...
@@ -9,6 +9,7 @@ void check_blame_hunk_index(
int
idx
,
int
start_line
,
int
len
,
char
boundary
,
const
char
*
commit_id
,
const
char
*
orig_path
);
...
...
tests-clar/blame/buffer.c
View file @
25c47aae
...
...
@@ -38,7 +38,7 @@ CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
cl_git_pass
(
git_blame_buffer
(
&
g_bufferblame
,
g_fileblame
,
buffer
,
strlen
(
buffer
)));
cl_assert_equal_i
(
5
,
git_blame_get_hunk_count
(
g_bufferblame
));
check_blame_hunk_index
(
g_repo
,
g_bufferblame
,
2
,
6
,
1
,
"000000"
,
"b.txt"
);
check_blame_hunk_index
(
g_repo
,
g_bufferblame
,
2
,
6
,
1
,
0
,
"000000"
,
"b.txt"
);
}
void
test_blame_buffer__deleted_line
(
void
)
...
...
@@ -59,9 +59,9 @@ CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
\n\n
"
;
cl_git_pass
(
git_blame_buffer
(
&
g_bufferblame
,
g_fileblame
,
buffer
,
strlen
(
buffer
)));
check_blame_hunk_index
(
g_repo
,
g_bufferblame
,
2
,
6
,
3
,
"63d671eb"
,
"b.txt"
);
check_blame_hunk_index
(
g_repo
,
g_bufferblame
,
3
,
9
,
1
,
"63d671eb"
,
"b.txt"
);
check_blame_hunk_index
(
g_repo
,
g_bufferblame
,
4
,
10
,
5
,
"aa06ecca"
,
"b.txt"
);
check_blame_hunk_index
(
g_repo
,
g_bufferblame
,
2
,
6
,
3
,
0
,
"63d671eb"
,
"b.txt"
);
check_blame_hunk_index
(
g_repo
,
g_bufferblame
,
3
,
9
,
1
,
0
,
"63d671eb"
,
"b.txt"
);
check_blame_hunk_index
(
g_repo
,
g_bufferblame
,
4
,
10
,
5
,
0
,
"aa06ecca"
,
"b.txt"
);
}
void
test_blame_buffer__add_splits_hunk
(
void
)
...
...
@@ -84,9 +84,9 @@ CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
\n\n
"
;
cl_git_pass
(
git_blame_buffer
(
&
g_bufferblame
,
g_fileblame
,
buffer
,
strlen
(
buffer
)));
check_blame_hunk_index
(
g_repo
,
g_bufferblame
,
2
,
6
,
2
,
"63d671eb"
,
"b.txt"
);
check_blame_hunk_index
(
g_repo
,
g_bufferblame
,
3
,
8
,
1
,
"00000000"
,
"b.txt"
);
check_blame_hunk_index
(
g_repo
,
g_bufferblame
,
4
,
9
,
3
,
"63d671eb"
,
"b.txt"
);
check_blame_hunk_index
(
g_repo
,
g_bufferblame
,
2
,
6
,
2
,
0
,
"63d671eb"
,
"b.txt"
);
check_blame_hunk_index
(
g_repo
,
g_bufferblame
,
3
,
8
,
1
,
0
,
"00000000"
,
"b.txt"
);
check_blame_hunk_index
(
g_repo
,
g_bufferblame
,
4
,
9
,
3
,
0
,
"63d671eb"
,
"b.txt"
);
}
void
test_blame_buffer__delete_crosses_hunk_boundary
(
void
)
...
...
@@ -101,8 +101,8 @@ BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
\n\n
"
;
cl_git_pass
(
git_blame_buffer
(
&
g_bufferblame
,
g_fileblame
,
buffer
,
strlen
(
buffer
)));
check_blame_hunk_index
(
g_repo
,
g_bufferblame
,
2
,
6
,
1
,
"63d671eb"
,
"b.txt"
);
check_blame_hunk_index
(
g_repo
,
g_bufferblame
,
3
,
7
,
2
,
"aa06ecca"
,
"b.txt"
);
check_blame_hunk_index
(
g_repo
,
g_bufferblame
,
2
,
6
,
1
,
0
,
"63d671eb"
,
"b.txt"
);
check_blame_hunk_index
(
g_repo
,
g_bufferblame
,
3
,
7
,
2
,
0
,
"aa06ecca"
,
"b.txt"
);
}
void
test_blame_buffer__replace_line
(
void
)
...
...
@@ -124,7 +124,7 @@ CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
\n\n
"
;
cl_git_pass
(
git_blame_buffer
(
&
g_bufferblame
,
g_fileblame
,
buffer
,
strlen
(
buffer
)));
check_blame_hunk_index
(
g_repo
,
g_bufferblame
,
2
,
6
,
1
,
"63d671eb"
,
"b.txt"
);
check_blame_hunk_index
(
g_repo
,
g_bufferblame
,
3
,
7
,
1
,
"00000000"
,
"b.txt"
);
check_blame_hunk_index
(
g_repo
,
g_bufferblame
,
4
,
8
,
3
,
"63d671eb"
,
"b.txt"
);
check_blame_hunk_index
(
g_repo
,
g_bufferblame
,
2
,
6
,
1
,
0
,
"63d671eb"
,
"b.txt"
);
check_blame_hunk_index
(
g_repo
,
g_bufferblame
,
3
,
7
,
1
,
0
,
"00000000"
,
"b.txt"
);
check_blame_hunk_index
(
g_repo
,
g_bufferblame
,
4
,
8
,
3
,
0
,
"63d671eb"
,
"b.txt"
);
}
tests-clar/blame/simple.c
View file @
25c47aae
This diff is collapsed.
Click to expand it.
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