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
f16c0a9d
Commit
f16c0a9d
authored
Apr 23, 2011
by
Vicent Martí
Browse files
Options
Browse Files
Download
Plain Diff
Merged pull request #140 from jpfender/insert-replace.
index: Allow user to toggle whether to replace an index entry
parents
5ba7c4cb
729b6f49
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
9 deletions
+12
-9
include/git2/index.h
+5
-4
src/index.c
+7
-5
No files found.
include/git2/index.h
View file @
f16c0a9d
...
...
@@ -203,15 +203,16 @@ GIT_EXTERN(int) git_index_remove(git_index *index, int position);
/**
* Insert an entry into the index.
* A full copy (including the 'path' string) of the given
* 'source_entry' will be inserted on the index; if the
index
*
already contains an entry for the same path, the entry
* will be updated.
* 'source_entry' will be inserted on the index; if the
*
replace flag is not set and the index already contains
*
an entry for the same path, the entry
will be updated.
*
* @param index an existing index object
* @param source_entry new entry object
* @param replace if set, existing entries will be replaced
* @return 0 on success, otherwise an error code
*/
GIT_EXTERN
(
int
)
git_index_insert
(
git_index
*
index
,
const
git_index_entry
*
source_entry
);
GIT_EXTERN
(
int
)
git_index_insert
(
git_index
*
index
,
const
git_index_entry
*
source_entry
,
int
replace
);
/**
* Get a pointer to one of the entries in the index
...
...
src/index.c
View file @
f16c0a9d
...
...
@@ -330,7 +330,7 @@ int git_index_add(git_index *index, const char *rel_path, int stage)
entry
.
flags
|=
(
stage
<<
GIT_IDXENTRY_STAGESHIFT
);
entry
.
path
=
(
char
*
)
rel_path
;
/* do not duplicate; index_insert already does this */
return
git_index_insert
(
index
,
&
entry
);
return
git_index_insert
(
index
,
&
entry
,
1
);
}
void
sort_index
(
git_index
*
index
)
...
...
@@ -338,7 +338,7 @@ void sort_index(git_index *index)
git_vector_sort
(
&
index
->
entries
);
}
int
git_index_insert
(
git_index
*
index
,
const
git_index_entry
*
source_entry
)
int
git_index_insert
(
git_index
*
index
,
const
git_index_entry
*
source_entry
,
int
replace
)
{
git_index_entry
*
entry
;
size_t
path_length
;
...
...
@@ -374,13 +374,15 @@ int git_index_insert(git_index *index, const git_index_entry *source_entry)
/* look if an entry with this path already exists */
position
=
git_index_find
(
index
,
source_entry
->
path
);
/* if no entry exists, add the entry at the end;
/* if no entry exists and replace is not set,
* add the entry at the end;
* the index is no longer sorted */
if
(
position
==
GIT_ENOTFOUND
)
{
if
(
!
replace
||
position
==
GIT_ENOTFOUND
)
{
if
(
git_vector_insert
(
&
index
->
entries
,
entry
)
<
GIT_SUCCESS
)
return
GIT_ENOMEM
;
/* if a previous entry exists, replace it */
/* if a previous entry exists and replace is set,
* replace it */
}
else
{
git_index_entry
**
entry_array
=
(
git_index_entry
**
)
index
->
entries
.
contents
;
...
...
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