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
9bd89d96
Commit
9bd89d96
authored
May 04, 2013
by
Carlos Martín Nieto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move a couple more functions to use iterators
parent
2b562c3a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
39 deletions
+48
-39
src/branch.c
+30
-27
src/remote.c
+18
-12
No files found.
src/branch.c
View file @
9bd89d96
...
...
@@ -124,40 +124,43 @@ on_error:
return
error
;
}
typedef
struct
{
git_branch_foreach_cb
branch_cb
;
void
*
callback_payload
;
unsigned
int
branch_type
;
}
branch_foreach_filter
;
static
int
branch_foreach_cb
(
const
char
*
branch_name
,
void
*
payload
)
{
branch_foreach_filter
*
filter
=
(
branch_foreach_filter
*
)
payload
;
if
(
filter
->
branch_type
&
GIT_BRANCH_LOCAL
&&
git__prefixcmp
(
branch_name
,
GIT_REFS_HEADS_DIR
)
==
0
)
return
filter
->
branch_cb
(
branch_name
+
strlen
(
GIT_REFS_HEADS_DIR
),
GIT_BRANCH_LOCAL
,
filter
->
callback_payload
);
if
(
filter
->
branch_type
&
GIT_BRANCH_REMOTE
&&
git__prefixcmp
(
branch_name
,
GIT_REFS_REMOTES_DIR
)
==
0
)
return
filter
->
branch_cb
(
branch_name
+
strlen
(
GIT_REFS_REMOTES_DIR
),
GIT_BRANCH_REMOTE
,
filter
->
callback_payload
);
return
0
;
}
int
git_branch_foreach
(
git_repository
*
repo
,
unsigned
int
list_flags
,
git_branch_foreach_cb
branch_cb
,
git_branch_foreach_cb
callback
,
void
*
payload
)
{
branch_foreach_filter
filter
;
git_reference_iterator
*
iter
;
const
char
*
name
;
int
error
;
if
(
git_reference_iterator_new
(
&
iter
,
repo
)
<
0
)
return
-
1
;
filter
.
branch_cb
=
branch_cb
;
filter
.
branch_type
=
list_flags
;
filter
.
callback_payload
=
payload
;
while
((
error
=
git_reference_next
(
&
name
,
iter
))
==
0
)
{
if
(
list_flags
&
GIT_BRANCH_LOCAL
&&
git__prefixcmp
(
name
,
GIT_REFS_HEADS_DIR
)
==
0
)
{
if
(
callback
(
name
+
strlen
(
GIT_REFS_HEADS_DIR
),
GIT_BRANCH_LOCAL
,
payload
))
{
error
=
GIT_EUSER
;
break
;
}
}
if
(
list_flags
&
GIT_BRANCH_REMOTE
&&
git__prefixcmp
(
name
,
GIT_REFS_REMOTES_DIR
)
==
0
)
{
if
(
callback
(
name
+
strlen
(
GIT_REFS_REMOTES_DIR
),
GIT_BRANCH_REMOTE
,
payload
))
{
error
=
GIT_EUSER
;
break
;
}
}
}
if
(
error
==
GIT_ITEROVER
)
error
=
0
;
git_reference_iterator_free
(
iter
);
return
error
;
return
git_reference_foreach
(
repo
,
&
branch_foreach_cb
,
(
void
*
)
&
filter
);
}
int
git_branch_move
(
...
...
src/remote.c
View file @
9bd89d96
...
...
@@ -1244,14 +1244,6 @@ static int update_branch_remote_config_entry(
update_config_entries_cb
,
&
data
);
}
static
int
rename_cb
(
const
char
*
ref
,
void
*
data
)
{
if
(
git__prefixcmp
(
ref
,
GIT_REFS_REMOTES_DIR
))
return
0
;
return
git_vector_insert
((
git_vector
*
)
data
,
git__strdup
(
ref
));
}
static
int
rename_one_remote_reference
(
git_repository
*
repo
,
const
char
*
reference_name
,
...
...
@@ -1291,14 +1283,28 @@ static int rename_remote_references(
int
error
=
-
1
;
unsigned
int
i
;
char
*
name
;
const
char
*
refname
;
git_reference_iterator
*
iter
;
if
(
git_vector_init
(
&
refnames
,
8
,
NULL
)
<
0
)
return
-
1
;
if
(
git_reference_iterator_new
(
&
iter
,
repo
)
<
0
)
goto
cleanup
;
if
(
git_reference_foreach
(
repo
,
rename_cb
,
&
refnames
)
<
0
)
while
((
error
=
git_reference_next
(
&
refname
,
iter
))
==
0
)
{
if
(
git__prefixcmp
(
refname
,
GIT_REFS_REMOTES_DIR
))
continue
;
if
((
error
=
git_vector_insert
(
&
refnames
,
git__strdup
(
refname
)))
<
0
)
break
;
}
git_reference_iterator_free
(
iter
);
if
(
error
==
GIT_ITEROVER
)
error
=
0
;
else
goto
cleanup
;
git_vector_foreach
(
&
refnames
,
i
,
name
)
{
...
...
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