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
ac584fcf
Commit
ac584fcf
authored
Mar 18, 2014
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce GIT_MERGE_ANALYSIS_UNBORN
parent
97f3462a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
14 deletions
+52
-14
include/git2/merge.h
+7
-0
src/merge.c
+25
-10
tests/merge/workdir/analysis.c
+20
-4
No files found.
include/git2/merge.h
View file @
ac584fcf
...
...
@@ -259,6 +259,13 @@ typedef enum {
* given merge input.
*/
GIT_MERGE_ANALYSIS_FASTFORWARD
=
(
1
<<
2
),
/**
* The HEAD of the current repository is "unborn" and does not point to
* a valid commit. No merge can be performed, but the caller may wish
* to simply set HEAD to the target commit(s).
*/
GIT_MERGE_ANALYSIS_UNBORN
=
(
1
<<
3
),
}
git_merge_analysis_t
;
/**
...
...
src/merge.c
View file @
ac584fcf
...
...
@@ -2524,26 +2524,41 @@ int git_merge_analysis(
size_t
their_heads_len
)
{
git_merge_head
*
ancestor_head
=
NULL
,
*
our_head
=
NULL
;
int
error
;
int
error
=
0
;
assert
(
out
&&
repo
&&
their_heads
);
*
out
=
GIT_MERGE_ANALYSIS_NORMAL
;
*
out
=
GIT_MERGE_ANALYSIS_NONE
;
if
(
git_repository_head_unborn
(
repo
))
{
*
out
=
GIT_MERGE_ANALYSIS_UNBORN
;
goto
done
;
}
if
(
their_heads_len
!=
1
)
{
giterr_set
(
GITERR_MERGE
,
"Can only merge a single branch"
);
error
=
-
1
;
goto
done
;
}
if
((
error
=
merge_heads
(
&
ancestor_head
,
&
our_head
,
repo
,
their_heads
,
their_heads_len
))
<
0
)
goto
done
;
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_ANALYSIS_UP_TO_DATE
;
/* We're up-to-date if we're trying to merge our own common ancestor. */
if
(
ancestor_head
&&
git_oid_equal
(
&
ancestor_head
->
oid
,
&
their_heads
[
0
]
->
oid
))
*
out
=
GIT_MERGE_ANALYSIS_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_ANALYSIS_FASTFORWARD
|
GIT_MERGE_ANALYSIS_NORMAL
;
}
/* We're fastforwardable if we're our own common ancestor. */
else
if
(
ancestor_head
&&
git_oid_equal
(
&
ancestor_head
->
oid
,
&
our_head
->
oid
))
*
out
=
GIT_MERGE_ANALYSIS_FASTFORWARD
|
GIT_MERGE_ANALYSIS_NORMAL
;
/* Otherwise, just a normal merge is possible. */
else
*
out
=
GIT_MERGE_ANALYSIS_NORMAL
;
done:
git_merge_head_free
(
ancestor_head
);
git_merge_head_free
(
our_head
);
return
error
;
}
...
...
tests/merge/workdir/analysis.c
View file @
ac584fcf
...
...
@@ -5,6 +5,7 @@
#include "merge.h"
#include "../merge_helpers.h"
#include "refs.h"
#include "posix.h"
static
git_repository
*
repo
;
static
git_index
*
repo_index
;
...
...
@@ -39,18 +40,18 @@ static git_merge_analysis_t analysis_from_branch(const char *branchname)
{
git_buf
refname
=
GIT_BUF_INIT
;
git_reference
*
their_ref
;
git_merge_head
*
their_head
s
[
1
]
;
git_merge_head
*
their_head
;
git_merge_analysis_t
analysis
;
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_head
s
[
0
]
,
repo
,
their_ref
));
cl_git_pass
(
git_merge_head_from_ref
(
&
their_head
,
repo
,
their_ref
));
cl_git_pass
(
git_merge_analysis
(
&
analysis
,
repo
,
their_heads
,
1
));
cl_git_pass
(
git_merge_analysis
(
&
analysis
,
repo
,
(
const
git_merge_head
**
)
&
their_head
,
1
));
git_buf_free
(
&
refname
);
git_merge_head_free
(
their_head
s
[
0
]
);
git_merge_head_free
(
their_head
);
git_reference_free
(
their_ref
);
return
analysis
;
...
...
@@ -88,3 +89,18 @@ void test_merge_workdir_analysis__uptodate_merging_prev_commit(void)
analysis
=
analysis_from_branch
(
PREVIOUS_BRANCH
);
cl_assert_equal_i
(
GIT_MERGE_ANALYSIS_UP_TO_DATE
,
analysis
);
}
void
test_merge_workdir_analysis__unborn
(
void
)
{
git_merge_analysis_t
analysis
;
git_buf
master
=
GIT_BUF_INIT
;
git_buf_joinpath
(
&
master
,
git_repository_path
(
repo
),
"refs/heads/master"
);
p_unlink
(
git_buf_cstr
(
&
master
));
analysis
=
analysis_from_branch
(
NOFASTFORWARD_BRANCH
);
cl_assert_equal_i
(
GIT_MERGE_ANALYSIS_UNBORN
,
analysis
);
git_buf_free
(
&
master
);
}
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