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
be8404a7
Commit
be8404a7
authored
Feb 03, 2015
by
Edward Thomson
Committed by
Edward Thomson
Feb 14, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
merge-like operations: lock index while working
parent
8b0ddd5d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
11 deletions
+67
-11
src/cherrypick.c
+24
-4
src/rebase.c
+20
-3
src/revert.c
+23
-4
No files found.
src/cherrypick.c
View file @
be8404a7
...
...
@@ -10,6 +10,7 @@
#include "filebuf.h"
#include "merge.h"
#include "vector.h"
#include "index.h"
#include "git2/types.h"
#include "git2/merge.h"
...
...
@@ -171,7 +172,9 @@ int git_cherrypick(
char
commit_oidstr
[
GIT_OID_HEXSZ
+
1
];
const
char
*
commit_msg
,
*
commit_summary
;
git_buf
their_label
=
GIT_BUF_INIT
;
git_index
*
index_new
=
NULL
;
git_index
*
index
=
NULL
,
*
index_new
=
NULL
;
git_indexwriter
indexwriter
=
GIT_INDEXWRITER_INIT
;
bool
write_index
=
false
;
int
error
=
0
;
assert
(
repo
&&
commit
);
...
...
@@ -191,21 +194,38 @@ int git_cherrypick(
if
((
error
=
write_merge_msg
(
repo
,
commit_msg
))
<
0
||
(
error
=
git_buf_printf
(
&
their_label
,
"%.7s... %s"
,
commit_oidstr
,
commit_summary
))
<
0
||
(
error
=
cherrypick_normalize_opts
(
repo
,
&
opts
,
given_opts
,
git_buf_cstr
(
&
their_label
)))
<
0
||
(
error
=
write_cherrypick_head
(
repo
,
commit_oidstr
))
<
0
||
(
error
=
cherrypick_normalize_opts
(
repo
,
&
opts
,
given_opts
,
git_buf_cstr
(
&
their_label
)))
<
0
)
goto
on_error
;
write_index
=
(
opts
.
checkout_opts
.
checkout_strategy
&
GIT_CHECKOUT_DONT_WRITE_INDEX
)
==
0
;
if
(
write_index
)
{
/* Never let checkout update the index, we'll update it ourselves. */
opts
.
checkout_opts
.
checkout_strategy
|=
GIT_CHECKOUT_DONT_WRITE_INDEX
;
if
((
error
=
git_repository_index
(
&
index
,
repo
))
<
0
||
(
error
=
git_indexwriter_init
(
&
indexwriter
,
index
))
<
0
)
goto
on_error
;
}
if
((
error
=
write_cherrypick_head
(
repo
,
commit_oidstr
))
<
0
||
(
error
=
git_repository_head
(
&
our_ref
,
repo
))
<
0
||
(
error
=
git_reference_peel
((
git_object
**
)
&
our_commit
,
our_ref
,
GIT_OBJ_COMMIT
))
<
0
||
(
error
=
git_cherrypick_commit
(
&
index_new
,
repo
,
commit
,
our_commit
,
opts
.
mainline
,
&
opts
.
merge_opts
))
<
0
||
(
error
=
git_merge__check_result
(
repo
,
index_new
))
<
0
||
(
error
=
git_merge__append_conflicts_to_merge_msg
(
repo
,
index_new
))
<
0
||
(
error
=
git_checkout_index
(
repo
,
index_new
,
&
opts
.
checkout_opts
))
<
0
)
(
error
=
git_checkout_index
(
repo
,
index_new
,
&
opts
.
checkout_opts
))
<
0
||
(
write_index
&&
(
error
=
git_indexwriter_commit
(
&
indexwriter
))
<
0
))
goto
on_error
;
goto
done
;
on_error:
cherrypick_state_cleanup
(
repo
);
done:
git_indexwriter_cleanup
(
&
indexwriter
);
git_index_free
(
index
);
git_index_free
(
index_new
);
git_commit_free
(
our_commit
);
git_reference_free
(
our_ref
);
...
...
src/rebase.c
View file @
be8404a7
...
...
@@ -14,6 +14,7 @@
#include "array.h"
#include "config.h"
#include "annotated_commit.h"
#include "index.h"
#include <git2/types.h>
#include <git2/annotated_commit.h>
...
...
@@ -725,7 +726,9 @@ static int rebase_next_merge(
git_checkout_options
checkout_opts
=
{
0
};
git_commit
*
current_commit
=
NULL
,
*
parent_commit
=
NULL
;
git_tree
*
current_tree
=
NULL
,
*
head_tree
=
NULL
,
*
parent_tree
=
NULL
;
git_index
*
index
=
NULL
;
git_index
*
index
=
NULL
,
*
index_new
=
NULL
;
git_indexwriter
indexwriter
=
GIT_INDEXWRITER_INIT
;
bool
write_index
=
false
;
git_rebase_operation
*
operation
;
char
current_idstr
[
GIT_OID_HEXSZ
];
unsigned
int
parent_count
;
...
...
@@ -755,6 +758,17 @@ static int rebase_next_merge(
git_oid_fmt
(
current_idstr
,
&
operation
->
id
);
write_index
=
(
checkout_opts
.
checkout_strategy
&
GIT_CHECKOUT_DONT_WRITE_INDEX
)
==
0
;
if
(
write_index
)
{
/* Never let checkout update the index, we'll update it ourselves. */
checkout_opts
.
checkout_strategy
|=
GIT_CHECKOUT_DONT_WRITE_INDEX
;
if
((
error
=
git_repository_index
(
&
index
,
rebase
->
repo
))
<
0
||
(
error
=
git_indexwriter_init
(
&
indexwriter
,
index
))
<
0
)
goto
done
;
}
if
((
error
=
rebase_setupfile
(
rebase
,
MSGNUM_FILE
,
-
1
,
"%d
\n
"
,
rebase
->
current
+
1
))
<
0
||
(
error
=
rebase_setupfile
(
rebase
,
CURRENT_FILE
,
-
1
,
"%.*s
\n
"
,
GIT_OID_HEXSZ
,
current_idstr
))
<
0
)
goto
done
;
...
...
@@ -762,14 +776,17 @@ static int rebase_next_merge(
normalize_checkout_opts
(
rebase
,
current_commit
,
&
checkout_opts
,
given_checkout_opts
);
if
((
error
=
git_merge_trees
(
&
index
,
rebase
->
repo
,
parent_tree
,
head_tree
,
current_tree
,
NULL
))
<
0
||
(
error
=
git_merge__check_result
(
rebase
->
repo
,
index
))
<
0
||
(
error
=
git_checkout_index
(
rebase
->
repo
,
index
,
&
checkout_opts
))
<
0
)
(
error
=
git_merge__check_result
(
rebase
->
repo
,
index_new
))
<
0
||
(
error
=
git_checkout_index
(
rebase
->
repo
,
index_new
,
&
checkout_opts
))
<
0
||
(
write_index
&&
(
error
=
git_indexwriter_commit
(
&
indexwriter
))
<
0
))
goto
done
;
*
out
=
operation
;
done
:
git_indexwriter_cleanup
(
&
indexwriter
);
git_index_free
(
index
);
git_index_free
(
index_new
);
git_tree_free
(
current_tree
);
git_tree_free
(
head_tree
);
git_tree_free
(
parent_tree
);
...
...
src/revert.c
View file @
be8404a7
...
...
@@ -9,6 +9,7 @@
#include "repository.h"
#include "filebuf.h"
#include "merge.h"
#include "index.h"
#include "git2/types.h"
#include "git2/merge.h"
...
...
@@ -174,7 +175,9 @@ int git_revert(
char
commit_oidstr
[
GIT_OID_HEXSZ
+
1
];
const
char
*
commit_msg
;
git_buf
their_label
=
GIT_BUF_INIT
;
git_index
*
index_new
=
NULL
;
git_index
*
index
=
NULL
,
*
index_new
=
NULL
;
git_indexwriter
indexwriter
=
GIT_INDEXWRITER_INIT
;
bool
write_index
=
false
;
int
error
;
assert
(
repo
&&
commit
);
...
...
@@ -193,15 +196,29 @@ int git_revert(
}
if
((
error
=
git_buf_printf
(
&
their_label
,
"parent of %.7s... %s"
,
commit_oidstr
,
commit_msg
))
<
0
||
(
error
=
revert_normalize_opts
(
repo
,
&
opts
,
given_opts
,
git_buf_cstr
(
&
their_label
)))
<
0
||
(
error
=
write_revert_head
(
repo
,
commit_oidstr
))
<
0
||
(
error
=
revert_normalize_opts
(
repo
,
&
opts
,
given_opts
,
git_buf_cstr
(
&
their_label
)))
<
0
)
goto
on_error
;
write_index
=
(
opts
.
checkout_opts
.
checkout_strategy
&
GIT_CHECKOUT_DONT_WRITE_INDEX
)
==
0
;
if
(
write_index
)
{
/* Never let checkout update the index, we'll update it ourselves. */
opts
.
checkout_opts
.
checkout_strategy
|=
GIT_CHECKOUT_DONT_WRITE_INDEX
;
if
((
error
=
git_repository_index
(
&
index
,
repo
))
<
0
||
(
error
=
git_indexwriter_init
(
&
indexwriter
,
index
))
<
0
)
goto
on_error
;
}
if
((
error
=
write_revert_head
(
repo
,
commit_oidstr
))
<
0
||
(
error
=
write_merge_msg
(
repo
,
commit_oidstr
,
commit_msg
))
<
0
||
(
error
=
git_repository_head
(
&
our_ref
,
repo
))
<
0
||
(
error
=
git_reference_peel
((
git_object
**
)
&
our_commit
,
our_ref
,
GIT_OBJ_COMMIT
))
<
0
||
(
error
=
git_revert_commit
(
&
index_new
,
repo
,
commit
,
our_commit
,
opts
.
mainline
,
&
opts
.
merge_opts
))
<
0
||
(
error
=
git_merge__check_result
(
repo
,
index_new
))
<
0
||
(
error
=
git_merge__append_conflicts_to_merge_msg
(
repo
,
index_new
))
<
0
||
(
error
=
git_checkout_index
(
repo
,
index_new
,
&
opts
.
checkout_opts
))
<
0
)
(
error
=
git_checkout_index
(
repo
,
index_new
,
&
opts
.
checkout_opts
))
<
0
||
(
write_index
&&
(
error
=
git_indexwriter_commit
(
&
indexwriter
))
<
0
))
goto
on_error
;
goto
done
;
...
...
@@ -210,6 +227,8 @@ on_error:
revert_state_cleanup
(
repo
);
done:
git_indexwriter_cleanup
(
&
indexwriter
);
git_index_free
(
index
);
git_index_free
(
index_new
);
git_commit_free
(
our_commit
);
git_reference_free
(
our_ref
);
...
...
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