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
1574d388
Commit
1574d388
authored
Feb 26, 2014
by
Ben Straub
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2137 from jru/blame-first-parent
Blame first-parent history
parents
6b34a4ed
0276f0f5
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
2 deletions
+27
-2
examples/blame.c
+5
-0
include/git2/blame.h
+3
-0
src/blame_git.c
+4
-2
tests/blame/simple.c
+15
-0
No files found.
examples/blame.c
View file @
1574d388
...
...
@@ -31,6 +31,7 @@ struct opts {
int
M
;
int
start_line
;
int
end_line
;
int
F
;
};
static
void
parse_opts
(
struct
opts
*
o
,
int
argc
,
char
*
argv
[]);
...
...
@@ -52,6 +53,7 @@ int main(int argc, char *argv[])
parse_opts
(
&
o
,
argc
,
argv
);
if
(
o
.
M
)
blameopts
.
flags
|=
GIT_BLAME_TRACK_COPIES_SAME_COMMIT_MOVES
;
if
(
o
.
C
)
blameopts
.
flags
|=
GIT_BLAME_TRACK_COPIES_SAME_COMMIT_COPIES
;
if
(
o
.
F
)
blameopts
.
flags
|=
GIT_BLAME_FIRST_PARENT
;
/** Open the repository. */
check_lg2
(
git_repository_open_ext
(
&
repo
,
"."
,
0
,
NULL
),
"Couldn't open repository"
,
NULL
);
...
...
@@ -146,6 +148,7 @@ static void usage(const char *msg, const char *arg)
fprintf
(
stderr
,
" -L <n,m> process only line range n-m, counting from 1
\n
"
);
fprintf
(
stderr
,
" -M find line moves within and across files
\n
"
);
fprintf
(
stderr
,
" -C find line copies within and across files
\n
"
);
fprintf
(
stderr
,
" -F follow only the first parent commits
\n
"
);
fprintf
(
stderr
,
"
\n
"
);
exit
(
1
);
}
...
...
@@ -174,6 +177,8 @@ static void parse_opts(struct opts *o, int argc, char *argv[])
o
->
M
=
1
;
else
if
(
!
strcasecmp
(
a
,
"-C"
))
o
->
C
=
1
;
else
if
(
!
strcasecmp
(
a
,
"-F"
))
o
->
F
=
1
;
else
if
(
!
strcasecmp
(
a
,
"-L"
))
{
i
++
;
a
=
argv
[
i
];
if
(
i
>=
argc
)
fatal
(
"Not enough arguments to -L"
,
NULL
);
...
...
include/git2/blame.h
View file @
1574d388
...
...
@@ -40,6 +40,9 @@ typedef enum {
* commit (like `git blame -CCC`). Implies SAME_COMMIT_COPIES.
* NOT IMPLEMENTED. */
GIT_BLAME_TRACK_COPIES_ANY_COMMIT_COPIES
=
(
1
<<
3
),
/** Restrict the search of commits to those reachable following only the
* first parents. */
GIT_BLAME_FIRST_PARENT
=
(
1
<<
4
),
}
git_blame_flag_t
;
/**
...
...
src/blame_git.c
View file @
1574d388
...
...
@@ -485,12 +485,14 @@ static void pass_blame(git_blame *blame, git_blame__origin *origin, uint32_t opt
git_blame__origin
*
sg_buf
[
16
];
git_blame__origin
*
porigin
,
**
sg_origin
=
sg_buf
;
GIT_UNUSED
(
opt
);
num_parents
=
git_commit_parentcount
(
commit
);
if
(
!
git_oid_cmp
(
git_commit_id
(
commit
),
&
blame
->
options
.
oldest_commit
))
/* Stop at oldest specified commit */
num_parents
=
0
;
else
if
(
opt
&
GIT_BLAME_FIRST_PARENT
&&
num_parents
>
1
)
/* Limit search to the first parent */
num_parents
=
1
;
if
(
!
num_parents
)
{
git_oid_cpy
(
&
blame
->
options
.
oldest_commit
,
git_commit_id
(
commit
));
goto
finish
;
...
...
tests/blame/simple.c
View file @
1574d388
...
...
@@ -303,3 +303,18 @@ void test_blame_simple__can_restrict_to_newish_commits(void)
check_blame_hunk_index
(
g_repo
,
g_blame
,
0
,
1
,
1
,
1
,
"be3563a"
,
"branch_file.txt"
);
check_blame_hunk_index
(
g_repo
,
g_blame
,
1
,
2
,
1
,
0
,
"a65fedf"
,
"branch_file.txt"
);
}
void
test_blame_simple__can_restrict_to_first_parent_commits
(
void
)
{
git_blame_options
opts
=
GIT_BLAME_OPTIONS_INIT
;
opts
.
flags
|=
GIT_BLAME_FIRST_PARENT
;
cl_git_pass
(
git_repository_open
(
&
g_repo
,
cl_fixture
(
"blametest.git"
)));
cl_git_pass
(
git_blame_file
(
&
g_blame
,
g_repo
,
"b.txt"
,
&
opts
));
cl_assert_equal_i
(
4
,
git_blame_get_hunk_count
(
g_blame
));
check_blame_hunk_index
(
g_repo
,
g_blame
,
0
,
1
,
4
,
0
,
"da237394"
,
"b.txt"
);
check_blame_hunk_index
(
g_repo
,
g_blame
,
1
,
5
,
1
,
1
,
"b99f7ac0"
,
"b.txt"
);
check_blame_hunk_index
(
g_repo
,
g_blame
,
2
,
6
,
5
,
0
,
"63d671eb"
,
"b.txt"
);
check_blame_hunk_index
(
g_repo
,
g_blame
,
3
,
11
,
5
,
0
,
"bc7c5ac2"
,
"b.txt"
);
}
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