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
7ad96e51
Commit
7ad96e51
authored
Mar 15, 2011
by
Vicent Marti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove duplicate refs in `git_reference_listall`
parent
5f8078d4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
12 deletions
+23
-12
src/refs.c
+18
-11
tests/t10-refs.c
+5
-1
No files found.
src/refs.c
View file @
7ad96e51
...
...
@@ -546,6 +546,7 @@ cleanup:
struct
dirent_list_data
{
git_vector
ref_list
;
git_repository
*
repo
;
size_t
repo_path_len
;
unsigned
int
list_flags
;
};
...
...
@@ -553,16 +554,18 @@ struct dirent_list_data {
static
int
_dirent_loose_listall
(
void
*
_data
,
char
*
full_path
)
{
struct
dirent_list_data
*
data
=
(
struct
dirent_list_data
*
)
_data
;
char
*
file_path
;
char
*
file_path
=
full_path
+
data
->
repo_path_len
;
if
(
gitfo_isdir
(
full_path
)
==
GIT_SUCCESS
)
return
gitfo_dirent
(
full_path
,
GIT_PATH_MAX
,
_dirent_loose_listall
,
_data
);
/* do not add twice a reference that exists already in the packfile */
if
(
git_hashtable_lookup
(
data
->
repo
->
references
.
packfile
,
file_path
)
!=
NULL
)
return
GIT_SUCCESS
;
if
((
data
->
list_flags
&
loose_guess_rtype
(
full_path
))
==
0
)
return
GIT_SUCCESS
;
/* we are filtering out this reference */
file_path
=
full_path
+
data
->
repo_path_len
;
return
git_vector_insert
(
&
data
->
ref_list
,
git__strdup
(
file_path
));
}
...
...
@@ -1336,15 +1339,9 @@ int git_reference_listall(git_strarray *array, git_repository *repo, unsigned in
git_vector_init
(
&
data
.
ref_list
,
8
,
NULL
);
data
.
repo_path_len
=
strlen
(
repo
->
path_repository
);
data
.
list_flags
=
list_flags
;
data
.
repo
=
repo
;
git__joinpath
(
refs_path
,
repo
->
path_repository
,
GIT_REFS_DIR
);
error
=
gitfo_dirent
(
refs_path
,
GIT_PATH_MAX
,
_dirent_loose_listall
,
&
data
);
if
(
error
<
GIT_SUCCESS
)
{
git_vector_free
(
&
data
.
ref_list
);
return
error
;
}
/* list all the packed references first */
if
(
list_flags
&
GIT_REF_PACKED
)
{
const
char
*
ref_name
;
void
*
_unused
;
...
...
@@ -1359,6 +1356,16 @@ int git_reference_listall(git_strarray *array, git_repository *repo, unsigned in
);
}
/* now list the loose references, trying not to
* duplicate the ref names already in the packed-refs file */
git__joinpath
(
refs_path
,
repo
->
path_repository
,
GIT_REFS_DIR
);
error
=
gitfo_dirent
(
refs_path
,
GIT_PATH_MAX
,
_dirent_loose_listall
,
&
data
);
if
(
error
<
GIT_SUCCESS
)
{
git_vector_free
(
&
data
.
ref_list
);
return
error
;
}
array
->
strings
=
(
char
**
)
data
.
ref_list
.
contents
;
array
->
count
=
data
.
ref_list
.
length
;
return
GIT_SUCCESS
;
...
...
tests/t10-refs.c
View file @
7ad96e51
...
...
@@ -716,7 +716,11 @@ BEGIN_TEST(list0, "try to list all the references in our test repo")
must_pass
(
git_repository_open
(
&
repo
,
REPOSITORY_FOLDER
));
must_pass
(
git_reference_listall
(
&
ref_list
,
repo
,
GIT_REF_LISTALL
));
must_be_true
(
ref_list
.
count
==
8
);
/* 8 refs in total if we include the packed ones */
/* We have exactly 7 refs in total if we include the packed ones:
* there is a reference that exists both in the packfile and as
* loose, but we only list it once */
must_be_true
(
ref_list
.
count
==
7
);
git_strarray_free
(
&
ref_list
);
git_repository_free
(
repo
);
...
...
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