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
c6713398
Commit
c6713398
authored
Jun 25, 2012
by
Vicent Martí
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #785 from nulltoken/topic/refs-fromglob
Topic/refs fromglob
parents
b15b91f5
11634346
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
139 additions
and
8 deletions
+139
-8
include/git2/refs.h
+30
-1
src/refs.c
+37
-0
src/revwalk.c
+2
-7
tests-clar/refs/foreachglob.c
+70
-0
No files found.
include/git2/refs.h
View file @
c6713398
...
...
@@ -258,7 +258,6 @@ GIT_EXTERN(int) git_reference_packall(git_repository *repo);
*/
GIT_EXTERN
(
int
)
git_reference_list
(
git_strarray
*
array
,
git_repository
*
repo
,
unsigned
int
list_flags
);
/**
* Perform an operation on each reference in the repository
*
...
...
@@ -324,6 +323,36 @@ GIT_EXTERN(void) git_reference_free(git_reference *ref);
*/
GIT_EXTERN
(
int
)
git_reference_cmp
(
git_reference
*
ref1
,
git_reference
*
ref2
);
/**
* Loop over all the references and issue a callback for each one
* which name matches the given glob pattern.
*
* The processed references may be filtered by type, or using
* a bitwise OR of several types. Use the magic value
* `GIT_REF_LISTALL` to obtain all references, including
* packed ones.
*
* @param repo Repository where to find the references.
*
* @param list_flags Filtering flags for the reference
* listing.
*
* @param callback Callback to invoke per found reference.
*
* @param payload Extra parameter to callback function.
*
* @return 0 or an error code.
*/
GIT_EXTERN
(
int
)
git_reference_foreach_glob
(
git_repository
*
repo
,
const
char
*
glob
,
unsigned
int
list_flags
,
int
(
*
callback
)(
const
char
*
reference_name
,
void
*
payload
),
void
*
payload
);
/** @} */
GIT_END_DECL
#endif
src/refs.c
View file @
c6713398
...
...
@@ -1764,3 +1764,40 @@ int git_reference__update(git_repository *repo, const git_oid *oid, const char *
git_reference_free
(
ref
);
return
res
;
}
struct
glob_cb_data
{
const
char
*
glob
;
int
(
*
callback
)(
const
char
*
,
void
*
);
void
*
payload
;
};
static
int
fromglob_cb
(
const
char
*
reference_name
,
void
*
payload
)
{
struct
glob_cb_data
*
data
=
(
struct
glob_cb_data
*
)
payload
;
if
(
!
p_fnmatch
(
data
->
glob
,
reference_name
,
0
))
return
data
->
callback
(
reference_name
,
data
->
payload
);
return
0
;
}
int
git_reference_foreach_glob
(
git_repository
*
repo
,
const
char
*
glob
,
unsigned
int
list_flags
,
int
(
*
callback
)(
const
char
*
reference_name
,
void
*
payload
),
void
*
payload
)
{
struct
glob_cb_data
data
;
assert
(
repo
&&
glob
&&
callback
);
data
.
glob
=
glob
;
data
.
callback
=
callback
;
data
.
payload
=
payload
;
return
git_reference_foreach
(
repo
,
list_flags
,
fromglob_cb
,
&
data
);
}
src/revwalk.c
View file @
c6713398
...
...
@@ -540,7 +540,6 @@ static int push_ref(git_revwalk *walk, const char *refname, int hide)
struct
push_cb_data
{
git_revwalk
*
walk
;
const
char
*
glob
;
int
hide
;
};
...
...
@@ -548,10 +547,7 @@ static int push_glob_cb(const char *refname, void *data_)
{
struct
push_cb_data
*
data
=
(
struct
push_cb_data
*
)
data_
;
if
(
!
p_fnmatch
(
data
->
glob
,
refname
,
0
))
return
push_ref
(
data
->
walk
,
refname
,
data
->
hide
);
return
0
;
}
static
int
push_glob
(
git_revwalk
*
walk
,
const
char
*
glob
,
int
hide
)
...
...
@@ -584,11 +580,10 @@ static int push_glob(git_revwalk *walk, const char *glob, int hide)
goto
on_error
;
data
.
walk
=
walk
;
data
.
glob
=
git_buf_cstr
(
&
buf
);
data
.
hide
=
hide
;
if
(
git_reference_foreach
(
walk
->
repo
,
GIT_REF_LISTALL
,
push_glob_cb
,
&
data
)
<
0
)
if
(
git_reference_foreach
_glob
(
walk
->
repo
,
git_buf_cstr
(
&
buf
)
,
GIT_REF_LISTALL
,
push_glob_cb
,
&
data
)
<
0
)
goto
on_error
;
regfree
(
&
preg
);
...
...
tests-clar/refs/foreachglob.c
0 → 100644
View file @
c6713398
#include "clar_libgit2.h"
#include "refs.h"
static
git_repository
*
repo
;
static
git_reference
*
fake_remote
;
void
test_refs_foreachglob__initialize
(
void
)
{
git_oid
id
;
cl_fixture_sandbox
(
"testrepo.git"
);
cl_git_pass
(
git_repository_open
(
&
repo
,
"testrepo.git"
));
cl_git_pass
(
git_oid_fromstr
(
&
id
,
"be3563ae3f795b2b4353bcce3a527ad0a4f7f644"
));
cl_git_pass
(
git_reference_create_oid
(
&
fake_remote
,
repo
,
"refs/remotes/nulltoken/master"
,
&
id
,
0
));
}
void
test_refs_foreachglob__cleanup
(
void
)
{
git_reference_free
(
fake_remote
);
git_repository_free
(
repo
);
cl_fixture_cleanup
(
"testrepo.git"
);
}
static
int
count_cb
(
const
char
*
reference_name
,
void
*
payload
)
{
int
*
count
=
(
int
*
)
payload
;
GIT_UNUSED
(
reference_name
);
(
*
count
)
++
;
return
0
;
}
static
void
assert_retrieval
(
const
char
*
glob
,
unsigned
int
flags
,
int
expected_count
)
{
int
count
=
0
;
cl_git_pass
(
git_reference_foreach_glob
(
repo
,
glob
,
flags
,
count_cb
,
&
count
));
cl_assert_equal_i
(
expected_count
,
count
);
}
void
test_refs_foreachglob__retrieve_all_refs
(
void
)
{
/* 7 heads (including one packed head) + 1 note + 2 remotes + 6 tags */
assert_retrieval
(
"*"
,
GIT_REF_LISTALL
,
16
);
}
void
test_refs_foreachglob__retrieve_remote_branches
(
void
)
{
assert_retrieval
(
"refs/remotes/*"
,
GIT_REF_LISTALL
,
2
);
}
void
test_refs_foreachglob__retrieve_local_branches
(
void
)
{
assert_retrieval
(
"refs/heads/*"
,
GIT_REF_LISTALL
,
7
);
}
void
test_refs_foreachglob__retrieve_partially_named_references
(
void
)
{
/*
* refs/heads/packed-test, refs/heads/test
* refs/remotes/test/master, refs/tags/test
*/
assert_retrieval
(
"*test*"
,
GIT_REF_LISTALL
,
4
);
}
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