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
6f6871a9
Commit
6f6871a9
authored
Oct 18, 2012
by
Vicent Martí
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #992 from carlosmn/fetch-cancel
remote: support fetch cancelation
parents
4c47a8bc
f0d2ddbb
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
5 deletions
+43
-5
include/git2/remote.h
+8
-0
src/fetch.c
+28
-5
src/remote.c
+5
-0
src/transport.h
+2
-0
No files found.
include/git2/remote.h
View file @
6f6871a9
...
...
@@ -199,6 +199,14 @@ GIT_EXTERN(int) git_remote_download(git_remote *remote, git_off_t *bytes, git_in
GIT_EXTERN
(
int
)
git_remote_connected
(
git_remote
*
remote
);
/**
* Cancel the operation
*
* At certain points in its operation, the network code checks whether
* the operation has been cancelled and if so stops the operation.
*/
GIT_EXTERN
(
void
)
git_remote_stop
(
git_remote
*
remote
);
/**
* Disconnect from the remote
*
* Close the connection to the remote and free the underlying
...
...
src/fetch.c
View file @
6f6871a9
...
...
@@ -152,7 +152,7 @@ int git_fetch_negotiate(git_remote *remote)
gitno_buffer
*
buf
=
&
t
->
buffer
;
git_buf
data
=
GIT_BUF_INIT
;
git_revwalk
*
walk
=
NULL
;
int
error
,
pkt_type
;
int
error
=
-
1
,
pkt_type
;
unsigned
int
i
;
git_oid
oid
;
...
...
@@ -190,6 +190,12 @@ int git_fetch_negotiate(git_remote *remote)
git_pkt_buffer_have
(
&
oid
,
&
data
);
i
++
;
if
(
i
%
20
==
0
)
{
if
(
t
->
cancel
.
val
)
{
giterr_set
(
GITERR_NET
,
"The fetch was cancelled by the user"
);
error
=
GIT_EUSER
;
goto
on_error
;
}
git_pkt_buffer_flush
(
&
data
);
if
(
git_buf_oom
(
&
data
))
goto
on_error
;
...
...
@@ -254,6 +260,11 @@ int git_fetch_negotiate(git_remote *remote)
}
git_pkt_buffer_done
(
&
data
);
if
(
t
->
cancel
.
val
)
{
giterr_set
(
GITERR_NET
,
"The fetch was cancelled by the user"
);
error
=
GIT_EUSER
;
goto
on_error
;
}
if
(
t
->
negotiation_step
(
t
,
data
.
ptr
,
data
.
size
)
<
0
)
goto
on_error
;
...
...
@@ -288,7 +299,7 @@ int git_fetch_negotiate(git_remote *remote)
on_error:
git_revwalk_free
(
walk
);
git_buf_free
(
&
data
);
return
-
1
;
return
error
;
}
int
git_fetch_download_pack
(
git_remote
*
remote
,
git_off_t
*
bytes
,
git_indexer_stats
*
stats
)
...
...
@@ -305,11 +316,16 @@ int git_fetch_download_pack(git_remote *remote, git_off_t *bytes, git_indexer_st
}
static
int
no_sideband
(
git_indexer_stream
*
idx
,
gitno_buffer
*
buf
,
git_off_t
*
bytes
,
git_indexer_stats
*
stats
)
static
int
no_sideband
(
git_
transport
*
t
,
git_
indexer_stream
*
idx
,
gitno_buffer
*
buf
,
git_off_t
*
bytes
,
git_indexer_stats
*
stats
)
{
int
recvd
;
do
{
if
(
t
->
cancel
.
val
)
{
giterr_set
(
GITERR_NET
,
"The fetch was cancelled by the user"
);
return
GIT_EUSER
;
}
if
(
git_indexer_stream_add
(
idx
,
buf
->
data
,
buf
->
offset
,
stats
)
<
0
)
return
-
1
;
...
...
@@ -337,6 +353,7 @@ int git_fetch__download_pack(
git_buf
path
=
GIT_BUF_INIT
;
gitno_buffer
*
buf
=
&
t
->
buffer
;
git_indexer_stream
*
idx
=
NULL
;
int
error
=
-
1
;
if
(
git_buf_joinpath
(
&
path
,
git_repository_path
(
repo
),
"objects/pack"
)
<
0
)
return
-
1
;
...
...
@@ -354,7 +371,7 @@ int git_fetch__download_pack(
* check which one belongs there.
*/
if
(
!
t
->
caps
.
side_band
&&
!
t
->
caps
.
side_band_64k
)
{
if
(
no_sideband
(
idx
,
buf
,
bytes
,
stats
)
<
0
)
if
(
no_sideband
(
t
,
idx
,
buf
,
bytes
,
stats
)
<
0
)
goto
on_error
;
git_indexer_stream_free
(
idx
);
...
...
@@ -362,6 +379,12 @@ int git_fetch__download_pack(
}
do
{
if
(
t
->
cancel
.
val
)
{
giterr_set
(
GITERR_NET
,
"The fetch was cancelled by the user"
);
error
=
GIT_EUSER
;
goto
on_error
;
}
git_pkt
*
pkt
;
if
(
recv_pkt
(
&
pkt
,
buf
)
<
0
)
goto
on_error
;
...
...
@@ -395,7 +418,7 @@ int git_fetch__download_pack(
on_error:
git_buf_free
(
&
path
);
git_indexer_stream_free
(
idx
);
return
-
1
;
return
error
;
}
int
git_fetch_setup_walk
(
git_revwalk
**
out
,
git_repository
*
repo
)
...
...
src/remote.c
View file @
6f6871a9
...
...
@@ -558,6 +558,11 @@ int git_remote_connected(git_remote *remote)
return
remote
->
transport
==
NULL
?
0
:
remote
->
transport
->
connected
;
}
void
git_remote_stop
(
git_remote
*
remote
)
{
git_atomic_set
(
&
remote
->
transport
->
cancel
,
1
);
}
void
git_remote_disconnect
(
git_remote
*
remote
)
{
assert
(
remote
);
...
...
src/transport.h
View file @
6f6871a9
...
...
@@ -91,6 +91,8 @@ struct git_transport {
GIT_SOCKET
socket
;
git_transport_caps
caps
;
void
*
cb_data
;
git_atomic
cancel
;
/**
* Connect and store the remote heads
*/
...
...
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