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
276ea401
Commit
276ea401
authored
Nov 01, 2012
by
Vicent Marti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
index: Add git_index_write_tree
parent
8ff0f325
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
84 additions
and
32 deletions
+84
-32
include/git2/index.h
+32
-0
include/git2/tree.h
+0
-18
src/index.c
+44
-8
src/tree.c
+2
-6
src/tree.h
+6
-0
No files found.
include/git2/index.h
View file @
276ea401
...
...
@@ -190,6 +190,38 @@ GIT_EXTERN(int) git_index_write(git_index *index);
*/
GIT_EXTERN
(
int
)
git_index_read_tree
(
git_index
*
index
,
git_tree
*
tree
);
/**
* Write the index as a tree
*
* This method will scan the index and write a representation
* of its current state back to disk; it recursively creates
* tree objects for each of the subtrees stored in the index,
* but only returns the OID of the root tree. This is the OID
* that can be used e.g. to create a commit.
*
* The index instance cannot be bare, and needs to be associated
* to an existing repository.
*
* @param oid Pointer where to store the OID of the written tree
* @param index Index to write
* @return 0 or an error code
*/
GIT_EXTERN
(
int
)
git_index_write_tree
(
git_oid
*
oid
,
git_index
*
index
);
/**
* Write the index as a tree to the given repository
*
* This method will do the same as `git_index_write_tree`, but
* letting the user choose the repository where the tree will
* be written.
*
* @param oid Pointer where to store OID of the the written tree
* @param index Index to write
* @param repo Repository where to write the tree
* @return 0 or an error code
*/
GIT_EXTERN
(
int
)
git_index_write_tree_to
(
git_oid
*
oid
,
git_index
*
index
,
git_repository
*
repo
);
/**@}*/
/** @name Raw Index Entry Functions
...
...
include/git2/tree.h
View file @
276ea401
...
...
@@ -185,24 +185,6 @@ GIT_EXTERN(int) git_tree_entry_to_object(
const
git_tree_entry
*
entry
);
/**
* Write a tree to the ODB from the index file
*
* This method will scan the index and write a representation
* of its current state back to disk; it recursively creates
* tree objects for each of the subtrees stored in the index,
* but only returns the OID of the root tree. This is the OID
* that can be used e.g. to create a commit.
*
* The index instance cannot be bare, and needs to be associated
* to an existing repository.
*
* @param oid Pointer where to store the written tree
* @param index Index to write
* @return 0 or an error code
*/
GIT_EXTERN
(
int
)
git_tree_create_fromindex
(
git_oid
*
oid
,
git_index
*
index
);
/**
* Create a new tree builder.
*
* The tree builder can be used to create or modify
...
...
src/index.c
View file @
276ea401
...
...
@@ -264,8 +264,14 @@ int git_index_open(git_index **index_out, const char *index_path)
index
=
git__calloc
(
1
,
sizeof
(
git_index
));
GITERR_CHECK_ALLOC
(
index
);
index
->
index_file_path
=
git__strdup
(
index_path
);
GITERR_CHECK_ALLOC
(
index
->
index_file_path
);
if
(
index_path
!=
NULL
)
{
index
->
index_file_path
=
git__strdup
(
index_path
);
GITERR_CHECK_ALLOC
(
index
->
index_file_path
);
/* Check if index file is stored on disk already */
if
(
git_path_exists
(
index
->
index_file_path
)
==
true
)
index
->
on_disk
=
1
;
}
if
(
git_vector_init
(
&
index
->
entries
,
32
,
index_cmp
)
<
0
)
return
-
1
;
...
...
@@ -275,13 +281,10 @@ int git_index_open(git_index **index_out, const char *index_path)
index
->
entries_search_path
=
index_srch_path
;
index
->
reuc_search
=
reuc_srch
;
/* Check if index file is stored on disk already */
if
(
git_path_exists
(
index
->
index_file_path
)
==
true
)
index
->
on_disk
=
1
;
*
index_out
=
index
;
GIT_REFCOUNT_INC
(
index
);
return
git_index_read
(
index
);
return
(
index_path
!=
NULL
)
?
git_index_read
(
index
)
:
0
;
}
static
void
index_free
(
git_index
*
index
)
...
...
@@ -394,7 +397,11 @@ int git_index_read(git_index *index)
git_buf
buffer
=
GIT_BUF_INIT
;
git_futils_filestamp
stamp
;
assert
(
index
->
index_file_path
);
if
(
!
index
->
index_file_path
)
{
giterr_set
(
GITERR_INDEX
,
"Failed to read index: The index is in-memory only"
);
return
-
1
;
}
if
(
!
index
->
on_disk
||
git_path_exists
(
index
->
index_file_path
)
==
false
)
{
git_index_clear
(
index
);
...
...
@@ -426,6 +433,12 @@ int git_index_write(git_index *index)
struct
stat
indexst
;
int
error
;
if
(
!
index
->
index_file_path
)
{
giterr_set
(
GITERR_INDEX
,
"Failed to write index: The index is in-memory only"
);
return
-
1
;
}
git_vector_sort
(
&
index
->
entries
);
git_vector_sort
(
&
index
->
reuc
);
...
...
@@ -449,6 +462,29 @@ int git_index_write(git_index *index)
return
0
;
}
int
git_index_write_tree
(
git_oid
*
oid
,
git_index
*
index
)
{
git_repository
*
repo
;
assert
(
oid
&&
index
);
repo
=
(
git_repository
*
)
GIT_REFCOUNT_OWNER
(
index
);
if
(
repo
==
NULL
)
{
giterr_set
(
GITERR_INDEX
,
"Failed to write tree. "
"The index file is not backed up by an existing repository"
);
return
-
1
}
return
git_tree__write_index
(
oid
,
index
,
repo
);
}
int
git_index_write_tree_to
(
git_oid
*
oid
,
git_index
*
index
,
git_repository
*
repo
)
{
assert
(
oid
&&
index
&&
repo
);
return
git_tree__write_index
(
oid
,
index
,
repo
);
}
unsigned
int
git_index_entrycount
(
git_index
*
index
)
{
assert
(
index
);
...
...
src/tree.c
View file @
276ea401
...
...
@@ -491,16 +491,12 @@ on_error:
return
-
1
;
}
int
git_tree_
create_fromindex
(
git_oid
*
oid
,
git_index
*
index
)
int
git_tree_
_write_index
(
git_oid
*
oid
,
git_index
*
index
,
git_repository
*
repo
)
{
int
ret
;
git_repository
*
repo
;
repo
=
(
git_repository
*
)
GIT_REFCOUNT_OWNER
(
index
);
if
(
repo
==
NULL
)
return
tree_error
(
"Failed to create tree. "
"The index file is not backed up by an existing repository"
);
assert
(
oid
&&
index
&&
repo
);
if
(
index
->
tree
!=
NULL
&&
index
->
tree
->
entries
>=
0
)
{
git_oid_cpy
(
oid
,
&
index
->
tree
->
oid
);
...
...
src/tree.h
View file @
276ea401
...
...
@@ -47,6 +47,12 @@ int git_tree__parse(git_tree *tree, git_odb_object *obj);
*/
int
git_tree__prefix_position
(
git_tree
*
tree
,
const
char
*
prefix
);
/**
* Write a tree to the given repository
*/
int
git_tree__write_index
(
git_oid
*
oid
,
git_index
*
index
,
git_repository
*
repo
);
/**
* Obsolete mode kept for compatibility reasons
*/
...
...
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