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
c7d9839f
Commit
c7d9839f
authored
Dec 20, 2014
by
Edward Thomson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2763 from libgit2/cmn/local-proto-progress
Show progress output on fetch for the local transport
parents
0de26b7c
4fd2bda9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
86 additions
and
0 deletions
+86
-0
src/transports/local.c
+52
-0
tests/network/fetchlocal.c
+34
-0
No files found.
src/transports/local.c
View file @
c7d9839f
...
...
@@ -35,6 +35,9 @@ typedef struct {
int
flags
;
git_atomic
cancelled
;
git_repository
*
repo
;
git_transport_message_cb
progress_cb
;
git_transport_message_cb
error_cb
;
void
*
message_cb_payload
;
git_vector
refs
;
unsigned
connected
:
1
,
have_refs
:
1
;
...
...
@@ -494,6 +497,8 @@ static int foreach_cb(void *buf, size_t len, void *payload)
return
data
->
writepack
->
append
(
data
->
writepack
,
buf
,
len
,
data
->
stats
);
}
static
const
char
*
counting_objects_fmt
=
"Counting objects %d
\r
"
;
static
int
local_download_pack
(
git_transport
*
transport
,
git_repository
*
repo
,
...
...
@@ -510,6 +515,7 @@ static int local_download_pack(
git_packbuilder
*
pack
=
NULL
;
git_odb_writepack
*
writepack
=
NULL
;
git_odb
*
odb
=
NULL
;
git_buf
progress_info
=
GIT_BUF_INIT
;
if
((
error
=
git_revwalk_new
(
&
walk
,
t
->
repo
))
<
0
)
goto
cleanup
;
...
...
@@ -540,6 +546,13 @@ static int local_download_pack(
git_object_free
(
obj
);
}
if
((
error
=
git_buf_printf
(
&
progress_info
,
counting_objects_fmt
,
git_packbuilder_object_count
(
pack
)))
<
0
)
goto
cleanup
;
if
(
t
->
progress_cb
&&
(
error
=
t
->
progress_cb
(
git_buf_cstr
(
&
progress_info
),
git_buf_len
(
&
progress_info
),
t
->
message_cb_payload
))
<
0
)
goto
cleanup
;
/* Walk the objects, building a packfile */
if
((
error
=
git_repository_odb__weakptr
(
&
odb
,
repo
))
<
0
)
goto
cleanup
;
...
...
@@ -561,9 +574,28 @@ static int local_download_pack(
}
git_commit_free
(
commit
);
git_buf_clear
(
&
progress_info
);
if
((
error
=
git_buf_printf
(
&
progress_info
,
counting_objects_fmt
,
git_packbuilder_object_count
(
pack
)))
<
0
)
goto
cleanup
;
if
(
t
->
progress_cb
&&
(
error
=
t
->
progress_cb
(
git_buf_cstr
(
&
progress_info
),
git_buf_len
(
&
progress_info
),
t
->
message_cb_payload
))
<
0
)
goto
cleanup
;
}
}
/* One last one with the newline */
git_buf_clear
(
&
progress_info
);
git_buf_printf
(
&
progress_info
,
counting_objects_fmt
,
git_packbuilder_object_count
(
pack
));
if
((
error
=
git_buf_putc
(
&
progress_info
,
'\n'
))
<
0
)
goto
cleanup
;
if
(
t
->
progress_cb
&&
(
error
=
t
->
progress_cb
(
git_buf_cstr
(
&
progress_info
),
git_buf_len
(
&
progress_info
),
t
->
message_cb_payload
))
<
0
)
goto
cleanup
;
if
((
error
=
git_odb_write_pack
(
&
writepack
,
odb
,
progress_cb
,
progress_payload
))
!=
0
)
goto
cleanup
;
...
...
@@ -582,11 +614,30 @@ static int local_download_pack(
cleanup:
if
(
writepack
)
writepack
->
free
(
writepack
);
git_buf_free
(
&
progress_info
);
git_packbuilder_free
(
pack
);
git_revwalk_free
(
walk
);
return
error
;
}
static
int
local_set_callbacks
(
git_transport
*
transport
,
git_transport_message_cb
progress_cb
,
git_transport_message_cb
error_cb
,
git_transport_certificate_check_cb
certificate_check_cb
,
void
*
message_cb_payload
)
{
transport_local
*
t
=
(
transport_local
*
)
transport
;
GIT_UNUSED
(
certificate_check_cb
);
t
->
progress_cb
=
progress_cb
;
t
->
error_cb
=
error_cb
;
t
->
message_cb_payload
=
message_cb_payload
;
return
0
;
}
static
int
local_is_connected
(
git_transport
*
transport
)
{
transport_local
*
t
=
(
transport_local
*
)
transport
;
...
...
@@ -656,6 +707,7 @@ int git_transport_local(git_transport **out, git_remote *owner, void *param)
GITERR_CHECK_ALLOC
(
t
);
t
->
parent
.
version
=
GIT_TRANSPORT_VERSION
;
t
->
parent
.
set_callbacks
=
local_set_callbacks
;
t
->
parent
.
connect
=
local_connect
;
t
->
parent
.
negotiate_fetch
=
local_negotiate_fetch
;
t
->
parent
.
download_pack
=
local_download_pack
;
...
...
tests/network/fetchlocal.c
View file @
c7d9839f
...
...
@@ -162,3 +162,37 @@ void test_network_fetchlocal__multi_remotes(void)
git_remote_free
(
test
);
git_remote_free
(
test2
);
}
static
int
sideband_cb
(
const
char
*
str
,
int
len
,
void
*
payload
)
{
int
*
count
=
(
int
*
)
payload
;
GIT_UNUSED
(
str
);
GIT_UNUSED
(
len
);
(
*
count
)
++
;
return
0
;
}
void
test_network_fetchlocal__call_progress
(
void
)
{
git_repository
*
repo
;
git_remote
*
remote
;
git_remote_callbacks
callbacks
=
GIT_REMOTE_CALLBACKS_INIT
;
int
callcount
=
0
;
cl_git_pass
(
git_repository_init
(
&
repo
,
"foo.git"
,
true
));
cl_set_cleanup
(
cleanup_local_repo
,
"foo.git"
);
cl_git_pass
(
git_remote_create_with_fetchspec
(
&
remote
,
repo
,
"origin"
,
cl_git_fixture_url
(
"testrepo.git"
),
"+refs/heads/*:refs/heads/*"
));
callbacks
.
sideband_progress
=
sideband_cb
;
callbacks
.
payload
=
&
callcount
;
cl_git_pass
(
git_remote_set_callbacks
(
remote
,
&
callbacks
));
cl_git_pass
(
git_remote_fetch
(
remote
,
NULL
,
NULL
,
NULL
));
cl_assert
(
callcount
!=
0
);
git_remote_free
(
remote
);
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