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
3fec548a
Commit
3fec548a
authored
Apr 23, 2015
by
Carlos Martín Nieto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
examples: adjust to the new remote API
parent
35a8a8c5
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16 additions
and
24 deletions
+16
-24
examples/network/clone.c
+3
-3
examples/network/fetch.c
+9
-8
examples/network/ls-remote.c
+1
-2
examples/remote.c
+3
-11
No files found.
examples/network/clone.c
View file @
3fec548a
...
...
@@ -86,9 +86,9 @@ int do_clone(git_repository *repo, int argc, char **argv)
checkout_opts
.
progress_cb
=
checkout_progress
;
checkout_opts
.
progress_payload
=
&
pd
;
clone_opts
.
checkout_opts
=
checkout_opts
;
clone_opts
.
remote_
callbacks
.
transfer_progress
=
&
fetch_progress
;
clone_opts
.
remote_
callbacks
.
credentials
=
cred_acquire_cb
;
clone_opts
.
remote_
callbacks
.
payload
=
&
pd
;
clone_opts
.
fetch_opts
.
callbacks
.
transfer_progress
=
&
fetch_progress
;
clone_opts
.
fetch_opts
.
callbacks
.
credentials
=
cred_acquire_cb
;
clone_opts
.
fetch_opts
.
callbacks
.
payload
=
&
pd
;
// Do the clone
error
=
git_clone
(
&
cloned_repo
,
url
,
path
,
&
clone_opts
);
...
...
examples/network/fetch.c
View file @
3fec548a
...
...
@@ -10,6 +10,7 @@
struct
dl_data
{
git_remote
*
remote
;
git_fetch_options
*
fetch_opts
;
int
ret
;
int
finished
;
};
...
...
@@ -28,7 +29,7 @@ static void *download(void *ptr)
// Connect to the remote end specifying that we want to fetch
// information from it.
if
(
git_remote_connect
(
data
->
remote
,
GIT_DIRECTION_FETCH
)
<
0
)
{
if
(
git_remote_connect
(
data
->
remote
,
GIT_DIRECTION_FETCH
,
&
data
->
fetch_opts
->
callbacks
)
<
0
)
{
data
->
ret
=
-
1
;
goto
exit
;
}
...
...
@@ -36,7 +37,7 @@ static void *download(void *ptr)
// Download the packfile and index it. This function updates the
// amount of received data and the indexer stats which lets you
// inform the user about progress.
if
(
git_remote_download
(
data
->
remote
,
NULL
)
<
0
)
{
if
(
git_remote_download
(
data
->
remote
,
NULL
,
data
->
fetch_opts
)
<
0
)
{
data
->
ret
=
-
1
;
goto
exit
;
}
...
...
@@ -78,7 +79,7 @@ int fetch(git_repository *repo, int argc, char **argv)
git_remote
*
remote
=
NULL
;
const
git_transfer_progress
*
stats
;
struct
dl_data
data
;
git_
remote_callbacks
callbacks
=
GIT_REMOTE_CALLBACK
S_INIT
;
git_
fetch_options
fetch_opts
=
GIT_FETCH_OPTION
S_INIT
;
#ifndef _WIN32
pthread_t
worker
;
#endif
...
...
@@ -96,13 +97,13 @@ int fetch(git_repository *repo, int argc, char **argv)
}
// Set up the callbacks (only update_tips for now)
callbacks
.
update_tips
=
&
update_cb
;
callbacks
.
sideband_progress
=
&
progress_cb
;
callbacks
.
credentials
=
cred_acquire_cb
;
git_remote_set_callbacks
(
remote
,
&
callbacks
);
fetch_opts
.
callbacks
.
update_tips
=
&
update_cb
;
fetch_opts
.
callbacks
.
sideband_progress
=
&
progress_cb
;
fetch_opts
.
callbacks
.
credentials
=
cred_acquire_cb
;
// Set up the information for the background worker thread
data
.
remote
=
remote
;
data
.
fetch_opts
=
&
fetch_opts
;
data
.
ret
=
0
;
data
.
finished
=
0
;
...
...
@@ -156,7 +157,7 @@ int fetch(git_repository *repo, int argc, char **argv)
// right commits. This may be needed even if there was no packfile
// to download, which can happen e.g. when the branches have been
// changed but all the needed objects are available locally.
if
(
git_remote_update_tips
(
remote
,
NULL
)
<
0
)
if
(
git_remote_update_tips
(
remote
,
&
fetch_opts
.
callbacks
,
1
,
fetch_opts
.
download_tags
,
NULL
)
<
0
)
return
-
1
;
git_remote_free
(
remote
);
...
...
examples/network/ls-remote.c
View file @
3fec548a
...
...
@@ -25,9 +25,8 @@ static int use_remote(git_repository *repo, char *name)
* each of the remote references.
*/
callbacks
.
credentials
=
cred_acquire_cb
;
git_remote_set_callbacks
(
remote
,
&
callbacks
);
error
=
git_remote_connect
(
remote
,
GIT_DIRECTION_FETCH
);
error
=
git_remote_connect
(
remote
,
GIT_DIRECTION_FETCH
,
&
callbacks
);
if
(
error
<
0
)
goto
cleanup
;
...
...
examples/remote.c
View file @
3fec548a
...
...
@@ -151,7 +151,6 @@ static int cmd_seturl(git_repository *repo, struct opts *o)
{
int
i
,
retval
,
push
=
0
;
char
*
name
=
NULL
,
*
url
=
NULL
;
git_remote
*
remote
;
for
(
i
=
0
;
i
<
o
->
argc
;
i
++
)
{
char
*
arg
=
o
->
argv
[
i
];
...
...
@@ -170,19 +169,12 @@ static int cmd_seturl(git_repository *repo, struct opts *o)
if
(
name
==
NULL
||
url
==
NULL
)
usage
(
"you need to specify remote and the new URL"
,
NULL
);
check_lg2
(
git_remote_lookup
(
&
remote
,
repo
,
name
),
"could not look up remote"
,
name
);
if
(
push
)
retval
=
git_remote_set_pushurl
(
re
mot
e
,
url
);
retval
=
git_remote_set_pushurl
(
re
po
,
nam
e
,
url
);
else
retval
=
git_remote_set_url
(
remote
,
url
);
check_lg2
(
retval
,
"could not set URL"
,
url
);
retval
=
git_remote_set_url
(
repo
,
name
,
url
);
check_lg2
(
git_remote_save
(
remote
),
"could not save remote"
,
NULL
);
git_remote_free
(
remote
);
check_lg2
(
retval
,
"could not set URL"
,
url
);
return
0
;
}
...
...
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