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
bff53e54
Commit
bff53e54
authored
Nov 27, 2012
by
Scott J. Goldman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add initial implementation of ahead-behind count
parent
69302126
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
92 additions
and
0 deletions
+92
-0
include/git2/merge.h
+11
-0
src/merge.c
+81
-0
No files found.
include/git2/merge.h
View file @
bff53e54
...
...
@@ -50,6 +50,17 @@ GIT_EXTERN(int) git_merge_base_many(
const
git_oid
input_array
[],
size_t
length
);
/**
* Count the number of unique commits between two commit objects
*
* @param ahead number of commits, starting at `one`, unique from commits in `two`
* @param behind number of commits, starting at `two`, unique from commits in `one`
* @param repo the repository where the commits exist
* @param one one of the commits
* @param two the other commit
*/
GIT_EXTERN
(
int
)
git_count_ahead_behind
(
int
*
ahead
,
int
*
behind
,
git_repository
*
repo
,
git_oid
*
one
,
git_oid
*
two
);
/** @} */
GIT_END_DECL
#endif
src/merge.c
View file @
bff53e54
...
...
@@ -242,3 +242,84 @@ int git_merge__bases_many(git_commit_list **out, git_revwalk *walk, git_commit_l
return
0
;
}
static
int
count_ahead_behind
(
git_commit_list_node
*
one
,
git_commit_list_node
*
two
,
int
*
ahead
,
int
*
behind
)
{
git_commit_list_node
*
commit
;
git_pqueue
pq
;
int
i
;
*
ahead
=
0
;
*
behind
=
0
;
if
(
git_pqueue_init
(
&
pq
,
2
,
git_commit_list_time_cmp
)
<
0
)
return
-
1
;
if
(
git_pqueue_insert
(
&
pq
,
one
)
<
0
)
return
-
1
;
if
(
git_pqueue_insert
(
&
pq
,
two
)
<
0
)
return
-
1
;
while
((
commit
=
git_pqueue_pop
(
&
pq
))
!=
NULL
)
{
if
(
commit
->
flags
&
RESULT
||
(
commit
->
flags
&
(
PARENT1
|
PARENT2
))
==
(
PARENT1
|
PARENT2
))
continue
;
else
if
(
commit
->
flags
&
PARENT1
)
(
*
behind
)
++
;
else
if
(
commit
->
flags
&
PARENT2
)
(
*
ahead
)
++
;
for
(
i
=
0
;
i
<
commit
->
out_degree
;
i
++
)
{
git_commit_list_node
*
p
=
commit
->
parents
[
i
];
if
(
git_pqueue_insert
(
&
pq
,
p
)
<
0
)
return
-
1
;
}
commit
->
flags
|=
RESULT
;
}
return
0
;
}
int
git_count_ahead_behind
(
int
*
ahead
,
int
*
behind
,
git_repository
*
repo
,
git_oid
*
one
,
git_oid
*
two
)
{
git_revwalk
*
walk
;
git_vector
list
;
struct
git_commit_list
*
result
=
NULL
;
git_commit_list_node
*
commit1
,
*
commit2
;
void
*
contents
[
1
];
if
(
git_revwalk_new
(
&
walk
,
repo
)
<
0
)
return
-
1
;
commit2
=
commit_lookup
(
walk
,
two
);
if
(
commit2
==
NULL
)
goto
on_error
;
/* This is just one value, so we can do it on the stack */
memset
(
&
list
,
0x0
,
sizeof
(
git_vector
));
contents
[
0
]
=
commit2
;
list
.
length
=
1
;
list
.
contents
=
contents
;
commit1
=
commit_lookup
(
walk
,
one
);
if
(
commit1
==
NULL
)
goto
on_error
;
if
(
git_merge__bases_many
(
&
result
,
walk
,
commit1
,
&
list
)
<
0
)
goto
on_error
;
if
(
count_ahead_behind
(
commit1
,
commit2
,
ahead
,
behind
)
<
0
)
goto
on_error
;
if
(
!
result
)
{
git_revwalk_free
(
walk
);
return
GIT_ENOTFOUND
;
}
git_commit_list_free
(
&
result
);
git_revwalk_free
(
walk
);
return
0
;
on_error:
git_revwalk_free
(
walk
);
return
-
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