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
917f85a1
Commit
917f85a1
authored
Oct 09, 2014
by
Arthur Schreiber
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract shared functionality.
parent
eca07bcd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
55 deletions
+41
-55
src/merge.c
+41
-55
No files found.
src/merge.c
View file @
917f85a1
...
@@ -62,16 +62,14 @@ struct merge_diff_df_data {
...
@@ -62,16 +62,14 @@ struct merge_diff_df_data {
/* Merge base computation */
/* Merge base computation */
int
git_merge_base_many
(
git_oid
*
out
,
git_repository
*
repo
,
size_t
length
,
const
git_oid
input_array
[])
int
merge_bases_many
(
git_commit_list
**
out
,
git_revwalk
**
walk_
out
,
git_repository
*
repo
,
size_t
length
,
const
git_oid
input_array
[])
{
{
git_revwalk
*
walk
;
git_revwalk
*
walk
=
NULL
;
git_vector
list
;
git_vector
list
;
git_commit_list
*
result
=
NULL
;
git_commit_list
*
result
=
NULL
;
git_commit_list_node
*
commit
;
int
error
=
-
1
;
int
error
=
-
1
;
unsigned
int
i
;
unsigned
int
i
;
git_commit_list_node
*
commit
;
assert
(
out
&&
repo
&&
input_array
);
if
(
length
<
2
)
{
if
(
length
<
2
)
{
giterr_set
(
GITERR_INVALID
,
"At least two commits are required to find an ancestor. Provided 'length' was %u."
,
length
);
giterr_set
(
GITERR_INVALID
,
"At least two commits are required to find an ancestor. Provided 'length' was %u."
,
length
);
...
@@ -82,104 +80,92 @@ int git_merge_base_many(git_oid *out, git_repository *repo, size_t length, const
...
@@ -82,104 +80,92 @@ int git_merge_base_many(git_oid *out, git_repository *repo, size_t length, const
return
-
1
;
return
-
1
;
if
(
git_revwalk_new
(
&
walk
,
repo
)
<
0
)
if
(
git_revwalk_new
(
&
walk
,
repo
)
<
0
)
goto
cleanup
;
goto
on_error
;
for
(
i
=
1
;
i
<
length
;
i
++
)
{
for
(
i
=
1
;
i
<
length
;
i
++
)
{
commit
=
git_revwalk__commit_lookup
(
walk
,
&
input_array
[
i
]);
commit
=
git_revwalk__commit_lookup
(
walk
,
&
input_array
[
i
]);
if
(
commit
==
NULL
)
if
(
commit
==
NULL
)
goto
cleanup
;
goto
on_error
;
git_vector_insert
(
&
list
,
commit
);
git_vector_insert
(
&
list
,
commit
);
}
}
commit
=
git_revwalk__commit_lookup
(
walk
,
&
input_array
[
0
]);
commit
=
git_revwalk__commit_lookup
(
walk
,
&
input_array
[
0
]);
if
(
commit
==
NULL
)
if
(
commit
==
NULL
)
goto
cleanup
;
goto
on_error
;
if
(
git_merge__bases_many
(
&
result
,
walk
,
commit
,
&
list
)
<
0
)
if
(
git_merge__bases_many
(
&
result
,
walk
,
commit
,
&
list
)
<
0
)
goto
cleanup
;
goto
on_error
;
if
(
!
result
)
{
if
(
!
result
)
{
giterr_set
(
GITERR_MERGE
,
"No merge base found"
);
giterr_set
(
GITERR_MERGE
,
"No merge base found"
);
error
=
GIT_ENOTFOUND
;
error
=
GIT_ENOTFOUND
;
goto
cleanup
;
goto
on_error
;
}
}
git_oid_cpy
(
out
,
&
result
->
item
->
oid
);
*
out
=
result
;
*
walk_out
=
walk
;
error
=
0
;
git_vector_free
(
&
list
);
return
0
;
cleanup:
on_error:
git_commit_list_free
(
&
result
);
git_revwalk_free
(
walk
);
git_vector_free
(
&
list
);
git_vector_free
(
&
list
);
git_revwalk_free
(
walk
);
return
error
;
return
error
;
}
}
int
git_merge_base
s_many
(
git_oidarray
*
out
,
git_repository
*
repo
,
size_t
length
,
const
git_oid
input_array
[])
int
git_merge_base
_many
(
git_oid
*
out
,
git_repository
*
repo
,
size_t
length
,
const
git_oid
input_array
[])
{
{
git_revwalk
*
walk
;
git_revwalk
*
walk
;
git_vector
list
;
git_commit_list
*
result
=
NULL
;
git_commit_list
*
current
,
*
result
=
NULL
;
int
error
=
0
;
int
error
=
-
1
;
unsigned
int
i
;
git_commit_list_node
*
commit
;
git_array_oid_t
array
;
assert
(
out
&&
repo
&&
input_array
);
assert
(
out
&&
repo
&&
input_array
);
if
(
length
<
2
)
{
if
((
error
=
merge_bases_many
(
&
result
,
&
walk
,
repo
,
length
,
input_array
))
<
0
)
giterr_set
(
GITERR_INVALID
,
"At least two commits are required to find an ancestor. Provided 'length' was %u."
,
length
);
return
error
;
return
-
1
;
}
if
(
git_vector_init
(
&
list
,
length
-
1
,
NULL
)
<
0
)
return
-
1
;
if
(
git_revwalk_new
(
&
walk
,
repo
)
<
0
)
git_oid_cpy
(
out
,
&
result
->
item
->
oid
);
goto
cleanup
;
for
(
i
=
1
;
i
<
length
;
i
++
)
{
git_commit_list_free
(
&
result
);
commit
=
git_revwalk__commit_lookup
(
walk
,
&
input_array
[
i
]);
git_revwalk_free
(
walk
);
if
(
commit
==
NULL
)
goto
cleanup
;
git_vector_insert
(
&
list
,
commit
)
;
return
0
;
}
}
commit
=
git_revwalk__commit_lookup
(
walk
,
&
input_array
[
0
]);
int
git_merge_bases_many
(
git_oidarray
*
out
,
git_repository
*
repo
,
size_t
length
,
const
git_oid
input_array
[])
if
(
commit
==
NULL
)
{
goto
cleanup
;
git_revwalk
*
walk
;
git_commit_list
*
list
,
*
result
=
NULL
;
int
error
=
0
;
git_array_oid_t
array
;
if
(
git_merge__bases_many
(
&
result
,
walk
,
commit
,
&
list
)
<
0
)
assert
(
out
&&
repo
&&
input_array
);
goto
cleanup
;
if
(
!
result
)
{
if
((
error
=
merge_bases_many
(
&
result
,
&
walk
,
repo
,
length
,
input_array
))
<
0
)
giterr_set
(
GITERR_MERGE
,
"No merge base found"
);
return
error
;
error
=
GIT_ENOTFOUND
;
goto
cleanup
;
}
git_array_init
(
array
);
git_array_init
(
array
);
curren
t
=
result
;
lis
t
=
result
;
while
(
curren
t
)
{
while
(
lis
t
)
{
git_oid
*
id
=
git_array_alloc
(
array
);
git_oid
*
id
=
git_array_alloc
(
array
);
if
(
id
==
NULL
)
if
(
id
==
NULL
)
{
error
=
-
1
;
goto
cleanup
;
goto
cleanup
;
}
git_oid_cpy
(
id
,
&
curren
t
->
item
->
oid
);
git_oid_cpy
(
id
,
&
lis
t
->
item
->
oid
);
current
=
curren
t
->
next
;
list
=
lis
t
->
next
;
}
}
git_oidarray__from_array
(
out
,
&
array
);
git_oidarray__from_array
(
out
,
&
array
);
error
=
0
;
cleanup:
cleanup:
git_commit_list_free
(
&
result
);
git_commit_list_free
(
&
result
);
git_revwalk_free
(
walk
);
git_revwalk_free
(
walk
);
git_vector_free
(
&
list
);
return
error
;
return
error
;
}
}
...
...
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