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
97f3462a
Commit
97f3462a
authored
Mar 18, 2014
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
git_merge_status -> git_merge_analysis
parent
d9fdee6e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
37 deletions
+41
-37
include/git2/merge.h
+13
-10
src/merge.c
+5
-5
tests/merge/workdir/analysis.c
+23
-22
No files found.
include/git2/merge.h
View file @
97f3462a
...
...
@@ -235,41 +235,44 @@ GIT_EXTERN(int) git_merge_init_options(
int
version
);
/**
* The results of `git_merge_
status` indicate the state of a merge scenario
.
* The results of `git_merge_
analysis` indicate the merge opportunities
.
*/
typedef
enum
{
/** No merge is possible. (Unused.) */
GIT_MERGE_ANALYSIS_NONE
=
0
,
/**
* A "normal" merge; both HEAD and the given merge input have diverged
* from their common ancestor. The divergent commits must be merged.
*/
GIT_MERGE_
STATUS_NORMAL
=
0
,
GIT_MERGE_
ANALYSIS_NORMAL
=
(
1
<<
0
)
,
/**
* The repository is already up-to-date and no merge needs to be
* performed. The given merge input already exists as a parent of HEAD.
*/
GIT_MERGE_
STATUS_UP_TO_DATE
=
(
1
<<
0
),
GIT_MERGE_
ANALYSIS_UP_TO_DATE
=
(
1
<<
1
),
/**
* The given merge input is a fast-forward from HEAD and no merge
* needs to be performed. Instead, the client can check out the
* given merge input.
*/
GIT_MERGE_
STATUS_FASTFORWARD
=
(
1
<<
1
),
}
git_merge_
statu
s_t
;
GIT_MERGE_
ANALYSIS_FASTFORWARD
=
(
1
<<
2
),
}
git_merge_
analysi
s_t
;
/**
*
Determine the status of the merge between the given branch(es) and the
* HEAD of the repository.
*
Analyzes the given branch(es) and determines the opportunities for
*
merging them into the
HEAD of the repository.
*
* @param
status_out statu
s enumeration that the result is written into
* @param
analysis_out analysi
s enumeration that the result is written into
* @param repo the repository to merge
* @param their_heads the heads to merge into
* @param their_heads_len the number of heads to merge
* @return 0 on success or error code
*/
GIT_EXTERN
(
int
)
git_merge_
statu
s
(
git_merge_
status_t
*
statu
s_out
,
GIT_EXTERN
(
int
)
git_merge_
analysi
s
(
git_merge_
analysis_t
*
analysi
s_out
,
git_repository
*
repo
,
const
git_merge_head
**
their_heads
,
size_t
their_heads_len
);
...
...
src/merge.c
View file @
97f3462a
...
...
@@ -2517,8 +2517,8 @@ done:
return
error
;
}
int
git_merge_
statu
s
(
git_merge_
statu
s_t
*
out
,
int
git_merge_
analysi
s
(
git_merge_
analysi
s_t
*
out
,
git_repository
*
repo
,
const
git_merge_head
**
their_heads
,
size_t
their_heads_len
)
...
...
@@ -2528,7 +2528,7 @@ int git_merge_status(
assert
(
out
&&
repo
&&
their_heads
);
*
out
=
GIT_MERGE_
STATU
S_NORMAL
;
*
out
=
GIT_MERGE_
ANALYSI
S_NORMAL
;
if
((
error
=
merge_heads
(
&
ancestor_head
,
&
our_head
,
repo
,
their_heads
,
their_heads_len
))
<
0
)
goto
done
;
...
...
@@ -2536,11 +2536,11 @@ int git_merge_status(
if
(
their_heads_len
==
1
&&
ancestor_head
!=
NULL
)
{
/* We're up-to-date if we're trying to merge our own common ancestor. */
if
(
git_oid_equal
(
&
ancestor_head
->
oid
,
&
their_heads
[
0
]
->
oid
))
*
out
=
GIT_MERGE_
STATU
S_UP_TO_DATE
;
*
out
=
GIT_MERGE_
ANALYSI
S_UP_TO_DATE
;
/* We're fastforwardable if we're our own common ancestor. */
else
if
(
git_oid_equal
(
&
ancestor_head
->
oid
,
&
our_head
->
oid
))
*
out
=
GIT_MERGE_
STATUS_FASTFORWARD
;
*
out
=
GIT_MERGE_
ANALYSIS_FASTFORWARD
|
GIT_MERGE_ANALYSIS_NORMAL
;
}
done:
...
...
tests/merge/workdir/
statu
s.c
→
tests/merge/workdir/
analysi
s.c
View file @
97f3462a
...
...
@@ -23,67 +23,68 @@ static git_index *repo_index;
// Fixture setup and teardown
void
test_merge_workdir_
statu
s__initialize
(
void
)
void
test_merge_workdir_
analysi
s__initialize
(
void
)
{
repo
=
cl_git_sandbox_init
(
TEST_REPO_PATH
);
git_repository_index
(
&
repo_index
,
repo
);
}
void
test_merge_workdir_
statu
s__cleanup
(
void
)
void
test_merge_workdir_
analysi
s__cleanup
(
void
)
{
git_index_free
(
repo_index
);
cl_git_sandbox_cleanup
();
}
static
git_
status_t
statu
s_from_branch
(
const
char
*
branchname
)
static
git_
merge_analysis_t
analysi
s_from_branch
(
const
char
*
branchname
)
{
git_buf
refname
=
GIT_BUF_INIT
;
git_reference
*
their_ref
;
git_merge_head
*
their_heads
[
1
];
git_
status_t
statu
s
;
git_
merge_analysis_t
analysi
s
;
git_buf_printf
(
&
refname
,
"%s%s"
,
GIT_REFS_HEADS_DIR
,
branchname
);
cl_git_pass
(
git_reference_lookup
(
&
their_ref
,
repo
,
git_buf_cstr
(
&
refname
)));
cl_git_pass
(
git_merge_head_from_ref
(
&
their_heads
[
0
],
repo
,
their_ref
));
cl_git_pass
(
git_merge_
status
(
&
statu
s
,
repo
,
their_heads
,
1
));
cl_git_pass
(
git_merge_
analysis
(
&
analysi
s
,
repo
,
their_heads
,
1
));
git_buf_free
(
&
refname
);
git_merge_head_free
(
their_heads
[
0
]);
git_reference_free
(
their_ref
);
return
statu
s
;
return
analysi
s
;
}
void
test_merge_workdir_
statu
s__fastforward
(
void
)
void
test_merge_workdir_
analysi
s__fastforward
(
void
)
{
git_merge_
status_t
statu
s
;
git_merge_
analysis_t
analysi
s
;
status
=
status_from_branch
(
FASTFORWARD_BRANCH
);
cl_assert_equal_i
(
GIT_MERGE_STATUS_FASTFORWARD
,
status
);
analysis
=
analysis_from_branch
(
FASTFORWARD_BRANCH
);
cl_assert_equal_i
(
GIT_MERGE_ANALYSIS_FASTFORWARD
,
(
analysis
&
GIT_MERGE_ANALYSIS_FASTFORWARD
));
cl_assert_equal_i
(
GIT_MERGE_ANALYSIS_NORMAL
,
(
analysis
&
GIT_MERGE_ANALYSIS_NORMAL
));
}
void
test_merge_workdir_
statu
s__no_fastforward
(
void
)
void
test_merge_workdir_
analysi
s__no_fastforward
(
void
)
{
git_merge_
status_t
statu
s
;
git_merge_
analysis_t
analysi
s
;
status
=
statu
s_from_branch
(
NOFASTFORWARD_BRANCH
);
cl_assert_equal_i
(
GIT_MERGE_
STATUS_NORMAL
,
statu
s
);
analysis
=
analysi
s_from_branch
(
NOFASTFORWARD_BRANCH
);
cl_assert_equal_i
(
GIT_MERGE_
ANALYSIS_NORMAL
,
analysi
s
);
}
void
test_merge_workdir_
statu
s__uptodate
(
void
)
void
test_merge_workdir_
analysi
s__uptodate
(
void
)
{
git_merge_
status_t
statu
s
;
git_merge_
analysis_t
analysi
s
;
status
=
statu
s_from_branch
(
UPTODATE_BRANCH
);
cl_assert_equal_i
(
GIT_MERGE_
STATUS_UP_TO_DATE
,
statu
s
);
analysis
=
analysi
s_from_branch
(
UPTODATE_BRANCH
);
cl_assert_equal_i
(
GIT_MERGE_
ANALYSIS_UP_TO_DATE
,
analysi
s
);
}
void
test_merge_workdir_
statu
s__uptodate_merging_prev_commit
(
void
)
void
test_merge_workdir_
analysi
s__uptodate_merging_prev_commit
(
void
)
{
git_merge_
status_t
statu
s
;
git_merge_
analysis_t
analysi
s
;
status
=
statu
s_from_branch
(
PREVIOUS_BRANCH
);
cl_assert_equal_i
(
GIT_MERGE_
STATUS_UP_TO_DATE
,
statu
s
);
analysis
=
analysi
s_from_branch
(
PREVIOUS_BRANCH
);
cl_assert_equal_i
(
GIT_MERGE_
ANALYSIS_UP_TO_DATE
,
analysi
s
);
}
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