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
e93af304
Commit
e93af304
authored
Aug 24, 2012
by
nulltoken
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
checkout: introduce git_checkout_index()
parent
3aa443a9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
19 deletions
+55
-19
include/git2/checkout.h
+14
-0
src/checkout.c
+41
-19
No files found.
include/git2/checkout.h
View file @
e93af304
...
...
@@ -71,6 +71,20 @@ GIT_EXTERN(int) git_checkout_reference(
git_indexer_stats
*
stats
);
/**
* Updates files in the working tree to match the content of the index.
*
* @param repo repository to check out (must be non-bare)
* @param opts specifies checkout options (may be NULL)
* @param stats structure through which progress information is reported
* @return 0 on success, GIT_ERROR otherwise (use giterr_last for information
* about the error)
*/
GIT_EXTERN
(
int
)
git_checkout_index
(
git_repository
*
repo
,
git_checkout_opts
*
opts
,
git_indexer_stats
*
stats
);
/**
* Updates files in the index and working tree to match the content of the
* tree pointed at by the treeish.
*
...
...
src/checkout.c
View file @
e93af304
...
...
@@ -220,14 +220,12 @@ static void normalize_options(git_checkout_opts *normalized, git_checkout_opts *
normalized
->
file_open_flags
=
O_CREAT
|
O_TRUNC
|
O_WRONLY
;
}
int
git_checkout_
tree
(
int
git_checkout_
index
(
git_repository
*
repo
,
git_object
*
treeish
,
git_checkout_opts
*
opts
,
git_indexer_stats
*
stats
)
{
git_index
*
index
=
NULL
;
git_tree
*
tree
=
NULL
;
git_diff_list
*
diff
=
NULL
;
git_indexer_stats
dummy_stats
;
...
...
@@ -239,25 +237,11 @@ int git_checkout_tree(
int
error
;
assert
(
repo
&&
treeish
);
assert
(
repo
);
if
((
git_repository__ensure_not_bare
(
repo
,
"checkout"
))
<
0
)
return
GIT_EBAREREPO
;
if
(
git_object_peel
((
git_object
**
)
&
tree
,
treeish
,
GIT_OBJ_TREE
)
<
0
)
{
giterr_set
(
GITERR_INVALID
,
"Provided treeish cannot be peeled into a tree."
);
return
GIT_ERROR
;
}
if
((
error
=
git_repository_index
(
&
index
,
repo
))
<
0
)
goto
cleanup
;
if
((
error
=
git_index_read_tree
(
index
,
tree
,
NULL
))
<
0
)
goto
cleanup
;
if
((
error
=
git_index_write
(
index
))
<
0
)
goto
cleanup
;
diff_opts
.
flags
=
GIT_DIFF_INCLUDE_UNTRACKED
;
if
(
opts
&&
opts
->
paths
)
{
...
...
@@ -277,6 +261,10 @@ int git_checkout_tree(
stats
=
&
dummy_stats
;
stats
->
processed
=
0
;
if
((
git_repository_index
(
&
index
,
repo
))
<
0
)
goto
cleanup
;
stats
->
total
=
git_index_entrycount
(
index
);
memset
(
&
data
,
0
,
sizeof
(
data
));
...
...
@@ -293,10 +281,44 @@ int git_checkout_tree(
error
=
git_diff_foreach
(
diff
,
&
data
,
checkout_diff_fn
,
NULL
,
NULL
);
cleanup:
git_index_free
(
index
);
git_diff_list_free
(
diff
);
git_buf_free
(
&
workdir
);
return
error
;
}
int
git_checkout_tree
(
git_repository
*
repo
,
git_object
*
treeish
,
git_checkout_opts
*
opts
,
git_indexer_stats
*
stats
)
{
git_index
*
index
=
NULL
;
git_tree
*
tree
=
NULL
;
int
error
;
assert
(
repo
&&
treeish
);
if
(
git_object_peel
((
git_object
**
)
&
tree
,
treeish
,
GIT_OBJ_TREE
)
<
0
)
{
giterr_set
(
GITERR_INVALID
,
"Provided treeish cannot be peeled into a tree."
);
return
GIT_ERROR
;
}
if
((
error
=
git_repository_index
(
&
index
,
repo
))
<
0
)
goto
cleanup
;
if
((
error
=
git_index_read_tree
(
index
,
tree
,
NULL
))
<
0
)
goto
cleanup
;
if
((
error
=
git_index_write
(
index
))
<
0
)
goto
cleanup
;
error
=
git_checkout_index
(
repo
,
opts
,
stats
);
cleanup:
git_index_free
(
index
);
git_tree_free
(
tree
);
git_buf_free
(
&
workdir
);
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