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
d57c47dc
Commit
d57c47dc
authored
Oct 16, 2012
by
Ben Straub
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add accessor for git_remote's stats field
Also converted the network example to use it.
parent
3028be07
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
9 deletions
+19
-9
examples/network/fetch.c
+8
-9
include/git2/remote.h
+5
-0
src/remote.c
+6
-0
No files found.
examples/network/fetch.c
View file @
d57c47dc
...
...
@@ -9,7 +9,6 @@
struct
dl_data
{
git_remote
*
remote
;
git_off_t
*
bytes
;
git_indexer_stats
*
stats
;
int
ret
;
int
finished
;
};
...
...
@@ -35,7 +34,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
,
data
->
bytes
,
data
->
stats
)
<
0
)
{
if
(
git_remote_download
(
data
->
remote
,
data
->
bytes
)
<
0
)
{
data
->
ret
=
-
1
;
goto
exit
;
}
...
...
@@ -70,14 +69,14 @@ int fetch(git_repository *repo, int argc, char **argv)
{
git_remote
*
remote
=
NULL
;
git_off_t
bytes
=
0
;
git_indexer_stats
stats
;
const
git_indexer_stats
*
stats
;
pthread_t
worker
;
struct
dl_data
data
;
git_remote_callbacks
callbacks
;
argc
=
argc
;
// Figure out whether it's a named remote or a URL
printf
(
"Fetching %s
\n
"
,
argv
[
1
]
);
printf
(
"Fetching %s
for repo %p
\n
"
,
argv
[
1
],
repo
);
if
(
git_remote_load
(
&
remote
,
repo
,
argv
[
1
])
<
0
)
{
if
(
git_remote_new
(
&
remote
,
repo
,
NULL
,
argv
[
1
],
NULL
)
<
0
)
return
-
1
;
...
...
@@ -92,10 +91,10 @@ int fetch(git_repository *repo, int argc, char **argv)
// Set up the information for the background worker thread
data
.
remote
=
remote
;
data
.
bytes
=
&
bytes
;
data
.
stats
=
&
stats
;
data
.
ret
=
0
;
data
.
finished
=
0
;
memset
(
&
stats
,
0
,
sizeof
(
stats
));
stats
=
git_remote_stats
(
remote
);
pthread_create
(
&
worker
,
NULL
,
download
,
&
data
);
...
...
@@ -106,16 +105,16 @@ int fetch(git_repository *repo, int argc, char **argv)
do
{
usleep
(
10000
);
if
(
stats
.
total
>
0
)
if
(
stats
->
total
>
0
)
printf
(
"Received %d/%d objects (%d) in %d bytes
\r
"
,
stats
.
received
,
stats
.
total
,
stats
.
processed
,
bytes
);
stats
->
received
,
stats
->
total
,
stats
->
processed
,
bytes
);
}
while
(
!
data
.
finished
);
if
(
data
.
ret
<
0
)
goto
on_error
;
pthread_join
(
worker
,
NULL
);
printf
(
"
\r
Received %d/%d objects in %zu bytes
\n
"
,
stats
.
processed
,
stats
.
total
,
bytes
);
printf
(
"
\r
Received %d/%d objects in %zu bytes
\n
"
,
stats
->
processed
,
stats
->
total
,
bytes
);
// Disconnect the underlying connection to prevent from idling.
git_remote_disconnect
(
remote
);
...
...
include/git2/remote.h
View file @
d57c47dc
...
...
@@ -313,6 +313,11 @@ struct git_remote_callbacks {
*/
GIT_EXTERN
(
void
)
git_remote_set_callbacks
(
git_remote
*
remote
,
git_remote_callbacks
*
callbacks
);
/**
* Get the statistics structure that is filled in by the fetch operation.
*/
GIT_EXTERN
(
const
git_indexer_stats
*
)
git_remote_stats
(
git_remote
*
remote
);
enum
{
GIT_REMOTE_DOWNLOAD_TAGS_UNSET
,
GIT_REMOTE_DOWNLOAD_TAGS_NONE
,
...
...
src/remote.c
View file @
d57c47dc
...
...
@@ -703,6 +703,12 @@ void git_remote_set_callbacks(git_remote *remote, git_remote_callbacks *callback
}
}
inline
const
git_indexer_stats
*
git_remote_stats
(
git_remote
*
remote
)
{
assert
(
remote
);
return
&
remote
->
stats
;
}
int
git_remote_autotag
(
git_remote
*
remote
)
{
return
remote
->
download_tags
;
...
...
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