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
11d9f6b3
Commit
11d9f6b3
authored
Jan 27, 2013
by
Philip Kelley
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Vector improvements and their fallout
parent
aa3bf89d
Show whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
226 additions
and
191 deletions
+226
-191
include/git2/index.h
+6
-4
src/attr.c
+8
-7
src/attr_file.c
+6
-5
src/commit.c
+2
-1
src/diff_tform.c
+19
-6
src/index.c
+35
-34
src/iterator.c
+1
-1
src/pack.c
+2
-3
src/remote.c
+1
-2
src/stash.c
+1
-1
src/submodule.c
+4
-4
src/tree.c
+34
-28
src/util.c
+6
-6
src/util.h
+4
-1
src/vector.c
+71
-53
src/vector.h
+5
-12
tests-clar/attr/repo.c
+2
-3
tests-clar/index/filemodes.c
+2
-3
tests-clar/index/rename.c
+3
-3
tests-clar/index/stage.c
+7
-7
tests-clar/index/tests.c
+5
-4
tests-clar/submodule/status.c
+2
-3
No files found.
include/git2/index.h
View file @
11d9f6b3
...
@@ -403,11 +403,12 @@ GIT_EXTERN(int) git_index_remove_bypath(git_index *index, const char *path);
...
@@ -403,11 +403,12 @@ GIT_EXTERN(int) git_index_remove_bypath(git_index *index, const char *path);
* Find the first index of any entries which point to given
* Find the first index of any entries which point to given
* path in the Git index.
* path in the Git index.
*
*
* @param at_pos the address to which the position of the index entry is written (optional)
* @param index an existing index object
* @param index an existing index object
* @param path path to search
* @param path path to search
* @return
an index >= 0 if found, -1 otherwise
* @return
0 if found, < 0 otherwise (GIT_ENOTFOUND)
*/
*/
GIT_EXTERN
(
int
)
git_index_find
(
git_index
*
index
,
const
char
*
path
);
GIT_EXTERN
(
int
)
git_index_find
(
size_t
*
at_pos
,
git_index
*
index
,
const
char
*
path
);
/**@}*/
/**@}*/
...
@@ -495,11 +496,12 @@ GIT_EXTERN(unsigned int) git_index_reuc_entrycount(git_index *index);
...
@@ -495,11 +496,12 @@ GIT_EXTERN(unsigned int) git_index_reuc_entrycount(git_index *index);
* Finds the resolve undo entry that points to the given path in the Git
* Finds the resolve undo entry that points to the given path in the Git
* index.
* index.
*
*
* @param at_pos the address to which the position of the reuc entry is written (optional)
* @param index an existing index object
* @param index an existing index object
* @param path path to search
* @param path path to search
* @return
an index >= 0 if found, -1 otherwise
* @return
0 if found, < 0 otherwise (GIT_ENOTFOUND)
*/
*/
GIT_EXTERN
(
int
)
git_index_reuc_find
(
git_index
*
index
,
const
char
*
path
);
GIT_EXTERN
(
int
)
git_index_reuc_find
(
size_t
*
at_pos
,
git_index
*
index
,
const
char
*
path
);
/**
/**
* Get a resolve undo entry from the index.
* Get a resolve undo entry from the index.
...
...
src/attr.c
View file @
11d9f6b3
...
@@ -61,8 +61,9 @@ int git_attr_get(
...
@@ -61,8 +61,9 @@ int git_attr_get(
git_vector_foreach
(
&
files
,
i
,
file
)
{
git_vector_foreach
(
&
files
,
i
,
file
)
{
git_attr_file__foreach_matching_rule
(
file
,
&
path
,
j
,
rule
)
{
git_attr_file__foreach_matching_rule
(
file
,
&
path
,
j
,
rule
)
{
int
pos
=
git_vector_bsearch
(
&
rule
->
assigns
,
&
attr
);
size_t
pos
;
if
(
pos
>=
0
)
{
if
(
!
git_vector_bsearch
(
&
pos
,
&
rule
->
assigns
,
&
attr
))
{
*
value
=
((
git_attr_assignment
*
)
git_vector_get
(
*
value
=
((
git_attr_assignment
*
)
git_vector_get
(
&
rule
->
assigns
,
pos
))
->
value
;
&
rule
->
assigns
,
pos
))
->
value
;
goto
cleanup
;
goto
cleanup
;
...
@@ -116,7 +117,7 @@ int git_attr_get_many(
...
@@ -116,7 +117,7 @@ int git_attr_get_many(
git_attr_file__foreach_matching_rule
(
file
,
&
path
,
j
,
rule
)
{
git_attr_file__foreach_matching_rule
(
file
,
&
path
,
j
,
rule
)
{
for
(
k
=
0
;
k
<
num_attr
;
k
++
)
{
for
(
k
=
0
;
k
<
num_attr
;
k
++
)
{
in
t
pos
;
size_
t
pos
;
if
(
info
[
k
].
found
!=
NULL
)
/* already found assignment */
if
(
info
[
k
].
found
!=
NULL
)
/* already found assignment */
continue
;
continue
;
...
@@ -126,8 +127,7 @@ int git_attr_get_many(
...
@@ -126,8 +127,7 @@ int git_attr_get_many(
info
[
k
].
name
.
name_hash
=
git_attr_file__name_hash
(
names
[
k
]);
info
[
k
].
name
.
name_hash
=
git_attr_file__name_hash
(
names
[
k
]);
}
}
pos
=
git_vector_bsearch
(
&
rule
->
assigns
,
&
info
[
k
].
name
);
if
(
!
git_vector_bsearch
(
&
pos
,
&
rule
->
assigns
,
&
info
[
k
].
name
))
{
if
(
pos
>=
0
)
{
info
[
k
].
found
=
(
git_attr_assignment
*
)
info
[
k
].
found
=
(
git_attr_assignment
*
)
git_vector_get
(
&
rule
->
assigns
,
pos
);
git_vector_get
(
&
rule
->
assigns
,
pos
);
values
[
k
]
=
info
[
k
].
found
->
value
;
values
[
k
]
=
info
[
k
].
found
->
value
;
...
@@ -294,14 +294,15 @@ static int load_attr_blob_from_index(
...
@@ -294,14 +294,15 @@ static int load_attr_blob_from_index(
const
char
*
relfile
)
const
char
*
relfile
)
{
{
int
error
;
int
error
;
size_t
pos
;
git_index
*
index
;
git_index
*
index
;
const
git_index_entry
*
entry
;
const
git_index_entry
*
entry
;
if
((
error
=
git_repository_index__weakptr
(
&
index
,
repo
))
<
0
||
if
((
error
=
git_repository_index__weakptr
(
&
index
,
repo
))
<
0
||
(
error
=
git_index_find
(
index
,
relfile
))
<
0
)
(
error
=
git_index_find
(
&
pos
,
index
,
relfile
))
<
0
)
return
error
;
return
error
;
entry
=
git_index_get_byindex
(
index
,
error
);
entry
=
git_index_get_byindex
(
index
,
pos
);
if
(
old_oid
&&
git_oid_cmp
(
old_oid
,
&
entry
->
oid
)
==
0
)
if
(
old_oid
&&
git_oid_cmp
(
old_oid
,
&
entry
->
oid
)
==
0
)
return
GIT_ENOTFOUND
;
return
GIT_ENOTFOUND
;
...
...
src/attr_file.c
View file @
11d9f6b3
...
@@ -191,9 +191,9 @@ int git_attr_file__lookup_one(
...
@@ -191,9 +191,9 @@ int git_attr_file__lookup_one(
name
.
name_hash
=
git_attr_file__name_hash
(
attr
);
name
.
name_hash
=
git_attr_file__name_hash
(
attr
);
git_attr_file__foreach_matching_rule
(
file
,
path
,
i
,
rule
)
{
git_attr_file__foreach_matching_rule
(
file
,
path
,
i
,
rule
)
{
int
pos
=
git_vector_bsearch
(
&
rule
->
assigns
,
&
name
)
;
size_t
pos
;
if
(
pos
>=
0
)
{
if
(
!
git_vector_bsearch
(
&
pos
,
&
rule
->
assigns
,
&
name
)
)
{
*
value
=
((
git_attr_assignment
*
)
*
value
=
((
git_attr_assignment
*
)
git_vector_get
(
&
rule
->
assigns
,
pos
))
->
value
;
git_vector_get
(
&
rule
->
assigns
,
pos
))
->
value
;
break
;
break
;
...
@@ -240,14 +240,15 @@ bool git_attr_rule__match(
...
@@ -240,14 +240,15 @@ bool git_attr_rule__match(
git_attr_assignment
*
git_attr_rule__lookup_assignment
(
git_attr_assignment
*
git_attr_rule__lookup_assignment
(
git_attr_rule
*
rule
,
const
char
*
name
)
git_attr_rule
*
rule
,
const
char
*
name
)
{
{
in
t
pos
;
size_
t
pos
;
git_attr_name
key
;
git_attr_name
key
;
key
.
name
=
name
;
key
.
name
=
name
;
key
.
name_hash
=
git_attr_file__name_hash
(
name
);
key
.
name_hash
=
git_attr_file__name_hash
(
name
);
pos
=
git_vector_bsearch
(
&
rule
->
assigns
,
&
key
);
if
(
git_vector_bsearch
(
&
pos
,
&
rule
->
assigns
,
&
key
))
return
NULL
;
return
(
pos
>=
0
)
?
git_vector_get
(
&
rule
->
assigns
,
pos
)
:
NULL
;
return
git_vector_get
(
&
rule
->
assigns
,
pos
)
;
}
}
int
git_attr_path__init
(
int
git_attr_path__init
(
...
...
src/commit.c
View file @
11d9f6b3
...
@@ -137,7 +137,8 @@ int git_commit__parse_buffer(git_commit *commit, const void *data, size_t len)
...
@@ -137,7 +137,8 @@ int git_commit__parse_buffer(git_commit *commit, const void *data, size_t len)
const
char
*
buffer_end
=
(
const
char
*
)
data
+
len
;
const
char
*
buffer_end
=
(
const
char
*
)
data
+
len
;
git_oid
parent_id
;
git_oid
parent_id
;
git_vector_init
(
&
commit
->
parent_ids
,
4
,
NULL
);
if
(
git_vector_init
(
&
commit
->
parent_ids
,
4
,
NULL
)
<
0
)
return
-
1
;
if
(
git_oid__parse
(
&
commit
->
tree_id
,
&
buffer
,
buffer_end
,
"tree "
)
<
0
)
if
(
git_oid__parse
(
&
commit
->
tree_id
,
&
buffer
,
buffer_end
,
"tree "
)
<
0
)
goto
bad_buffer
;
goto
bad_buffer
;
...
...
src/diff_tform.c
View file @
11d9f6b3
...
@@ -250,22 +250,21 @@ static int apply_splits_and_deletes(git_diff_list *diff, size_t expected_size)
...
@@ -250,22 +250,21 @@ static int apply_splits_and_deletes(git_diff_list *diff, size_t expected_size)
/* build new delta list without TO_DELETE and splitting TO_SPLIT */
/* build new delta list without TO_DELETE and splitting TO_SPLIT */
git_vector_foreach
(
&
diff
->
deltas
,
i
,
delta
)
{
git_vector_foreach
(
&
diff
->
deltas
,
i
,
delta
)
{
if
(
delta
->
status
==
GIT_DELTA__TO_DELETE
)
{
if
(
delta
->
status
==
GIT_DELTA__TO_DELETE
)
git__free
(
delta
);
continue
;
continue
;
}
if
(
delta
->
status
==
GIT_DELTA__TO_SPLIT
)
{
if
(
delta
->
status
==
GIT_DELTA__TO_SPLIT
)
{
git_diff_delta
*
deleted
=
diff_delta__dup
(
delta
,
&
diff
->
pool
);
git_diff_delta
*
deleted
=
diff_delta__dup
(
delta
,
&
diff
->
pool
);
if
(
!
deleted
)
if
(
!
deleted
)
return
-
1
;
goto
on_error
;
deleted
->
status
=
GIT_DELTA_DELETED
;
deleted
->
status
=
GIT_DELTA_DELETED
;
memset
(
&
deleted
->
new_file
,
0
,
sizeof
(
deleted
->
new_file
));
memset
(
&
deleted
->
new_file
,
0
,
sizeof
(
deleted
->
new_file
));
deleted
->
new_file
.
path
=
deleted
->
old_file
.
path
;
deleted
->
new_file
.
path
=
deleted
->
old_file
.
path
;
deleted
->
new_file
.
flags
|=
GIT_DIFF_FILE_VALID_OID
;
deleted
->
new_file
.
flags
|=
GIT_DIFF_FILE_VALID_OID
;
git_vector_insert
(
&
onto
,
deleted
);
if
(
git_vector_insert
(
&
onto
,
deleted
)
<
0
)
goto
on_error
;
delta
->
status
=
GIT_DELTA_ADDED
;
delta
->
status
=
GIT_DELTA_ADDED
;
memset
(
&
delta
->
old_file
,
0
,
sizeof
(
delta
->
old_file
));
memset
(
&
delta
->
old_file
,
0
,
sizeof
(
delta
->
old_file
));
...
@@ -273,15 +272,29 @@ static int apply_splits_and_deletes(git_diff_list *diff, size_t expected_size)
...
@@ -273,15 +272,29 @@ static int apply_splits_and_deletes(git_diff_list *diff, size_t expected_size)
delta
->
old_file
.
flags
|=
GIT_DIFF_FILE_VALID_OID
;
delta
->
old_file
.
flags
|=
GIT_DIFF_FILE_VALID_OID
;
}
}
git_vector_insert
(
&
onto
,
delta
);
if
(
git_vector_insert
(
&
onto
,
delta
)
<
0
)
goto
on_error
;
}
}
/* cannot return an error past this point */
git_vector_foreach
(
&
diff
->
deltas
,
i
,
delta
)
if
(
delta
->
status
==
GIT_DELTA__TO_DELETE
)
git__free
(
delta
);
/* swap new delta list into place */
/* swap new delta list into place */
git_vector_sort
(
&
onto
);
git_vector_sort
(
&
onto
);
git_vector_swap
(
&
diff
->
deltas
,
&
onto
);
git_vector_swap
(
&
diff
->
deltas
,
&
onto
);
git_vector_free
(
&
onto
);
git_vector_free
(
&
onto
);
return
0
;
return
0
;
on_error:
git_vector_foreach
(
&
onto
,
i
,
delta
)
git__free
(
delta
);
git_vector_free
(
&
onto
);
return
-
1
;
}
}
static
unsigned
int
calc_similarity
(
static
unsigned
int
calc_similarity
(
...
...
src/index.c
View file @
11d9f6b3
...
@@ -97,7 +97,7 @@ static int parse_index(git_index *index, const char *buffer, size_t buffer_size)
...
@@ -97,7 +97,7 @@ static int parse_index(git_index *index, const char *buffer, size_t buffer_size)
static
bool
is_index_extended
(
git_index
*
index
);
static
bool
is_index_extended
(
git_index
*
index
);
static
int
write_index
(
git_index
*
index
,
git_filebuf
*
file
);
static
int
write_index
(
git_index
*
index
,
git_filebuf
*
file
);
static
int
index_find
(
git_index
*
index
,
const
char
*
path
,
int
stage
);
static
int
index_find
(
size_t
*
at_pos
,
git_index
*
index
,
const
char
*
path
,
int
stage
);
static
void
index_entry_free
(
git_index_entry
*
entry
);
static
void
index_entry_free
(
git_index_entry
*
entry
);
static
void
index_entry_reuc_free
(
git_index_reuc_entry
*
reuc
);
static
void
index_entry_reuc_free
(
git_index_reuc_entry
*
reuc
);
...
@@ -504,13 +504,13 @@ const git_index_entry *git_index_get_byindex(
...
@@ -504,13 +504,13 @@ const git_index_entry *git_index_get_byindex(
const
git_index_entry
*
git_index_get_bypath
(
const
git_index_entry
*
git_index_get_bypath
(
git_index
*
index
,
const
char
*
path
,
int
stage
)
git_index
*
index
,
const
char
*
path
,
int
stage
)
{
{
in
t
pos
;
size_
t
pos
;
assert
(
index
);
assert
(
index
);
git_vector_sort
(
&
index
->
entries
);
git_vector_sort
(
&
index
->
entries
);
if
((
pos
=
index_find
(
index
,
path
,
stage
)
)
<
0
)
if
(
index_find
(
&
pos
,
index
,
path
,
stage
)
<
0
)
return
NULL
;
return
NULL
;
return
git_index_get_byindex
(
index
,
pos
);
return
git_index_get_byindex
(
index
,
pos
);
...
@@ -665,8 +665,7 @@ static void index_entry_free(git_index_entry *entry)
...
@@ -665,8 +665,7 @@ static void index_entry_free(git_index_entry *entry)
static
int
index_insert
(
git_index
*
index
,
git_index_entry
*
entry
,
int
replace
)
static
int
index_insert
(
git_index
*
index
,
git_index_entry
*
entry
,
int
replace
)
{
{
size_t
path_length
;
size_t
path_length
,
position
;
int
position
;
git_index_entry
**
existing
=
NULL
;
git_index_entry
**
existing
=
NULL
;
assert
(
index
&&
entry
&&
entry
->
path
!=
NULL
);
assert
(
index
&&
entry
&&
entry
->
path
!=
NULL
);
...
@@ -682,7 +681,7 @@ static int index_insert(git_index *index, git_index_entry *entry, int replace)
...
@@ -682,7 +681,7 @@ static int index_insert(git_index *index, git_index_entry *entry, int replace)
entry
->
flags
|=
GIT_IDXENTRY_NAMEMASK
;
entry
->
flags
|=
GIT_IDXENTRY_NAMEMASK
;
/* look if an entry with this path already exists */
/* look if an entry with this path already exists */
if
(
(
position
=
index_find
(
index
,
entry
->
path
,
index_entry_stage
(
entry
)))
>=
0
)
{
if
(
!
index_find
(
&
position
,
index
,
entry
->
path
,
index_entry_stage
(
entry
))
)
{
existing
=
(
git_index_entry
**
)
&
index
->
entries
.
contents
[
position
];
existing
=
(
git_index_entry
**
)
&
index
->
entries
.
contents
[
position
];
/* update filemode to existing values if stat is not trusted */
/* update filemode to existing values if stat is not trusted */
...
@@ -787,14 +786,14 @@ int git_index_add(git_index *index, const git_index_entry *source_entry)
...
@@ -787,14 +786,14 @@ int git_index_add(git_index *index, const git_index_entry *source_entry)
int
git_index_remove
(
git_index
*
index
,
const
char
*
path
,
int
stage
)
int
git_index_remove
(
git_index
*
index
,
const
char
*
path
,
int
stage
)
{
{
in
t
position
;
size_
t
position
;
int
error
;
int
error
;
git_index_entry
*
entry
;
git_index_entry
*
entry
;
git_vector_sort
(
&
index
->
entries
);
git_vector_sort
(
&
index
->
entries
);
if
(
(
position
=
index_find
(
index
,
path
,
stage
)
)
<
0
)
if
(
index_find
(
&
position
,
index
,
path
,
stage
)
<
0
)
return
position
;
return
GIT_ENOTFOUND
;
entry
=
git_vector_get
(
&
index
->
entries
,
position
);
entry
=
git_vector_get
(
&
index
->
entries
,
position
);
if
(
entry
!=
NULL
)
if
(
entry
!=
NULL
)
...
@@ -846,7 +845,7 @@ int git_index_remove_directory(git_index *index, const char *dir, int stage)
...
@@ -846,7 +845,7 @@ int git_index_remove_directory(git_index *index, const char *dir, int stage)
return
error
;
return
error
;
}
}
static
int
index_find
(
git_index
*
index
,
const
char
*
path
,
int
stage
)
static
int
index_find
(
size_t
*
at_pos
,
git_index
*
index
,
const
char
*
path
,
int
stage
)
{
{
struct
entry_srch_key
srch_key
;
struct
entry_srch_key
srch_key
;
...
@@ -855,20 +854,18 @@ static int index_find(git_index *index, const char *path, int stage)
...
@@ -855,20 +854,18 @@ static int index_find(git_index *index, const char *path, int stage)
srch_key
.
path
=
path
;
srch_key
.
path
=
path
;
srch_key
.
stage
=
stage
;
srch_key
.
stage
=
stage
;
return
git_vector_bsearch2
(
&
index
->
entries
,
index
->
entries_search
,
&
srch_key
);
return
git_vector_bsearch2
(
at_pos
,
&
index
->
entries
,
index
->
entries_search
,
&
srch_key
);
}
}
int
git_index_find
(
git_index
*
index
,
const
char
*
path
)
int
git_index_find
(
size_t
*
at_pos
,
git_index
*
index
,
const
char
*
path
)
{
{
in
t
pos
;
size_
t
pos
;
assert
(
index
&&
path
);
assert
(
index
&&
path
);
if
((
pos
=
git_vector_bsearch2
(
if
(
git_vector_bsearch2
(
&
pos
,
&
index
->
entries
,
index
->
entries_search_path
,
path
)
<
0
)
{
&
index
->
entries
,
index
->
entries_search_path
,
path
))
<
0
)
{
giterr_set
(
GITERR_INDEX
,
"Index does not contain %s"
,
path
);
giterr_set
(
GITERR_INDEX
,
"Index does not contain %s"
,
path
);
return
pos
;
return
GIT_ENOTFOUND
;
}
}
/* Since our binary search only looked at path, we may be in the
/* Since our binary search only looked at path, we may be in the
...
@@ -883,7 +880,10 @@ int git_index_find(git_index *index, const char *path)
...
@@ -883,7 +880,10 @@ int git_index_find(git_index *index, const char *path)
--
pos
;
--
pos
;
}
}
return
pos
;
if
(
at_pos
)
*
at_pos
=
pos
;
return
0
;
}
}
size_t
git_index__prefix_position
(
git_index
*
index
,
const
char
*
path
)
size_t
git_index__prefix_position
(
git_index
*
index
,
const
char
*
path
)
...
@@ -895,7 +895,7 @@ size_t git_index__prefix_position(git_index *index, const char *path)
...
@@ -895,7 +895,7 @@ size_t git_index__prefix_position(git_index *index, const char *path)
srch_key
.
stage
=
0
;
srch_key
.
stage
=
0
;
git_vector_sort
(
&
index
->
entries
);
git_vector_sort
(
&
index
->
entries
);
git_vector_bsearch
3
(
git_vector_bsearch
2
(
&
pos
,
&
index
->
entries
,
index
->
entries_search
,
&
srch_key
);
&
pos
,
&
index
->
entries
,
index
->
entries_search
,
&
srch_key
);
return
pos
;
return
pos
;
...
@@ -945,7 +945,8 @@ int git_index_conflict_get(git_index_entry **ancestor_out,
...
@@ -945,7 +945,8 @@ int git_index_conflict_get(git_index_entry **ancestor_out,
git_index_entry
**
their_out
,
git_index_entry
**
their_out
,
git_index
*
index
,
const
char
*
path
)
git_index
*
index
,
const
char
*
path
)
{
{
int
pos
,
posmax
,
stage
;
size_t
pos
,
posmax
;
int
stage
;
git_index_entry
*
conflict_entry
;
git_index_entry
*
conflict_entry
;
int
error
=
GIT_ENOTFOUND
;
int
error
=
GIT_ENOTFOUND
;
...
@@ -955,10 +956,10 @@ int git_index_conflict_get(git_index_entry **ancestor_out,
...
@@ -955,10 +956,10 @@ int git_index_conflict_get(git_index_entry **ancestor_out,
*
our_out
=
NULL
;
*
our_out
=
NULL
;
*
their_out
=
NULL
;
*
their_out
=
NULL
;
if
(
(
pos
=
git_index_find
(
index
,
path
)
)
<
0
)
if
(
git_index_find
(
&
pos
,
index
,
path
)
<
0
)
return
pos
;
return
GIT_ENOTFOUND
;
for
(
posmax
=
(
int
)
git_index_entrycount
(
index
);
pos
<
posmax
;
++
pos
)
{
for
(
posmax
=
git_index_entrycount
(
index
);
pos
<
posmax
;
++
pos
)
{
conflict_entry
=
git_vector_get
(
&
index
->
entries
,
pos
);
conflict_entry
=
git_vector_get
(
&
index
->
entries
,
pos
);
...
@@ -990,16 +991,16 @@ int git_index_conflict_get(git_index_entry **ancestor_out,
...
@@ -990,16 +991,16 @@ int git_index_conflict_get(git_index_entry **ancestor_out,
int
git_index_conflict_remove
(
git_index
*
index
,
const
char
*
path
)
int
git_index_conflict_remove
(
git_index
*
index
,
const
char
*
path
)
{
{
in
t
pos
,
posmax
;
size_
t
pos
,
posmax
;
git_index_entry
*
conflict_entry
;
git_index_entry
*
conflict_entry
;
int
error
=
0
;
int
error
=
0
;
assert
(
index
&&
path
);
assert
(
index
&&
path
);
if
(
(
pos
=
git_index_find
(
index
,
path
)
)
<
0
)
if
(
git_index_find
(
&
pos
,
index
,
path
)
<
0
)
return
pos
;
return
GIT_ENOTFOUND
;
posmax
=
(
int
)
git_index_entrycount
(
index
);
posmax
=
git_index_entrycount
(
index
);
while
(
pos
<
posmax
)
{
while
(
pos
<
posmax
)
{
conflict_entry
=
git_vector_get
(
&
index
->
entries
,
pos
);
conflict_entry
=
git_vector_get
(
&
index
->
entries
,
pos
);
...
@@ -1012,7 +1013,7 @@ int git_index_conflict_remove(git_index *index, const char *path)
...
@@ -1012,7 +1013,7 @@ int git_index_conflict_remove(git_index *index, const char *path)
continue
;
continue
;
}
}
if
((
error
=
git_vector_remove
(
&
index
->
entries
,
(
unsigned
int
)
pos
))
<
0
)
if
((
error
=
git_vector_remove
(
&
index
->
entries
,
pos
))
<
0
)
return
error
;
return
error
;
index_entry_free
(
conflict_entry
);
index_entry_free
(
conflict_entry
);
...
@@ -1064,11 +1065,11 @@ unsigned int git_index_reuc_entrycount(git_index *index)
...
@@ -1064,11 +1065,11 @@ unsigned int git_index_reuc_entrycount(git_index *index)
static
int
index_reuc_insert
(
git_index
*
index
,
git_index_reuc_entry
*
reuc
,
int
replace
)
static
int
index_reuc_insert
(
git_index
*
index
,
git_index_reuc_entry
*
reuc
,
int
replace
)
{
{
git_index_reuc_entry
**
existing
=
NULL
;
git_index_reuc_entry
**
existing
=
NULL
;
in
t
position
;
size_
t
position
;
assert
(
index
&&
reuc
&&
reuc
->
path
!=
NULL
);
assert
(
index
&&
reuc
&&
reuc
->
path
!=
NULL
);
if
(
(
position
=
git_index_reuc_find
(
index
,
reuc
->
path
))
>=
0
)
if
(
!
git_index_reuc_find
(
&
position
,
index
,
reuc
->
path
)
)
existing
=
(
git_index_reuc_entry
**
)
&
index
->
reuc
.
contents
[
position
];
existing
=
(
git_index_reuc_entry
**
)
&
index
->
reuc
.
contents
[
position
];
if
(
!
replace
||
!
existing
)
if
(
!
replace
||
!
existing
)
...
@@ -1102,15 +1103,15 @@ int git_index_reuc_add(git_index *index, const char *path,
...
@@ -1102,15 +1103,15 @@ int git_index_reuc_add(git_index *index, const char *path,
return
error
;
return
error
;
}
}
int
git_index_reuc_find
(
git_index
*
index
,
const
char
*
path
)
int
git_index_reuc_find
(
size_t
*
at_pos
,
git_index
*
index
,
const
char
*
path
)
{
{
return
git_vector_bsearch2
(
&
index
->
reuc
,
index
->
reuc_search
,
path
);
return
git_vector_bsearch2
(
at_pos
,
&
index
->
reuc
,
index
->
reuc_search
,
path
);
}
}
const
git_index_reuc_entry
*
git_index_reuc_get_bypath
(
const
git_index_reuc_entry
*
git_index_reuc_get_bypath
(
git_index
*
index
,
const
char
*
path
)
git_index
*
index
,
const
char
*
path
)
{
{
in
t
pos
;
size_
t
pos
;
assert
(
index
&&
path
);
assert
(
index
&&
path
);
if
(
!
index
->
reuc
.
length
)
if
(
!
index
->
reuc
.
length
)
...
@@ -1118,7 +1119,7 @@ const git_index_reuc_entry *git_index_reuc_get_bypath(
...
@@ -1118,7 +1119,7 @@ const git_index_reuc_entry *git_index_reuc_get_bypath(
git_vector_sort
(
&
index
->
reuc
);
git_vector_sort
(
&
index
->
reuc
);
if
(
(
pos
=
git_index_reuc_find
(
index
,
path
)
)
<
0
)
if
(
git_index_reuc_find
(
&
pos
,
index
,
path
)
<
0
)
return
NULL
;
return
NULL
;
return
git_vector_get
(
&
index
->
reuc
,
pos
);
return
git_vector_get
(
&
index
->
reuc
,
pos
);
...
...
src/iterator.c
View file @
11d9f6b3
...
@@ -689,7 +689,7 @@ static void workdir_iterator__seek_frame_start(
...
@@ -689,7 +689,7 @@ static void workdir_iterator__seek_frame_start(
return
;
return
;
if
(
wi
->
base
.
start
)
if
(
wi
->
base
.
start
)
git_vector_bsearch
3
(
git_vector_bsearch
2
(
&
wf
->
index
,
&
wf
->
entries
,
wi
->
entrycmp
,
wi
->
base
.
start
);
&
wf
->
index
,
&
wf
->
entries
,
wi
->
entrycmp
,
wi
->
base
.
start
);
else
else
wf
->
index
=
0
;
wf
->
index
=
0
;
...
...
src/pack.c
View file @
11d9f6b3
...
@@ -760,12 +760,11 @@ git_off_t get_delta_base(
...
@@ -760,12 +760,11 @@ git_off_t get_delta_base(
}
else
if
(
type
==
GIT_OBJ_REF_DELTA
)
{
}
else
if
(
type
==
GIT_OBJ_REF_DELTA
)
{
/* If we have the cooperative cache, search in it first */
/* If we have the cooperative cache, search in it first */
if
(
p
->
has_cache
)
{
if
(
p
->
has_cache
)
{
in
t
pos
;
size_
t
pos
;
struct
git_pack_entry
key
;
struct
git_pack_entry
key
;
git_oid_fromraw
(
&
key
.
sha1
,
base_info
);
git_oid_fromraw
(
&
key
.
sha1
,
base_info
);
pos
=
git_vector_bsearch
(
&
p
->
cache
,
&
key
);
if
(
!
git_vector_bsearch
(
&
pos
,
&
p
->
cache
,
&
key
))
{
if
(
pos
>=
0
)
{
*
curpos
+=
20
;
*
curpos
+=
20
;
return
((
struct
git_pack_entry
*
)
git_vector_get
(
&
p
->
cache
,
pos
))
->
offset
;
return
((
struct
git_pack_entry
*
)
git_vector_get
(
&
p
->
cache
,
pos
))
->
offset
;
}
}
...
...
src/remote.c
View file @
11d9f6b3
...
@@ -681,9 +681,8 @@ int git_remote_download(
...
@@ -681,9 +681,8 @@ int git_remote_download(
static
int
update_tips_callback
(
git_remote_head
*
head
,
void
*
payload
)
static
int
update_tips_callback
(
git_remote_head
*
head
,
void
*
payload
)
{
{
git_vector
*
refs
=
(
git_vector
*
)
payload
;
git_vector
*
refs
=
(
git_vector
*
)
payload
;
git_vector_insert
(
refs
,
head
);
return
0
;
return
git_vector_insert
(
refs
,
head
)
;
}
}
static
int
remote_head_for_fetchspec_src
(
git_remote_head
**
out
,
git_vector
*
update_heads
,
const
char
*
fetchspec_src
)
static
int
remote_head_for_fetchspec_src
(
git_remote_head
**
out
,
git_vector
*
update_heads
,
const
char
*
fetchspec_src
)
...
...
src/stash.c
View file @
11d9f6b3
...
@@ -192,7 +192,7 @@ static int update_index_cb(
...
@@ -192,7 +192,7 @@ static int update_index_cb(
case
GIT_DELTA_DELETED
:
case
GIT_DELTA_DELETED
:
if
(
!
data
->
include_changed
)
if
(
!
data
->
include_changed
)
break
;
break
;
if
(
git_index_find
(
data
->
index
,
delta
->
old_file
.
path
)
==
0
)
if
(
git_index_find
(
NULL
,
data
->
index
,
delta
->
old_file
.
path
)
==
0
)
data
->
error
=
git_index_remove
(
data
->
error
=
git_index_remove
(
data
->
index
,
delta
->
old_file
.
path
,
0
);
data
->
index
,
delta
->
old_file
.
path
,
0
);
break
;
break
;
...
...
src/submodule.c
View file @
11d9f6b3
...
@@ -157,7 +157,7 @@ int git_submodule_foreach(
...
@@ -157,7 +157,7 @@ int git_submodule_foreach(
* and path are not the same.
* and path are not the same.
*/
*/
if
(
sm
->
refcount
>
1
)
{
if
(
sm
->
refcount
>
1
)
{
if
(
git_vector_bsearch
(
&
seen
,
sm
)
!=
GIT_ENOTFOUND
)
if
(
git_vector_bsearch
(
NULL
,
&
seen
,
sm
)
!=
GIT_ENOTFOUND
)
continue
;
continue
;
if
((
error
=
git_vector_insert
(
&
seen
,
sm
))
<
0
)
if
((
error
=
git_vector_insert
(
&
seen
,
sm
))
<
0
)
break
;
break
;
...
@@ -716,7 +716,8 @@ int git_submodule_reload(git_submodule *submodule)
...
@@ -716,7 +716,8 @@ int git_submodule_reload(git_submodule *submodule)
{
{
git_repository
*
repo
;
git_repository
*
repo
;
git_index
*
index
;
git_index
*
index
;
int
pos
,
error
;
int
error
;
size_t
pos
;
git_tree
*
head
;
git_tree
*
head
;
git_config_backend
*
mods
;
git_config_backend
*
mods
;
...
@@ -732,8 +733,7 @@ int git_submodule_reload(git_submodule *submodule)
...
@@ -732,8 +733,7 @@ int git_submodule_reload(git_submodule *submodule)
~
(
GIT_SUBMODULE_STATUS_IN_INDEX
|
~
(
GIT_SUBMODULE_STATUS_IN_INDEX
|
GIT_SUBMODULE_STATUS__INDEX_OID_VALID
);
GIT_SUBMODULE_STATUS__INDEX_OID_VALID
);
pos
=
git_index_find
(
index
,
submodule
->
path
);
if
(
!
git_index_find
(
&
pos
,
index
,
submodule
->
path
))
{
if
(
pos
>=
0
)
{
const
git_index_entry
*
entry
=
git_index_get_byindex
(
index
,
pos
);
const
git_index_entry
*
entry
=
git_index_get_byindex
(
index
,
pos
);
if
(
S_ISGITLINK
(
entry
->
mode
))
{
if
(
S_ISGITLINK
(
entry
->
mode
))
{
...
...
src/tree.c
View file @
11d9f6b3
...
@@ -132,45 +132,56 @@ static int homing_search_cmp(const void *key, const void *array_member)
...
@@ -132,45 +132,56 @@ static int homing_search_cmp(const void *key, const void *array_member)
* around the area for our target file.
* around the area for our target file.
*/
*/
static
int
tree_key_search
(
static
int
tree_key_search
(
git_vector
*
entries
,
const
char
*
filename
,
size_t
filename_len
)
size_t
*
at_pos
,
git_vector
*
entries
,
const
char
*
filename
,
size_t
filename_len
)
{
{
struct
tree_key_search
ksearch
;
struct
tree_key_search
ksearch
;
const
git_tree_entry
*
entry
;
const
git_tree_entry
*
entry
;
in
t
homing
,
i
;
size_
t
homing
,
i
;
ksearch
.
filename
=
filename
;
ksearch
.
filename
=
filename
;
ksearch
.
filename_len
=
filename_len
;
ksearch
.
filename_len
=
filename_len
;
/* Initial homing search; find an entry on the tree with
/* Initial homing search; find an entry on the tree with
* the same prefix as the filename we're looking for */
* the same prefix as the filename we're looking for */
homing
=
git_vector_bsearch2
(
entries
,
&
homing_search_cmp
,
&
ksearch
);
if
(
git_vector_bsearch2
(
&
homing
,
entries
,
&
homing_search_cmp
,
&
ksearch
)
<
0
)
if
(
homing
<
0
)
return
GIT_ENOTFOUND
;
return
homing
;
/* We found a common prefix. Look forward as long as
/* We found a common prefix. Look forward as long as
* there are entries that share the common prefix */
* there are entries that share the common prefix */
for
(
i
=
homing
;
i
<
(
int
)
entries
->
length
;
++
i
)
{
for
(
i
=
homing
;
i
<
entries
->
length
;
++
i
)
{
entry
=
entries
->
contents
[
i
];
entry
=
entries
->
contents
[
i
];
if
(
homing_search_cmp
(
&
ksearch
,
entry
)
<
0
)
if
(
homing_search_cmp
(
&
ksearch
,
entry
)
<
0
)
break
;
break
;
if
(
entry
->
filename_len
==
filename_len
&&
if
(
entry
->
filename_len
==
filename_len
&&
memcmp
(
filename
,
entry
->
filename
,
filename_len
)
==
0
)
memcmp
(
filename
,
entry
->
filename
,
filename_len
)
==
0
)
{
return
i
;
if
(
at_pos
)
*
at_pos
=
i
;
return
0
;
}
}
}
/* If we haven't found our filename yet, look backwards
/* If we haven't found our filename yet, look backwards
* too as long as we have entries with the same prefix */
* too as long as we have entries with the same prefix */
for
(
i
=
homing
-
1
;
i
>=
0
;
--
i
)
{
if
(
homing
>
0
)
{
i
=
homing
-
1
;
do
{
entry
=
entries
->
contents
[
i
];
entry
=
entries
->
contents
[
i
];
if
(
homing_search_cmp
(
&
ksearch
,
entry
)
>
0
)
if
(
homing_search_cmp
(
&
ksearch
,
entry
)
>
0
)
break
;
break
;
if
(
entry
->
filename_len
==
filename_len
&&
if
(
entry
->
filename_len
==
filename_len
&&
memcmp
(
filename
,
entry
->
filename
,
filename_len
)
==
0
)
memcmp
(
filename
,
entry
->
filename
,
filename_len
)
==
0
)
{
return
i
;
if
(
at_pos
)
*
at_pos
=
i
;
return
0
;
}
}
while
(
i
--
>
0
);
}
}
/* The filename doesn't exist at all */
/* The filename doesn't exist at all */
...
@@ -267,8 +278,9 @@ int git_tree_entry_to_object(
...
@@ -267,8 +278,9 @@ int git_tree_entry_to_object(
static
const
git_tree_entry
*
entry_fromname
(
static
const
git_tree_entry
*
entry_fromname
(
git_tree
*
tree
,
const
char
*
name
,
size_t
name_len
)
git_tree
*
tree
,
const
char
*
name
,
size_t
name_len
)
{
{
int
idx
=
tree_key_search
(
&
tree
->
entries
,
name
,
name_len
);
size_t
idx
;
if
(
idx
<
0
)
if
(
tree_key_search
(
&
idx
,
&
tree
->
entries
,
name
,
name_len
)
<
0
)
return
NULL
;
return
NULL
;
return
git_vector_get
(
&
tree
->
entries
,
idx
);
return
git_vector_get
(
&
tree
->
entries
,
idx
);
...
@@ -317,7 +329,7 @@ int git_tree__prefix_position(git_tree *tree, const char *path)
...
@@ -317,7 +329,7 @@ int git_tree__prefix_position(git_tree *tree, const char *path)
ksearch
.
filename_len
=
strlen
(
path
);
ksearch
.
filename_len
=
strlen
(
path
);
/* Find tree entry with appropriate prefix */
/* Find tree entry with appropriate prefix */
git_vector_bsearch
3
(
&
at_pos
,
entries
,
&
homing_search_cmp
,
&
ksearch
);
git_vector_bsearch
2
(
&
at_pos
,
entries
,
&
homing_search_cmp
,
&
ksearch
);
for
(;
at_pos
<
entries
->
length
;
++
at_pos
)
{
for
(;
at_pos
<
entries
->
length
;
++
at_pos
)
{
const
git_tree_entry
*
entry
=
entries
->
contents
[
at_pos
];
const
git_tree_entry
*
entry
=
entries
->
contents
[
at_pos
];
...
@@ -612,7 +624,7 @@ int git_treebuilder_insert(
...
@@ -612,7 +624,7 @@ int git_treebuilder_insert(
git_filemode_t
filemode
)
git_filemode_t
filemode
)
{
{
git_tree_entry
*
entry
;
git_tree_entry
*
entry
;
in
t
pos
;
size_
t
pos
;
assert
(
bld
&&
id
&&
filename
);
assert
(
bld
&&
id
&&
filename
);
...
@@ -622,41 +634,35 @@ int git_treebuilder_insert(
...
@@ -622,41 +634,35 @@ int git_treebuilder_insert(
if
(
!
valid_entry_name
(
filename
))
if
(
!
valid_entry_name
(
filename
))
return
tree_error
(
"Failed to insert entry. Invalid name for a tree entry"
,
filename
);
return
tree_error
(
"Failed to insert entry. Invalid name for a tree entry"
,
filename
);
pos
=
tree_key_search
(
&
bld
->
entries
,
filename
,
strlen
(
filename
));
if
(
!
tree_key_search
(
&
pos
,
&
bld
->
entries
,
filename
,
strlen
(
filename
)))
{
if
(
pos
>=
0
)
{
entry
=
git_vector_get
(
&
bld
->
entries
,
pos
);
entry
=
git_vector_get
(
&
bld
->
entries
,
pos
);
if
(
entry
->
removed
)
if
(
entry
->
removed
)
entry
->
removed
=
0
;
entry
->
removed
=
0
;
}
else
{
}
else
{
entry
=
alloc_entry
(
filename
);
entry
=
alloc_entry
(
filename
);
GITERR_CHECK_ALLOC
(
entry
);
GITERR_CHECK_ALLOC
(
entry
);
}
git_oid_cpy
(
&
entry
->
oid
,
id
);
entry
->
attr
=
filemode
;
if
(
pos
<
0
)
{
if
(
git_vector_insert
(
&
bld
->
entries
,
entry
)
<
0
)
if
(
git_vector_insert
(
&
bld
->
entries
,
entry
)
<
0
)
return
-
1
;
return
-
1
;
}
}
if
(
entry_out
!=
NULL
)
{
git_oid_cpy
(
&
entry
->
oid
,
id
);
entry
->
attr
=
filemode
;
if
(
entry_out
)
*
entry_out
=
entry
;
*
entry_out
=
entry
;
}
return
0
;
return
0
;
}
}
static
git_tree_entry
*
treebuilder_get
(
git_treebuilder
*
bld
,
const
char
*
filename
)
static
git_tree_entry
*
treebuilder_get
(
git_treebuilder
*
bld
,
const
char
*
filename
)
{
{
in
t
idx
;
size_
t
idx
;
git_tree_entry
*
entry
;
git_tree_entry
*
entry
;
assert
(
bld
&&
filename
);
assert
(
bld
&&
filename
);
idx
=
tree_key_search
(
&
bld
->
entries
,
filename
,
strlen
(
filename
));
if
(
tree_key_search
(
&
idx
,
&
bld
->
entries
,
filename
,
strlen
(
filename
))
<
0
)
if
(
idx
<
0
)
return
NULL
;
return
NULL
;
entry
=
git_vector_get
(
&
bld
->
entries
,
idx
);
entry
=
git_vector_get
(
&
bld
->
entries
,
idx
);
...
...
src/util.c
View file @
11d9f6b3
...
@@ -501,11 +501,11 @@ int git__bsearch(
...
@@ -501,11 +501,11 @@ int git__bsearch(
int
(
*
compare
)(
const
void
*
,
const
void
*
),
int
(
*
compare
)(
const
void
*
,
const
void
*
),
size_t
*
position
)
size_t
*
position
)
{
{
unsigned
in
t
lim
;
size_
t
lim
;
int
cmp
=
-
1
;
int
cmp
=
-
1
;
void
**
part
,
**
base
=
array
;
void
**
part
,
**
base
=
array
;
for
(
lim
=
(
unsigned
int
)
array_len
;
lim
!=
0
;
lim
>>=
1
)
{
for
(
lim
=
array_len
;
lim
!=
0
;
lim
>>=
1
)
{
part
=
base
+
(
lim
>>
1
);
part
=
base
+
(
lim
>>
1
);
cmp
=
(
*
compare
)(
key
,
*
part
);
cmp
=
(
*
compare
)(
key
,
*
part
);
if
(
cmp
==
0
)
{
if
(
cmp
==
0
)
{
...
@@ -521,7 +521,7 @@ int git__bsearch(
...
@@ -521,7 +521,7 @@ int git__bsearch(
if
(
position
)
if
(
position
)
*
position
=
(
base
-
array
);
*
position
=
(
base
-
array
);
return
(
cmp
==
0
)
?
0
:
-
1
;
return
(
cmp
==
0
)
?
0
:
GIT_ENOTFOUND
;
}
}
int
git__bsearch_r
(
int
git__bsearch_r
(
...
@@ -532,11 +532,11 @@ int git__bsearch_r(
...
@@ -532,11 +532,11 @@ int git__bsearch_r(
void
*
payload
,
void
*
payload
,
size_t
*
position
)
size_t
*
position
)
{
{
unsigned
in
t
lim
;
size_
t
lim
;
int
cmp
=
-
1
;
int
cmp
=
-
1
;
void
**
part
,
**
base
=
array
;
void
**
part
,
**
base
=
array
;
for
(
lim
=
(
unsigned
int
)
array_len
;
lim
!=
0
;
lim
>>=
1
)
{
for
(
lim
=
array_len
;
lim
!=
0
;
lim
>>=
1
)
{
part
=
base
+
(
lim
>>
1
);
part
=
base
+
(
lim
>>
1
);
cmp
=
(
*
compare_r
)(
key
,
*
part
,
payload
);
cmp
=
(
*
compare_r
)(
key
,
*
part
,
payload
);
if
(
cmp
==
0
)
{
if
(
cmp
==
0
)
{
...
@@ -552,7 +552,7 @@ int git__bsearch_r(
...
@@ -552,7 +552,7 @@ int git__bsearch_r(
if
(
position
)
if
(
position
)
*
position
=
(
base
-
array
);
*
position
=
(
base
-
array
);
return
(
cmp
==
0
)
?
0
:
-
1
;
return
(
cmp
==
0
)
?
0
:
GIT_ENOTFOUND
;
}
}
/**
/**
...
...
src/util.h
View file @
11d9f6b3
...
@@ -13,6 +13,9 @@
...
@@ -13,6 +13,9 @@
#ifndef min
#ifndef min
# define min(a,b) ((a) < (b) ? (a) : (b))
# define min(a,b) ((a) < (b) ? (a) : (b))
#endif
#endif
#ifndef max
# define max(a,b) ((a) > (b) ? (a) : (b))
#endif
/*
/*
* Custom memory allocation wrappers
* Custom memory allocation wrappers
...
@@ -132,7 +135,7 @@ extern void git__tsort_r(
...
@@ -132,7 +135,7 @@ extern void git__tsort_r(
/**
/**
* @param position If non-NULL, this will be set to the position where the
* @param position If non-NULL, this will be set to the position where the
* element is or would be inserted if not found.
* element is or would be inserted if not found.
* @return
pos (>=0) if found or -1
if not found
* @return
0 if found; GIT_ENOTFOUND
if not found
*/
*/
extern
int
git__bsearch
(
extern
int
git__bsearch
(
void
**
array
,
void
**
array
,
...
...
src/vector.c
View file @
11d9f6b3
...
@@ -9,33 +9,59 @@
...
@@ -9,33 +9,59 @@
#include "repository.h"
#include "repository.h"
#include "vector.h"
#include "vector.h"
static
const
double
git_vector_resize_factor
=
1
.
75
;
/* In elements, not bytes */
static
const
size_t
git_vector_minimum_size
=
8
;
#define MIN_ALLOCSIZE 8
static
int
resize_vector
(
git_vector
*
v
)
GIT_INLINE
(
size_t
)
compute_new_size
(
git_vector
*
v
)
{
{
v
->
_alloc_size
=
(
size_t
)(
v
->
_alloc_size
*
git_vector_resize_factor
)
+
1
;
size_t
new_size
=
v
->
_alloc_size
;
if
(
v
->
_alloc_size
<
git_vector_minimum_size
)
v
->
_alloc_size
=
git_vector_minimum_size
;
/* Use a resize factor of 1.5, which is quick to compute using integer
* instructions and less than the golden ratio (1.618...) */
if
(
new_size
<
MIN_ALLOCSIZE
)
new_size
=
MIN_ALLOCSIZE
;
else
if
(
new_size
<=
SIZE_MAX
/
3
)
new_size
=
new_size
*
3
/
2
+
1
;
else
new_size
=
SIZE_MAX
;
v
->
contents
=
git__realloc
(
v
->
contents
,
v
->
_alloc_size
*
sizeof
(
void
*
));
return
new_size
;
GITERR_CHECK_ALLOC
(
v
->
contents
);
}
GIT_INLINE
(
int
)
resize_vector
(
git_vector
*
v
,
size_t
new_size
)
{
size_t
new_bytes
=
new_size
*
sizeof
(
void
*
);
void
*
new_contents
;
/* Check for overflow */
if
(
new_bytes
/
sizeof
(
void
*
)
!=
new_size
)
GITERR_CHECK_ALLOC
(
NULL
);
new_contents
=
git__realloc
(
v
->
contents
,
new_bytes
);
GITERR_CHECK_ALLOC
(
new_contents
);
v
->
_alloc_size
=
new_size
;
v
->
contents
=
new_contents
;
return
0
;
return
0
;
}
}
int
git_vector_dup
(
git_vector
*
v
,
const
git_vector
*
src
,
git_vector_cmp
cmp
)
int
git_vector_dup
(
git_vector
*
v
,
const
git_vector
*
src
,
git_vector_cmp
cmp
)
{
{
size_t
bytes
;
assert
(
v
&&
src
);
assert
(
v
&&
src
);
bytes
=
src
->
length
*
sizeof
(
void
*
);
v
->
_alloc_size
=
src
->
length
;
v
->
_alloc_size
=
src
->
length
;
v
->
_cmp
=
cmp
;
v
->
_cmp
=
cmp
;
v
->
length
=
src
->
length
;
v
->
length
=
src
->
length
;
v
->
sorted
=
src
->
sorted
&&
cmp
==
src
->
_cmp
;
v
->
sorted
=
src
->
sorted
&&
cmp
==
src
->
_cmp
;
v
->
contents
=
git__malloc
(
src
->
length
*
sizeof
(
void
*
)
);
v
->
contents
=
git__malloc
(
bytes
);
GITERR_CHECK_ALLOC
(
v
->
contents
);
GITERR_CHECK_ALLOC
(
v
->
contents
);
memcpy
(
v
->
contents
,
src
->
contents
,
src
->
length
*
sizeof
(
void
*
)
);
memcpy
(
v
->
contents
,
src
->
contents
,
bytes
);
return
0
;
return
0
;
}
}
...
@@ -55,21 +81,13 @@ int git_vector_init(git_vector *v, size_t initial_size, git_vector_cmp cmp)
...
@@ -55,21 +81,13 @@ int git_vector_init(git_vector *v, size_t initial_size, git_vector_cmp cmp)
{
{
assert
(
v
);
assert
(
v
);
memset
(
v
,
0x0
,
sizeof
(
git_vector
));
v
->
_alloc_size
=
0
;
if
(
initial_size
==
0
)
initial_size
=
git_vector_minimum_size
;
v
->
_alloc_size
=
initial_size
;
v
->
_cmp
=
cmp
;
v
->
_cmp
=
cmp
;
v
->
length
=
0
;
v
->
length
=
0
;
v
->
sorted
=
1
;
v
->
sorted
=
1
;
v
->
contents
=
NULL
;
v
->
contents
=
git__malloc
(
v
->
_alloc_size
*
sizeof
(
void
*
));
return
resize_vector
(
v
,
max
(
initial_size
,
MIN_ALLOCSIZE
));
GITERR_CHECK_ALLOC
(
v
->
contents
);
return
0
;
}
}
int
git_vector_insert
(
git_vector
*
v
,
void
*
element
)
int
git_vector_insert
(
git_vector
*
v
,
void
*
element
)
...
@@ -77,7 +95,7 @@ int git_vector_insert(git_vector *v, void *element)
...
@@ -77,7 +95,7 @@ int git_vector_insert(git_vector *v, void *element)
assert
(
v
);
assert
(
v
);
if
(
v
->
length
>=
v
->
_alloc_size
&&
if
(
v
->
length
>=
v
->
_alloc_size
&&
resize_vector
(
v
)
<
0
)
resize_vector
(
v
,
compute_new_size
(
v
)
)
<
0
)
return
-
1
;
return
-
1
;
v
->
contents
[
v
->
length
++
]
=
element
;
v
->
contents
[
v
->
length
++
]
=
element
;
...
@@ -98,26 +116,25 @@ int git_vector_insert_sorted(
...
@@ -98,26 +116,25 @@ int git_vector_insert_sorted(
git_vector_sort
(
v
);
git_vector_sort
(
v
);
if
(
v
->
length
>=
v
->
_alloc_size
&&
if
(
v
->
length
>=
v
->
_alloc_size
&&
resize_vector
(
v
)
<
0
)
resize_vector
(
v
,
compute_new_size
(
v
)
)
<
0
)
return
-
1
;
return
-
1
;
/* If we find the element and have a duplicate handler callback,
/* If we find the element and have a duplicate handler callback,
* invoke it. If it returns non-zero, then cancel insert, otherwise
* invoke it. If it returns non-zero, then cancel insert, otherwise
* proceed with normal insert.
* proceed with normal insert.
*/
*/
if
(
git__bsearch
(
v
->
contents
,
v
->
length
,
element
,
v
->
_cmp
,
&
pos
)
>=
0
&&
if
(
!
git__bsearch
(
v
->
contents
,
v
->
length
,
element
,
v
->
_cmp
,
&
pos
)
&&
on_dup
!=
NULL
&&
on_dup
&&
(
result
=
on_dup
(
&
v
->
contents
[
pos
],
element
))
<
0
)
(
result
=
on_dup
(
&
v
->
contents
[
pos
],
element
))
<
0
)
return
result
;
return
result
;
/* shift elements to the right */
/* shift elements to the right */
if
(
pos
<
v
->
length
)
{
if
(
pos
<
v
->
length
)
memmove
(
v
->
contents
+
pos
+
1
,
v
->
contents
+
pos
,
memmove
(
v
->
contents
+
pos
+
1
,
v
->
contents
+
pos
,
(
v
->
length
-
pos
)
*
sizeof
(
void
*
));
(
v
->
length
-
pos
)
*
sizeof
(
void
*
));
}
v
->
contents
[
pos
]
=
element
;
v
->
contents
[
pos
]
=
element
;
v
->
length
++
;
v
->
length
++
;
return
0
;
return
0
;
}
}
...
@@ -125,47 +142,44 @@ void git_vector_sort(git_vector *v)
...
@@ -125,47 +142,44 @@ void git_vector_sort(git_vector *v)
{
{
assert
(
v
);
assert
(
v
);
if
(
v
->
sorted
||
v
->
_cmp
==
NULL
)
if
(
v
->
sorted
||
!
v
->
_cmp
)
return
;
return
;
git__tsort
(
v
->
contents
,
v
->
length
,
v
->
_cmp
);
git__tsort
(
v
->
contents
,
v
->
length
,
v
->
_cmp
);
v
->
sorted
=
1
;
v
->
sorted
=
1
;
}
}
int
git_vector_bsearch
3
(
int
git_vector_bsearch
2
(
size_t
*
at_pos
,
size_t
*
at_pos
,
git_vector
*
v
,
git_vector
*
v
,
git_vector_cmp
key_lookup
,
git_vector_cmp
key_lookup
,
const
void
*
key
)
const
void
*
key
)
{
{
int
rval
;
size_t
pos
;
assert
(
v
&&
key
&&
key_lookup
);
assert
(
v
&&
key
&&
key_lookup
);
/* need comparison function to sort the vector */
/* need comparison function to sort the vector */
assert
(
v
->
_cmp
!=
NULL
);
if
(
!
v
->
_cmp
)
return
-
1
;
git_vector_sort
(
v
);
git_vector_sort
(
v
);
rval
=
git__bsearch
(
v
->
contents
,
v
->
length
,
key
,
key_lookup
,
&
pos
);
return
git__bsearch
(
v
->
contents
,
v
->
length
,
key
,
key_lookup
,
at_pos
);
if
(
at_pos
!=
NULL
)
*
at_pos
=
pos
;
return
(
rval
>=
0
)
?
(
int
)
pos
:
GIT_ENOTFOUND
;
}
}
int
git_vector_search2
(
int
git_vector_search2
(
const
git_vector
*
v
,
git_vector_cmp
key_lookup
,
const
void
*
key
)
size_t
*
at_pos
,
const
git_vector
*
v
,
git_vector_cmp
key_lookup
,
const
void
*
key
)
{
{
size_t
i
;
size_t
i
;
assert
(
v
&&
key
&&
key_lookup
);
assert
(
v
&&
key
&&
key_lookup
);
for
(
i
=
0
;
i
<
v
->
length
;
++
i
)
{
for
(
i
=
0
;
i
<
v
->
length
;
++
i
)
{
if
(
key_lookup
(
key
,
v
->
contents
[
i
])
==
0
)
if
(
key_lookup
(
key
,
v
->
contents
[
i
])
==
0
)
{
return
(
int
)
i
;
if
(
at_pos
)
*
at_pos
=
i
;
return
0
;
}
}
}
return
GIT_ENOTFOUND
;
return
GIT_ENOTFOUND
;
...
@@ -176,22 +190,25 @@ static int strict_comparison(const void *a, const void *b)
...
@@ -176,22 +190,25 @@ static int strict_comparison(const void *a, const void *b)
return
(
a
==
b
)
?
0
:
-
1
;
return
(
a
==
b
)
?
0
:
-
1
;
}
}
int
git_vector_search
(
const
git_vector
*
v
,
const
void
*
entry
)
int
git_vector_search
(
size_t
*
at_pos
,
const
git_vector
*
v
,
const
void
*
entry
)
{
{
return
git_vector_search2
(
v
,
v
->
_cmp
?
v
->
_cmp
:
strict_comparison
,
entry
);
return
git_vector_search2
(
at_pos
,
v
,
v
->
_cmp
?
v
->
_cmp
:
strict_comparison
,
entry
);
}
}
int
git_vector_remove
(
git_vector
*
v
,
size_t
idx
)
int
git_vector_remove
(
git_vector
*
v
,
size_t
idx
)
{
{
size_t
i
;
size_t
shift_count
;
assert
(
v
);
assert
(
v
);
if
(
idx
>=
v
->
length
||
v
->
length
==
0
)
if
(
idx
>=
v
->
length
)
return
GIT_ENOTFOUND
;
return
GIT_ENOTFOUND
;
for
(
i
=
idx
;
i
<
v
->
length
-
1
;
++
i
)
shift_count
=
v
->
length
-
idx
-
1
;
v
->
contents
[
i
]
=
v
->
contents
[
i
+
1
];
if
(
shift_count
)
memmove
(
&
v
->
contents
[
idx
],
&
v
->
contents
[
idx
+
1
],
shift_count
*
sizeof
(
void
*
));
v
->
length
--
;
v
->
length
--
;
return
0
;
return
0
;
...
@@ -249,12 +266,13 @@ void git_vector_swap(git_vector *a, git_vector *b)
...
@@ -249,12 +266,13 @@ void git_vector_swap(git_vector *a, git_vector *b)
{
{
git_vector
t
;
git_vector
t
;
if
(
!
a
||
!
b
||
a
==
b
)
assert
(
a
&&
b
);
return
;
if
(
a
!=
b
)
{
memcpy
(
&
t
,
a
,
sizeof
(
t
));
memcpy
(
&
t
,
a
,
sizeof
(
t
));
memcpy
(
a
,
b
,
sizeof
(
t
));
memcpy
(
a
,
b
,
sizeof
(
t
));
memcpy
(
b
,
&
t
,
sizeof
(
t
));
memcpy
(
b
,
&
t
,
sizeof
(
t
));
}
}
}
int
git_vector_resize_to
(
git_vector
*
v
,
size_t
new_length
)
int
git_vector_resize_to
(
git_vector
*
v
,
size_t
new_length
)
...
@@ -262,8 +280,8 @@ int git_vector_resize_to(git_vector *v, size_t new_length)
...
@@ -262,8 +280,8 @@ int git_vector_resize_to(git_vector *v, size_t new_length)
if
(
new_length
<=
v
->
length
)
if
(
new_length
<=
v
->
length
)
return
0
;
return
0
;
while
(
new_length
>=
v
->
_alloc_size
)
if
(
new_length
>
v
->
_alloc_size
&&
if
(
resize_vector
(
v
)
<
0
)
resize_vector
(
v
,
new_length
)
<
0
)
return
-
1
;
return
-
1
;
memset
(
&
v
->
contents
[
v
->
length
],
0
,
memset
(
&
v
->
contents
[
v
->
length
],
0
,
...
...
src/vector.h
View file @
11d9f6b3
...
@@ -30,29 +30,22 @@ void git_vector_swap(git_vector *a, git_vector *b);
...
@@ -30,29 +30,22 @@ void git_vector_swap(git_vector *a, git_vector *b);
void
git_vector_sort
(
git_vector
*
v
);
void
git_vector_sort
(
git_vector
*
v
);
/** Linear search for matching entry using internal comparison function */
/** Linear search for matching entry using internal comparison function */
int
git_vector_search
(
const
git_vector
*
v
,
const
void
*
entry
);
int
git_vector_search
(
size_t
*
at_pos
,
const
git_vector
*
v
,
const
void
*
entry
);
/** Linear search for matching entry using explicit comparison function */
/** Linear search for matching entry using explicit comparison function */
int
git_vector_search2
(
const
git_vector
*
v
,
git_vector_cmp
cmp
,
const
void
*
key
);
int
git_vector_search2
(
size_t
*
at_pos
,
const
git_vector
*
v
,
git_vector_cmp
cmp
,
const
void
*
key
);
/**
/**
* Binary search for matching entry using explicit comparison function that
* Binary search for matching entry using explicit comparison function that
* returns position where item would go if not found.
* returns position where item would go if not found.
*/
*/
int
git_vector_bsearch
3
(
int
git_vector_bsearch
2
(
size_t
*
at_pos
,
git_vector
*
v
,
git_vector_cmp
cmp
,
const
void
*
key
);
size_t
*
at_pos
,
git_vector
*
v
,
git_vector_cmp
cmp
,
const
void
*
key
);
/** Binary search for matching entry using internal comparison function */
/** Binary search for matching entry using internal comparison function */
GIT_INLINE
(
int
)
git_vector_bsearch
(
git_vector
*
v
,
const
void
*
key
)
GIT_INLINE
(
int
)
git_vector_bsearch
(
size_t
*
at_pos
,
git_vector
*
v
,
const
void
*
key
)
{
{
return
git_vector_bsearch3
(
NULL
,
v
,
v
->
_cmp
,
key
);
return
git_vector_bsearch2
(
at_pos
,
v
,
v
->
_cmp
,
key
);
}
/** Binary search for matching entry using explicit comparison function */
GIT_INLINE
(
int
)
git_vector_bsearch2
(
git_vector
*
v
,
git_vector_cmp
cmp
,
const
void
*
key
)
{
return
git_vector_bsearch3
(
NULL
,
v
,
cmp
,
key
);
}
}
GIT_INLINE
(
void
*
)
git_vector_get
(
const
git_vector
*
v
,
size_t
position
)
GIT_INLINE
(
void
*
)
git_vector_get
(
const
git_vector
*
v
,
size_t
position
)
...
...
tests-clar/attr/repo.c
View file @
11d9f6b3
...
@@ -266,14 +266,13 @@ static void add_to_workdir(const char *filename, const char *content)
...
@@ -266,14 +266,13 @@ static void add_to_workdir(const char *filename, const char *content)
static
void
assert_proper_normalization
(
git_index
*
index
,
const
char
*
filename
,
const
char
*
expected_sha
)
static
void
assert_proper_normalization
(
git_index
*
index
,
const
char
*
filename
,
const
char
*
expected_sha
)
{
{
in
t
index_pos
;
size_
t
index_pos
;
const
git_index_entry
*
entry
;
const
git_index_entry
*
entry
;
add_to_workdir
(
filename
,
CONTENT
);
add_to_workdir
(
filename
,
CONTENT
);
cl_git_pass
(
git_index_add_bypath
(
index
,
filename
));
cl_git_pass
(
git_index_add_bypath
(
index
,
filename
));
index_pos
=
git_index_find
(
index
,
filename
);
cl_assert
(
!
git_index_find
(
&
index_pos
,
index
,
filename
));
cl_assert
(
index_pos
>=
0
);
entry
=
git_index_get_byindex
(
index
,
index_pos
);
entry
=
git_index_get_byindex
(
index
,
index_pos
);
cl_assert_equal_i
(
0
,
git_oid_streq
(
&
entry
->
oid
,
expected_sha
));
cl_assert_equal_i
(
0
,
git_oid_streq
(
&
entry
->
oid
,
expected_sha
));
...
...
tests-clar/index/filemodes.c
View file @
11d9f6b3
...
@@ -53,13 +53,12 @@ static void replace_file_with_mode(
...
@@ -53,13 +53,12 @@ static void replace_file_with_mode(
static
void
add_and_check_mode
(
static
void
add_and_check_mode
(
git_index
*
index
,
const
char
*
filename
,
unsigned
int
expect_mode
)
git_index
*
index
,
const
char
*
filename
,
unsigned
int
expect_mode
)
{
{
in
t
pos
;
size_
t
pos
;
const
git_index_entry
*
entry
;
const
git_index_entry
*
entry
;
cl_git_pass
(
git_index_add_bypath
(
index
,
filename
));
cl_git_pass
(
git_index_add_bypath
(
index
,
filename
));
pos
=
git_index_find
(
index
,
filename
);
cl_assert
(
!
git_index_find
(
&
pos
,
index
,
filename
));
cl_assert
(
pos
>=
0
);
entry
=
git_index_get_byindex
(
index
,
pos
);
entry
=
git_index_get_byindex
(
index
,
pos
);
cl_assert
(
entry
->
mode
==
expect_mode
);
cl_assert
(
entry
->
mode
==
expect_mode
);
...
...
tests-clar/index/rename.c
View file @
11d9f6b3
...
@@ -5,7 +5,7 @@ void test_index_rename__single_file(void)
...
@@ -5,7 +5,7 @@ void test_index_rename__single_file(void)
{
{
git_repository
*
repo
;
git_repository
*
repo
;
git_index
*
index
;
git_index
*
index
;
in
t
position
;
size_
t
position
;
git_oid
expected
;
git_oid
expected
;
const
git_index_entry
*
entry
;
const
git_index_entry
*
entry
;
...
@@ -24,7 +24,7 @@ void test_index_rename__single_file(void)
...
@@ -24,7 +24,7 @@ void test_index_rename__single_file(void)
cl_git_pass
(
git_oid_fromstr
(
&
expected
,
"d4fa8600b4f37d7516bef4816ae2c64dbf029e3a"
));
cl_git_pass
(
git_oid_fromstr
(
&
expected
,
"d4fa8600b4f37d7516bef4816ae2c64dbf029e3a"
));
position
=
git_index_find
(
index
,
"lame.name.txt"
);
cl_assert
(
!
git_index_find
(
&
position
,
index
,
"lame.name.txt"
)
);
entry
=
git_index_get_byindex
(
index
,
position
);
entry
=
git_index_get_byindex
(
index
,
position
);
cl_assert
(
git_oid_cmp
(
&
expected
,
&
entry
->
oid
)
==
0
);
cl_assert
(
git_oid_cmp
(
&
expected
,
&
entry
->
oid
)
==
0
);
...
@@ -38,7 +38,7 @@ void test_index_rename__single_file(void)
...
@@ -38,7 +38,7 @@ void test_index_rename__single_file(void)
cl_git_pass
(
git_index_add_bypath
(
index
,
"fancy.name.txt"
));
cl_git_pass
(
git_index_add_bypath
(
index
,
"fancy.name.txt"
));
cl_assert
(
git_index_entrycount
(
index
)
==
1
);
cl_assert
(
git_index_entrycount
(
index
)
==
1
);
position
=
git_index_find
(
index
,
"fancy.name.txt"
);
cl_assert
(
!
git_index_find
(
&
position
,
index
,
"fancy.name.txt"
)
);
entry
=
git_index_get_byindex
(
index
,
position
);
entry
=
git_index_get_byindex
(
index
,
position
);
cl_assert
(
git_oid_cmp
(
&
expected
,
&
entry
->
oid
)
==
0
);
cl_assert
(
git_oid_cmp
(
&
expected
,
&
entry
->
oid
)
==
0
);
...
...
tests-clar/index/stage.c
View file @
11d9f6b3
...
@@ -26,36 +26,36 @@ void test_index_stage__cleanup(void)
...
@@ -26,36 +26,36 @@ void test_index_stage__cleanup(void)
void
test_index_stage__add_always_adds_stage_0
(
void
)
void
test_index_stage__add_always_adds_stage_0
(
void
)
{
{
in
t
entry_idx
;
size_
t
entry_idx
;
const
git_index_entry
*
entry
;
const
git_index_entry
*
entry
;
cl_git_mkfile
(
"./mergedrepo/new-file.txt"
,
"new-file
\n
"
);
cl_git_mkfile
(
"./mergedrepo/new-file.txt"
,
"new-file
\n
"
);
cl_git_pass
(
git_index_add_bypath
(
repo_index
,
"new-file.txt"
));
cl_git_pass
(
git_index_add_bypath
(
repo_index
,
"new-file.txt"
));
cl_assert
(
(
entry_idx
=
git_index_find
(
repo_index
,
"new-file.txt"
))
>=
0
);
cl_assert
(
!
git_index_find
(
&
entry_idx
,
repo_index
,
"new-file.txt"
)
);
cl_assert
((
entry
=
git_index_get_byindex
(
repo_index
,
entry_idx
))
!=
NULL
);
cl_assert
((
entry
=
git_index_get_byindex
(
repo_index
,
entry_idx
))
!=
NULL
);
cl_assert
(
git_index_entry_stage
(
entry
)
==
0
);
cl_assert
(
git_index_entry_stage
(
entry
)
==
0
);
}
}
void
test_index_stage__find_gets_first_stage
(
void
)
void
test_index_stage__find_gets_first_stage
(
void
)
{
{
in
t
entry_idx
;
size_
t
entry_idx
;
const
git_index_entry
*
entry
;
const
git_index_entry
*
entry
;
cl_assert
(
(
entry_idx
=
git_index_find
(
repo_index
,
"one.txt"
))
>=
0
);
cl_assert
(
!
git_index_find
(
&
entry_idx
,
repo_index
,
"one.txt"
)
);
cl_assert
((
entry
=
git_index_get_byindex
(
repo_index
,
entry_idx
))
!=
NULL
);
cl_assert
((
entry
=
git_index_get_byindex
(
repo_index
,
entry_idx
))
!=
NULL
);
cl_assert
(
git_index_entry_stage
(
entry
)
==
0
);
cl_assert
(
git_index_entry_stage
(
entry
)
==
0
);
cl_assert
(
(
entry_idx
=
git_index_find
(
repo_index
,
"two.txt"
))
>=
0
);
cl_assert
(
!
git_index_find
(
&
entry_idx
,
repo_index
,
"two.txt"
)
);
cl_assert
((
entry
=
git_index_get_byindex
(
repo_index
,
entry_idx
))
!=
NULL
);
cl_assert
((
entry
=
git_index_get_byindex
(
repo_index
,
entry_idx
))
!=
NULL
);
cl_assert
(
git_index_entry_stage
(
entry
)
==
0
);
cl_assert
(
git_index_entry_stage
(
entry
)
==
0
);
cl_assert
(
(
entry_idx
=
git_index_find
(
repo_index
,
"conflicts-one.txt"
))
>=
0
);
cl_assert
(
!
git_index_find
(
&
entry_idx
,
repo_index
,
"conflicts-one.txt"
)
);
cl_assert
((
entry
=
git_index_get_byindex
(
repo_index
,
entry_idx
))
!=
NULL
);
cl_assert
((
entry
=
git_index_get_byindex
(
repo_index
,
entry_idx
))
!=
NULL
);
cl_assert
(
git_index_entry_stage
(
entry
)
==
1
);
cl_assert
(
git_index_entry_stage
(
entry
)
==
1
);
cl_assert
(
(
entry_idx
=
git_index_find
(
repo_index
,
"conflicts-two.txt"
))
>=
0
);
cl_assert
(
!
git_index_find
(
&
entry_idx
,
repo_index
,
"conflicts-two.txt"
)
);
cl_assert
((
entry
=
git_index_get_byindex
(
repo_index
,
entry_idx
))
!=
NULL
);
cl_assert
((
entry
=
git_index_get_byindex
(
repo_index
,
entry_idx
))
!=
NULL
);
cl_assert
(
git_index_entry_stage
(
entry
)
==
1
);
cl_assert
(
git_index_entry_stage
(
entry
)
==
1
);
}
}
...
...
tests-clar/index/tests.c
View file @
11d9f6b3
...
@@ -10,7 +10,7 @@ static const size_t index_entry_count_2 = 1437;
...
@@ -10,7 +10,7 @@ static const size_t index_entry_count_2 = 1437;
// Suite data
// Suite data
struct
test_entry
{
struct
test_entry
{
in
t
index
;
size_
t
index
;
char
path
[
128
];
char
path
[
128
];
git_off_t
file_size
;
git_off_t
file_size
;
git_time_t
mtime
;
git_time_t
mtime
;
...
@@ -131,7 +131,9 @@ void test_index_tests__find_in_existing(void)
...
@@ -131,7 +131,9 @@ void test_index_tests__find_in_existing(void)
cl_git_pass
(
git_index_open
(
&
index
,
TEST_INDEX_PATH
));
cl_git_pass
(
git_index_open
(
&
index
,
TEST_INDEX_PATH
));
for
(
i
=
0
;
i
<
ARRAY_SIZE
(
test_entries
);
++
i
)
{
for
(
i
=
0
;
i
<
ARRAY_SIZE
(
test_entries
);
++
i
)
{
int
idx
=
git_index_find
(
index
,
test_entries
[
i
].
path
);
size_t
idx
;
cl_assert
(
!
git_index_find
(
&
idx
,
index
,
test_entries
[
i
].
path
));
cl_assert
(
idx
==
test_entries
[
i
].
index
);
cl_assert
(
idx
==
test_entries
[
i
].
index
);
}
}
...
@@ -146,8 +148,7 @@ void test_index_tests__find_in_empty(void)
...
@@ -146,8 +148,7 @@ void test_index_tests__find_in_empty(void)
cl_git_pass
(
git_index_open
(
&
index
,
"fake-index"
));
cl_git_pass
(
git_index_open
(
&
index
,
"fake-index"
));
for
(
i
=
0
;
i
<
ARRAY_SIZE
(
test_entries
);
++
i
)
{
for
(
i
=
0
;
i
<
ARRAY_SIZE
(
test_entries
);
++
i
)
{
int
idx
=
git_index_find
(
index
,
test_entries
[
i
].
path
);
cl_assert
(
GIT_ENOTFOUND
==
git_index_find
(
NULL
,
index
,
test_entries
[
i
].
path
));
cl_assert
(
idx
==
GIT_ENOTFOUND
);
}
}
git_index_free
(
index
);
git_index_free
(
index
);
...
...
tests-clar/submodule/status.c
View file @
11d9f6b3
...
@@ -100,11 +100,10 @@ void test_submodule_status__ignore_none(void)
...
@@ -100,11 +100,10 @@ void test_submodule_status__ignore_none(void)
/* remove sm_changed_head from index */
/* remove sm_changed_head from index */
{
{
git_index
*
index
;
git_index
*
index
;
in
t
pos
;
size_
t
pos
;
cl_git_pass
(
git_repository_index
(
&
index
,
g_repo
));
cl_git_pass
(
git_repository_index
(
&
index
,
g_repo
));
pos
=
git_index_find
(
index
,
"sm_changed_head"
);
cl_assert
(
!
git_index_find
(
&
pos
,
index
,
"sm_changed_head"
));
cl_assert
(
pos
>=
0
);
cl_git_pass
(
git_index_remove
(
index
,
"sm_changed_head"
,
0
));
cl_git_pass
(
git_index_remove
(
index
,
"sm_changed_head"
,
0
));
cl_git_pass
(
git_index_write
(
index
));
cl_git_pass
(
git_index_write
(
index
));
...
...
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